Changeset 2019 for Whitix

Show
Ignore:
Timestamp:
04/02/09 21:21:10 (3 years ago)
Author:
mwhitworth
Message:

Attempt to rework PCI BIOS, add note.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/trunk/devices/pci/pci_bios.c

    r1668 r2019  
    1717 */ 
    1818 
     19/* TODO: This code needs checking, if it is ever used. */ 
    1920 
    2021#include <i386/ioports.h> 
     
    2728BYTE bios32FarCall[6]; 
    2829 
    29 int PciDetectBios() 
     30static DWORD PciScanForBios(DWORD start, DWORD end) 
    3031{ 
    31 #if 0 
    32         DWORD addr=0xE0000,name,temp; 
    33         BYTE length,sum,revision,err; 
    34  
    35         for (;addr < 0xFFFF0; addr+=16) 
     32        DWORD curr; 
     33        BYTE length, sum; 
     34         
     35        for (curr = start; curr < end; curr += 16) 
    3636        { 
    37                 printf("Here, %#X\n", addr); 
    38                 name=*(DWORD*)addr; 
    39                 if (name != 0x5F32335F) 
     37                if (*(DWORD*)curr != BIOS32_SIGNATURE) 
    4038                        continue; 
    41  
    42                 //Structure length 
    43                 length=(*(BYTE*)addr+9)*16; 
     39                         
     40                /* Get the length of the BIOS32 descriptor. It should not be zero. */ 
     41                length=(*(BYTE*)curr+9)*16; 
    4442 
    4543                if (length == 0) 
    4644                        continue; 
    4745 
     46                /* Checksum, to make sure we have a valid BIOS32 descriptor. */ 
    4847                for (sum=0; length!=0; length--) 
    49                         sum+=*(BYTE*)((addr+length)-1); 
     48                        sum+=*(BYTE*)((curr+length)-1); 
     49                 
     50                return curr; 
     51        } 
     52         
     53        return 0; 
     54} 
    5055 
    51                 *(DWORD*)(bios32FarCall+0)=*(DWORD*)(addr+4); 
    52                 *(WORD*)(bios32FarCall+4)=0x08; 
     56int PciDetectBios() 
     57{ 
     58        DWORD name,temp; 
     59        DWORD addr; 
     60        BYTE revision, err; 
    5361 
    54                 asm volatile("mov $0x49435024,%%eax\n" 
     62        addr = PciScanForBios(0xE0000, 0xffff0); 
     63 
     64        if (!addr) 
     65        { 
     66                KePrint(KERN_ERROR "PCI: Could not find BIOS32.\n"); 
     67                return -EINVAL; 
     68        } 
     69 
     70        *(DWORD*)(bios32FarCall+0)=*(DWORD*)(addr+4); 
     71        *(WORD*)(bios32FarCall+4)=0x08; 
     72 
     73#if 0 
     74        asm volatile("mov $0x49435024,%%eax\n" 
    5575                             "mov 0,%%ebx\n" 
    5676                             "lcall *(%%edi)" 
    5777                             : "=a"(err), 
    58                                 "=b"(addr), 
    59                                 "=c"(length), 
    60                                 "=d"(temp) 
     78                                 "=b"(addr), 
     79                                 "=c"(length), 
     80                                 "=d"(temp) 
    6181                             :  "D"(&bios32FarCall)); 
    6282 
    63                 if (err == 0x80) 
    64                 { 
    65                         printf("Computer has BIOS32, but no PCI32\n"); 
    66                         return false; 
    67                 } 
     83        if (err == 0x80) 
     84        { 
     85                KePrint("PCI: BIOS32 present, but no PCI32\n"); 
     86                return -EINVAL; 
     87        } 
    6888 
    69                 if (err) 
    70                 { 
    71                         printf("BIOS32 error = %u\n",(DWORD)err); 
    72                         return false; 
    73                 } 
     89        if (err) 
     90        { 
     91                printf("PCI: BIOS32 error\n"); 
     92                return -EINVAL; 
     93        } 
    7494 
    7595                return true;