source: rtems/bsps/shared/dev/pci/pci_bus_count.c @ f923901

5
Last change on this file since f923901 was f923901, checked in by Sebastian Huber <sebastian.huber@…>, on 04/19/18 at 04:10:18

bsps: Move pci_bus_count.c to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 * This software is Copyright (C) 1998 by T.sqware - all rights limited
3 * It is provided in to the public domain "as is", can be freely modified
4 * as far as this copyight notice is kept unchanged, but does not imply
5 * an endorsement by T.sqware of the product in which it is included.
6 */
7
8#include <rtems.h>
9#include <rtems/pci.h>
10#include <rtems/bspIo.h>
11
12static uint8_t pci_number_of_buses = 0xff;
13
14unsigned char pci_bus_count(void)
15{
16  if ( pci_number_of_buses != 0xff ) {
17    return pci_number_of_buses;
18  }
19
20  uint8_t  bus;
21  uint8_t  device;
22  uint8_t  function;
23  uint8_t  number_of_functions;
24  uint8_t  header = 0;
25  uint8_t  buses = 0;
26  uint32_t vendor = 0;
27  uint32_t class_rev = 0;
28
29  pci_number_of_buses = 0;
30
31  for (bus=0; bus < 0xff; bus++) {
32    for (device=0; device < PCI_MAX_DEVICES; device++) {
33
34       pci_read_config_dword(bus, device, 0, PCI_VENDOR_ID, &vendor);
35       if ( vendor == -1 ) {
36         continue;
37       }
38
39       pci_read_config_byte(bus, device, 0, PCI_HEADER_TYPE, &header);
40       number_of_functions = (header & 0x80) ? PCI_MAX_FUNCTIONS : 1;
41
42       for ( function=0; function < number_of_functions; function++ ) {
43         pci_read_config_dword(bus, device, function, PCI_VENDOR_ID, &vendor);
44         if ( vendor == -1 ) {
45           continue;
46         }
47
48         pci_read_config_dword(bus, device, function, PCI_CLASS_REVISION, &class_rev);
49         if ( (class_rev >> 16) == PCI_CLASS_BRIDGE_PCI ) {
50            pci_read_config_byte(bus, device, function, PCI_SUBORDINATE_BUS, &buses);
51            if ( buses > pci_number_of_buses ) {
52              pci_number_of_buses = buses;
53            }
54         }
55       }
56    }
57  }
58
59  if ( pci_number_of_buses == 0 ) {
60    printk("pci_bus_count() found 0 busses, assuming 1\n");
61    pci_number_of_buses = 1;
62  } else if ( pci_number_of_buses == 0xff ) {
63    printk("pci_bus_count() found 0xff busses, assuming 1\n");
64    pci_number_of_buses = 1;
65  }
66
67  return pci_number_of_buses;
68}
Note: See TracBrowser for help on using the repository browser.