1 | /* $Id: pci.c 151 2000-05-28 16:50:46Z sandervl $ */
|
---|
2 |
|
---|
3 | //******************************************************************************
|
---|
4 | // OS/2 IDC services (callback to 16 bits MMPM2 driver)
|
---|
5 | //
|
---|
6 | // Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | //
|
---|
8 | // Parts based on Linux kernel code (pci_read/write_*)
|
---|
9 | //
|
---|
10 | // This program is free software; you can redistribute it and/or
|
---|
11 | // modify it under the terms of the GNU General Public License as
|
---|
12 | // published by the Free Software Foundation; either version 2 of
|
---|
13 | // the License, or (at your option) any later version.
|
---|
14 | //
|
---|
15 | // This program is distributed in the hope that it will be useful,
|
---|
16 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | // GNU General Public License for more details.
|
---|
19 | //
|
---|
20 | // You should have received a copy of the GNU General Public
|
---|
21 | // License along with this program; if not, write to the Free
|
---|
22 | // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
|
---|
23 | // USA.
|
---|
24 | //
|
---|
25 | //******************************************************************************
|
---|
26 | #include "hwaccess.h"
|
---|
27 | #include <linux/init.h>
|
---|
28 | #include <linux/poll.h>
|
---|
29 | #include <asm/uaccess.h>
|
---|
30 | #include <asm/hardirq.h>
|
---|
31 |
|
---|
32 | #define LINUX
|
---|
33 | #include <ossidc.h>
|
---|
34 | #include <stacktoflat.h>
|
---|
35 |
|
---|
36 | #define MAX_PCI_DEVICES 16
|
---|
37 | #define MAX_PCI_BUSSES 2
|
---|
38 |
|
---|
39 | static struct pci_dev pci_devices[MAX_PCI_DEVICES] = {0};
|
---|
40 | static struct pci_bus pci_busses[MAX_PCI_BUSSES] = {0};
|
---|
41 |
|
---|
42 | //******************************************************************************
|
---|
43 | //******************************************************************************
|
---|
44 | int pcidev_prepare(struct pci_dev *dev)
|
---|
45 | {
|
---|
46 | return 1; //todo: correct return value??
|
---|
47 | }
|
---|
48 | //******************************************************************************
|
---|
49 | //******************************************************************************
|
---|
50 | int pcidev_activate(struct pci_dev *dev)
|
---|
51 | {
|
---|
52 | return 1; //todo: correct return value??
|
---|
53 | }
|
---|
54 | //******************************************************************************
|
---|
55 | //******************************************************************************
|
---|
56 | int pcidev_deactivate(struct pci_dev *dev)
|
---|
57 | {
|
---|
58 | return 1; //todo: correct return value??
|
---|
59 | }
|
---|
60 | //******************************************************************************
|
---|
61 | //TODO: Doesn't completely fill in the pci_dev structure
|
---|
62 | //******************************************************************************
|
---|
63 | int FindPCIDevice(unsigned int vendor, unsigned int device, struct pci_dev near *pcidev)
|
---|
64 | {
|
---|
65 | IDC_RESOURCE idcres;
|
---|
66 | ULONG devid, pResource;
|
---|
67 | int i, residx = 0;
|
---|
68 |
|
---|
69 | pcidev->prepare = pcidev_prepare;
|
---|
70 | pcidev->activate = pcidev_activate;
|
---|
71 | pcidev->deactivate = pcidev_deactivate;
|
---|
72 | pcidev->active = 1;
|
---|
73 | pcidev->ro = 0;
|
---|
74 | pcidev->sibling = NULL;
|
---|
75 | pcidev->next = NULL;
|
---|
76 | pcidev->vendor = vendor;
|
---|
77 | pcidev->device = device;
|
---|
78 |
|
---|
79 | devid = (device << 16) | vendor;
|
---|
80 |
|
---|
81 | #ifdef KEE
|
---|
82 | pResource = __FlatToStack(&idcres);
|
---|
83 | #else
|
---|
84 | pResource = __Compress48Pointer((char FAR48 *)&idcres);
|
---|
85 | #endif
|
---|
86 | if(CallOSS16(IDC16_FIND_PCIDEVICE, devid, pResource) == FALSE) {
|
---|
87 | return FALSE;
|
---|
88 | }
|
---|
89 |
|
---|
90 | for(i=0;i<MAX_RES_IO;i++) {
|
---|
91 | if(idcres.io[i] != 0xffff) {
|
---|
92 | pcidev->resource[residx].name = 0;
|
---|
93 | pcidev->resource[residx].child = 0;
|
---|
94 | pcidev->resource[residx].sibling = 0;
|
---|
95 | pcidev->resource[residx].parent = 0;
|
---|
96 | pcidev->resource[residx].start = idcres.io[i];
|
---|
97 | pcidev->resource[residx].end = idcres.io[i] + idcres.iolength[i]; //inclusive??
|
---|
98 | pcidev->resource[residx].flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO;
|
---|
99 |
|
---|
100 | residx++;
|
---|
101 | }
|
---|
102 | }
|
---|
103 | for(i=0;i<MAX_RES_MEM;i++) {
|
---|
104 | if(idcres.mem[i] != 0xffffffff) {
|
---|
105 | pcidev->resource[residx].name = 0;
|
---|
106 | pcidev->resource[residx].child = 0;
|
---|
107 | pcidev->resource[residx].sibling = 0;
|
---|
108 | pcidev->resource[residx].parent = 0;
|
---|
109 | pcidev->resource[residx].start = idcres.mem[i];
|
---|
110 | pcidev->resource[residx].end = idcres.mem[i] + idcres.memlength[i]; //inclusive??
|
---|
111 | pcidev->resource[residx].flags = IORESOURCE_MEM | IORESOURCE_MEM_WRITEABLE;
|
---|
112 |
|
---|
113 | residx++;
|
---|
114 | }
|
---|
115 | }
|
---|
116 | for(i=0;i<MAX_RES_DMA;i++) {
|
---|
117 | if(idcres.dma[i] != 0xffff) {
|
---|
118 | pcidev->dma_resource[i].name = 0;
|
---|
119 | pcidev->dma_resource[i].child = 0;
|
---|
120 | pcidev->dma_resource[i].sibling = 0;
|
---|
121 | pcidev->dma_resource[i].parent = 0;
|
---|
122 | pcidev->dma_resource[i].start = idcres.dma[i];
|
---|
123 | pcidev->dma_resource[i].end = idcres.dma[i];
|
---|
124 | //todo: 8/16 bits
|
---|
125 | pcidev->dma_resource[i].flags = IORESOURCE_DMA;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | for(i=0;i<MAX_RES_IRQ;i++) {
|
---|
129 | if(idcres.irq[i] != 0xffff) {
|
---|
130 | pcidev->irq_resource[i].name = 0;
|
---|
131 | pcidev->irq_resource[i].child = 0;
|
---|
132 | pcidev->irq_resource[i].sibling = 0;
|
---|
133 | pcidev->irq_resource[i].parent = 0;
|
---|
134 | pcidev->irq_resource[i].start = idcres.irq[i];
|
---|
135 | pcidev->irq_resource[i].end = idcres.irq[i];
|
---|
136 | //todo: irq flags
|
---|
137 | pcidev->irq_resource[9].flags = IORESOURCE_IRQ;
|
---|
138 | }
|
---|
139 | }
|
---|
140 | pcidev->irq = pcidev->irq_resource[0].start;
|
---|
141 | pcidev->bus = &pci_busses[0];
|
---|
142 | return TRUE;
|
---|
143 | }
|
---|
144 | //******************************************************************************
|
---|
145 | //******************************************************************************
|
---|
146 | struct pci_dev *pci_find_device (unsigned int vendor, unsigned int device, struct pci_dev *from)
|
---|
147 | {
|
---|
148 | int i;
|
---|
149 |
|
---|
150 | if(from) {
|
---|
151 | //requesting 2nd device of the same type; don't support this for now
|
---|
152 | return 0;
|
---|
153 | }
|
---|
154 | for(i=0;i<MAX_PCI_DEVICES;i++) {
|
---|
155 | if(pci_devices[i].devfn == 0) {
|
---|
156 | if(FindPCIDevice(vendor, device, (struct pci_dev near *)&pci_devices[i]) == TRUE) {
|
---|
157 | return &pci_devices[i];
|
---|
158 | }
|
---|
159 | break;
|
---|
160 | }
|
---|
161 | }
|
---|
162 | return 0;
|
---|
163 | }
|
---|
164 | //******************************************************************************
|
---|
165 | #define CONFIG_CMD(dev, where) (0x80000000 | (dev->bus->number << 16) | (dev->devfn << 8) | (where & ~3))
|
---|
166 | //******************************************************************************
|
---|
167 | int pci_read_config_byte(struct pci_dev *dev, int where, u8 *value)
|
---|
168 | {
|
---|
169 | outl(CONFIG_CMD(dev,where), 0xCF8);
|
---|
170 | *value = inb(0xCFC + (where&3));
|
---|
171 | return PCIBIOS_SUCCESSFUL;
|
---|
172 | }
|
---|
173 | //******************************************************************************
|
---|
174 | //******************************************************************************
|
---|
175 | int pci_read_config_word(struct pci_dev *dev, int where, u16 *value)
|
---|
176 | {
|
---|
177 | outl(CONFIG_CMD(dev,where), 0xCF8);
|
---|
178 | *value = inw(0xCFC + (where&2));
|
---|
179 | return PCIBIOS_SUCCESSFUL;
|
---|
180 | }
|
---|
181 | //******************************************************************************
|
---|
182 | //******************************************************************************
|
---|
183 | int pci_read_config_dword(struct pci_dev *dev, int where, u32 *value)
|
---|
184 | {
|
---|
185 | outl(CONFIG_CMD(dev,where), 0xCF8);
|
---|
186 | *value = inl(0xCFC);
|
---|
187 | return PCIBIOS_SUCCESSFUL;
|
---|
188 | }
|
---|
189 | //******************************************************************************
|
---|
190 | //******************************************************************************
|
---|
191 | int pci_write_config_byte(struct pci_dev *dev, int where, u8 value)
|
---|
192 | {
|
---|
193 | outl(CONFIG_CMD(dev,where), 0xCF8);
|
---|
194 | outb(value, 0xCFC + (where&3));
|
---|
195 | return PCIBIOS_SUCCESSFUL;
|
---|
196 | }
|
---|
197 | //******************************************************************************
|
---|
198 | //******************************************************************************
|
---|
199 | int pci_write_config_word(struct pci_dev *dev, int where, u16 value)
|
---|
200 | {
|
---|
201 | outl(CONFIG_CMD(dev,where), 0xCF8);
|
---|
202 | outw(value, 0xCFC + (where&2));
|
---|
203 | return PCIBIOS_SUCCESSFUL;
|
---|
204 | }
|
---|
205 | //******************************************************************************
|
---|
206 | //******************************************************************************
|
---|
207 | int pci_write_config_dword(struct pci_dev *dev, int where, u32 value)
|
---|
208 | {
|
---|
209 | outl(CONFIG_CMD(dev,where), 0xCF8);
|
---|
210 | outl(value, 0xCFC);
|
---|
211 | return PCIBIOS_SUCCESSFUL;
|
---|
212 | }
|
---|
213 | //******************************************************************************
|
---|
214 | //******************************************************************************
|
---|
215 | int pcibios_present(void)
|
---|
216 | {
|
---|
217 | return 1;
|
---|
218 | }
|
---|
219 | //******************************************************************************
|
---|
220 | //******************************************************************************
|
---|
221 | struct pci_dev *pci_find_slot (unsigned int bus, unsigned int devfn)
|
---|
222 | {
|
---|
223 | return NULL;
|
---|
224 | }
|
---|
225 | //******************************************************************************
|
---|
226 | //******************************************************************************
|
---|
227 | int pci_dma_supported(struct pci_dev *dev, unsigned long mask)
|
---|
228 | {
|
---|
229 | return 1;
|
---|
230 | }
|
---|
231 | //******************************************************************************
|
---|
232 | //******************************************************************************
|
---|
233 | int pci_enable_device(struct pci_dev *dev)
|
---|
234 | {
|
---|
235 | return 0;
|
---|
236 | }
|
---|
237 | //******************************************************************************
|
---|
238 | struct pci_dev *sblivepcidev = NULL;
|
---|
239 | //******************************************************************************
|
---|
240 | int pci_register_driver(struct pci_driver *driver)
|
---|
241 | {
|
---|
242 | struct pci_dev *pcidev;
|
---|
243 |
|
---|
244 | pcidev = pci_find_device(driver->id_table->vendor, driver->id_table->device, NULL);
|
---|
245 | if(pcidev) {
|
---|
246 | if(driver->probe(pcidev, driver->id_table) == 0) {
|
---|
247 | sblivepcidev = pcidev;
|
---|
248 | return 0;
|
---|
249 | }
|
---|
250 | }
|
---|
251 | return 1;
|
---|
252 | }
|
---|
253 | //******************************************************************************
|
---|
254 | //******************************************************************************
|
---|
255 | int pci_unregister_driver(struct pci_driver *driver)
|
---|
256 | {
|
---|
257 | if(driver && sblivepcidev) {
|
---|
258 | driver->remove(sblivepcidev);
|
---|
259 | }
|
---|
260 | return 0;
|
---|
261 | }
|
---|
262 | //******************************************************************************
|
---|
263 | //******************************************************************************
|
---|
264 | void pci_set_master(struct pci_dev *dev)
|
---|
265 | {
|
---|
266 |
|
---|
267 | }
|
---|
268 | //******************************************************************************
|
---|
269 | //******************************************************************************
|
---|