Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

Peripheral Component Interconnect (PCI) bus
[Device Drivers]


Data Structures

struct  pci_cfg
 PCI configuration structure for a device. Every PCI device belong to a known class. To find this class we have to look at the base_class, sub_class and interface code. More...


Typedefs

typedef pci_cfg pci_cfg_t
 PCI configuration structure for a device. Every PCI device belong to a known class. To find this class we have to look at the base_class, sub_class and interface code.


Functions

bool pci_find_cfg (pci_cfg_t *cfg, bool enable)
 Look for a device in the PCI bus and eventually enable it.
Parameters:
cfg  The PCI device configuration structure.
enable 
  • TRUE enable the device if present;
  • FALSE simply look for a device without enabling it.
Returns:
  • TRUE a device has been found;
  • FALSE device not found.


void pci_scan ()
 Scan all the PCI buses, looking for devices. If a device is found it will be enabled.


Detailed Description

The PCI (Peripheral Component Interconnect) bus driver and device identification.

Typedef Documentation

typedef struct pci_cfg pci_cfg_t
 

PCI configuration structure for a device. Every PCI device belong to a known class. To find this class we have to look at the base_class, sub_class and interface code.

pci_config_header.jpg

The PCI configuration header


Function Documentation

bool pci_find_cfg pci_cfg_t   cfg,
bool    enable
 

Look for a device in the PCI bus and eventually enable it.

Parameters:
cfg  The PCI device configuration structure.
enable 
  • TRUE enable the device if present;
  • FALSE simply look for a device without enabling it.
Returns:
  • TRUE a device has been found;
  • FALSE device not found.

Definition at line 769 of file pci.c.

00770 {
00771         uint16_t bus, dev, func;
00772         pci_cfg_t *pcfg;
00773 
00774         pcfg = kmalloc( sizeof(pci_cfg_t) );
00775 
00776         for (bus=0; bus<4; bus++)
00777         for (dev=0; dev<32; dev++)
00778         for (func=0; func<8; func++)
00779         {
00780                 if ( pci_probe(bus, dev, func, pcfg) )
00781                 {
00782                         if (
00783                                 cfg->base_class == pcfg->base_class &&
00784                                 cfg->sub_class == pcfg->sub_class &&
00785                                 cfg->interface == pcfg->interface
00786                         )
00787                         {
00788                                 // Device found                         //
00789                                 memcpy(cfg, pcfg, sizeof(pci_cfg_t));
00790                                 // Enable the device if required        //
00791                                 if (enable) pci_enable_device(pcfg);
00792                                 // Free the temporary structure         //
00793                                 kfree(pcfg);
00794                                 return(TRUE);
00795                         }
00796                 }
00797         }
00798         // Device not found                                             //
00799         kfree(pcfg);
00800         return(FALSE);
00801 }

void pci_scan  
 

Scan all the PCI buses, looking for devices. If a device is found it will be enabled.

Definition at line 806 of file pci.c.

00807 {
00808         uint16_t bus, dev, func;
00809         pci_cfg_t pcfg;
00810         int i, key;
00811 
00812         for (bus=0; bus<4; bus++)
00813         for (dev = 0; dev < 32; dev++)
00814         for (func = 0; func < 8; func++)
00815         {
00816                 if ( pci_probe(bus, dev, func, &pcfg) )
00817                 {
00818                         set_color(WHITE);
00819                         kprintf("\n\rPCI:%u:%u:%u", bus, dev, func);
00820                         set_color(DEFAULT_COLOR);
00821 
00822                         kprintf(        "\n\rVendor       :%04X Device       :%04X"
00823                                 "\n\rSubSys_Vendor:%04X SubSys_Device:%04X",
00824                                 pcfg.vendor_id, pcfg.device_id, pcfg.subsys_vendor, pcfg.subsys_device);
00825                         kprintf(        "\n\rBase_Class   :%02X   Sub_Class    :%02X   Interface    :%02X",
00826                                 pcfg.base_class, pcfg.sub_class, pcfg.interface);
00827 
00828                         for (i=0;; i++)
00829                         {
00830                                 if ( i>=PCI_CLASS_ENTRIES )
00831                                 {
00832                                         kprintf("\n\r* Description : Unknown device!");
00833                                         break;
00834                                 }
00835                                 if
00836                                 (
00837                                         (classes[i].base_class == pcfg.base_class) &&
00838                                         (classes[i].sub_class == pcfg.sub_class) &&
00839                                         (classes[i].interface == pcfg.interface)
00840                                 )
00841                                 {
00842                                         kprintf("\n\r* Description : %s", classes[i].name);
00843                                         break;
00844                                 }
00845                         }
00846 
00847                         for (i=0; i<6; i++)
00848                                 if (pcfg.base[i])
00849                                 {
00850                                         if (pcfg.type[i] == PCI_IO_RESOURCE_IO)
00851                                                 kprintf("\n\r* Base Register %d IO: %#06x (%#06x)",
00852                                                         i, pcfg.base[i], pcfg.size[i]);
00853                                         else
00854                                                 kprintf("\n\r* Base Register %d MM: %#010x (%#010x)",
00855                                                         i, pcfg.base[i] & 0xfffffff0, pcfg.size[i]);
00856                                 }
00857                                 if (pcfg.rom_base)
00858                                         kprintf("\n\r* Base Register ROM : %#010x (%#010x)",
00859                                                 pcfg.rom_base, pcfg.rom_size);
00860 
00861                         if (pcfg.irq)
00862                                 kprintf("\n\r* Interrupt line: %u", pcfg.irq);
00863 
00864 
00865                         switch(pcfg.header_type & 0x7F)
00866                         {
00867                                 case PCI_HEADER_TYPE_NORMAL:
00868                                 kprintf("\n\r* Normal device");
00869                                 break;
00870 
00871                                 case PCI_HEADER_TYPE_BRIDGE:
00872                                 kprintf("\n\r* PCI <-> PCI bridge");
00873                                 break;
00874 
00875                                 default:
00876                                 kprintf("\n\r* Unknown header type");
00877                                 break;
00878                         }
00879 
00880                         // kprintf("\n\rDo you want to enable this device (Y/N)? ");
00881                         pci_enable_device(&pcfg);
00882                         key = kgetchar();
00883                         if ( key==CTRL_C ) return;
00884                         /*
00885                         key &= 0xFF;
00886                         if ( key=='Y' || key=='y' )
00887                         {
00888                                 putchar(key);
00889                                 pci_enable_device(&pcfg);
00890                         }
00891                         else
00892                                 putchar('N');
00893                         */
00894                         kprintf("\n\r");
00895                 }
00896         }
00897         kprintf("\n\rPCI: finished\n\r");
00898 }


Generated on Fri Feb 20 15:32:22 2004 for Minirighi by doxygen1.2.18