|
@@ -8,6 +8,132 @@
|
8
|
8
|
#define DBG(...)
|
9
|
9
|
#endif
|
10
|
10
|
|
|
11
|
+static struct pci_device current;
|
|
12
|
+static char used_current;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+ * Fill in parameters (vendor & device ids, class, membase etc.) for a
|
|
16
|
+ * PCI device based on bus & devfn.
|
|
17
|
+ *
|
|
18
|
+ * Returns 1 if a device was found, 0 for no device present.
|
|
19
|
+ */
|
|
20
|
+static int fill_pci_device ( struct pci_device *pci ) {
|
|
21
|
+ uint32_t l;
|
|
22
|
+ int reg;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+ */
|
|
26
|
+ pci_read_config_dword ( pci, PCI_VENDOR_ID, &l );
|
|
27
|
+
|
|
28
|
+ if ( ( l == 0xffffffff ) || ( l == 0x00000000 ) ) {
|
|
29
|
+ return 0;
|
|
30
|
+ }
|
|
31
|
+ pci->vendor = l & 0xffff;
|
|
32
|
+ pci->dev_id = ( l >> 16 ) & 0xffff;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+ * non-multifunction device.
|
|
36
|
+ */
|
|
37
|
+ if ( PCI_FUNC ( pci->devfn ) != 0 ) {
|
|
38
|
+ uint8_t header_type;
|
|
39
|
+ pci_read_config_byte ( pci, PCI_HEADER_TYPE, &header_type );
|
|
40
|
+ if ( ! ( header_type & 0x80 ) ) {
|
|
41
|
+ return 0;
|
|
42
|
+ }
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+ pci_read_config_dword ( pci, PCI_REVISION, &l );
|
|
47
|
+ pci->class = ( l >> 8 ) & 0xffffff;
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+ pci_read_config_dword ( pci, PCI_BASE_ADDRESS_1, &pci->membase );
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+ pci->ioaddr = 0;
|
|
54
|
+ for ( reg = PCI_BASE_ADDRESS_0; reg <= PCI_BASE_ADDRESS_5; reg += 4 ) {
|
|
55
|
+ pci_read_config_dword ( pci, reg, &pci->ioaddr );
|
|
56
|
+ if ( pci->ioaddr & PCI_BASE_ADDRESS_SPACE_IO ) {
|
|
57
|
+ pci->ioaddr &= PCI_BASE_ADDRESS_IO_MASK;
|
|
58
|
+ if ( pci->ioaddr ) {
|
|
59
|
+ break;
|
|
60
|
+ }
|
|
61
|
+ }
|
|
62
|
+ pci->ioaddr = 0;
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+ pci_read_config_byte ( pci, PCI_INTERRUPT_PIN, &pci->irq );
|
|
67
|
+ if ( pci->irq ) {
|
|
68
|
+ pci_read_config_byte ( pci, PCI_INTERRUPT_LINE, &pci->irq );
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ return 1;
|
|
72
|
+}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+ * Set PCI device to use.
|
|
76
|
+ *
|
|
77
|
+ * This routine can be called by e.g. the ROM prefix to specify that
|
|
78
|
+ * the first device to be tried should be the device on which the ROM
|
|
79
|
+ * was physically located.
|
|
80
|
+ *
|
|
81
|
+ */
|
|
82
|
+void set_pci_device ( uint8_t bus, uint8_t devfn ) {
|
|
83
|
+ current.bus = bus;
|
|
84
|
+ current.devfn = devfn;
|
|
85
|
+ used_current = 0;
|
|
86
|
+}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+ * Find a PCI device matching the specified driver
|
|
90
|
+ *
|
|
91
|
+ */
|
|
92
|
+struct pci_device * find_pci_device ( struct pci_driver *driver ) {
|
|
93
|
+ int i;
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+ * starting where we left off.
|
|
97
|
+ */
|
|
98
|
+ for ( ; current.bus <= 0xff ; current.bus++ ) {
|
|
99
|
+ for ( ; current.devfn <= 0xff ; current.devfn++ ) {
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+ if ( used_current ) {
|
|
103
|
+ used_current = 0;
|
|
104
|
+ continue;
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+ if ( ! fill_pci_device ( ¤t ) ) {
|
|
109
|
+ continue;
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+ if ( driver->class &&
|
|
114
|
+ ( driver->class == current.class ) ) {
|
|
115
|
+ current.name = driver->name;
|
|
116
|
+ used_current = 1;
|
|
117
|
+ return ¤t;
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+ for ( i = 0 ; i < driver->id_count; i++ ) {
|
|
122
|
+ struct pci_id *id = &driver->ids[i];
|
|
123
|
+
|
|
124
|
+ if ( ( current.vendor == id->vendor ) &&
|
|
125
|
+ ( current.dev_id == id->dev_id ) ) {
|
|
126
|
+ current.name = id->name;
|
|
127
|
+ used_current = 1;
|
|
128
|
+ return ¤t;
|
|
129
|
+ }
|
|
130
|
+ }
|
|
131
|
+ }
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ memset ( ¤t, 0, sizeof ( current ) );
|
|
135
|
+ return NULL;
|
|
136
|
+}
|
11
|
137
|
|
12
|
138
|
|
13
|
139
|
* Set device to be a busmaster in case BIOS neglected to do so. Also
|