1 | /* $Id: pci.c,v 1.1.1.1 2003/07/02 13:57:02 eleph Exp $ */
|
---|
2 | /*
|
---|
3 | * OS/2 implementation of Linux PCI functions (using direct port I/O)
|
---|
4 | *
|
---|
5 | * (C) 2000-2002 InnoTek Systemberatung GmbH
|
---|
6 | * (C) 2000-2001 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | * Copyright (c) 2016-2017 David Azarewicz <david@88watts.net>
|
---|
8 | *
|
---|
9 | * Parts based on Linux kernel sources
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License as
|
---|
13 | * published by the Free Software Foundation; either version 2 of
|
---|
14 | * the License, or (at your option) any later version.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public
|
---|
22 | * License along with this program; if not, write to the Free
|
---|
23 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
|
---|
24 | * USA.
|
---|
25 | *
|
---|
26 | */
|
---|
27 | #define CONFIG_PM
|
---|
28 | #include "linux.h"
|
---|
29 | #include <linux/init.h>
|
---|
30 | #include <linux/poll.h>
|
---|
31 | #include <linux/dma-mapping.h>
|
---|
32 | #include <asm/uaccess.h>
|
---|
33 | #include <asm/hardirq.h>
|
---|
34 | #include <asm/io.h>
|
---|
35 | #include <sound/config.h>
|
---|
36 | #include <sound/core.h>
|
---|
37 | #include <sound/asound.h>
|
---|
38 |
|
---|
39 | #define LINUX
|
---|
40 | #include <ossidc.h>
|
---|
41 | #include <stacktoflat.h>
|
---|
42 | #include <dbgos2.h>
|
---|
43 | #include <osspci.h>
|
---|
44 |
|
---|
45 | #define MAX_PCI_BUSSES 256
|
---|
46 | #define MAX_PCI_DEVICES 16
|
---|
47 |
|
---|
48 | struct pci_dev pci_devices[MAX_PCI_DEVICES] = {0};
|
---|
49 | //struct pci_bus pci_busses[MAX_PCI_BUSSES] = {0};
|
---|
50 |
|
---|
51 | extern int nrCardsDetected;
|
---|
52 | extern int iAdapterNumber;
|
---|
53 |
|
---|
54 |
|
---|
55 | #define PCI_CONFIG_ENABLE 0x80000000
|
---|
56 | #define PCI_CONFIG_ADDRESS 0xCF8
|
---|
57 | #define PCI_CONFIG_DATA 0xCFC
|
---|
58 |
|
---|
59 | //******************************************************************************
|
---|
60 | #define CONFIG_CMD(dev, where) \
|
---|
61 | (PCI_CONFIG_ENABLE | (dev->bus->number<<16) | (dev->devfn<<8) | (where & ~3))
|
---|
62 | //******************************************************************************
|
---|
63 | int pci_read_config_byte(struct pci_dev *dev, int where, u8 *value)
|
---|
64 | {
|
---|
65 | outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
|
---|
66 | *value = inb(PCI_CONFIG_DATA + (where&3));
|
---|
67 | return PCIBIOS_SUCCESSFUL;
|
---|
68 | }
|
---|
69 | //******************************************************************************
|
---|
70 | //******************************************************************************
|
---|
71 | int pci_read_config_word(struct pci_dev *dev, int where, u16 *value)
|
---|
72 | {
|
---|
73 | outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
|
---|
74 | *value = inw(PCI_CONFIG_DATA + (where&2));
|
---|
75 | return PCIBIOS_SUCCESSFUL;
|
---|
76 | }
|
---|
77 | //******************************************************************************
|
---|
78 | //******************************************************************************
|
---|
79 | int pci_read_config_dword(struct pci_dev *dev, int where, u32 *value)
|
---|
80 | {
|
---|
81 | outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
|
---|
82 | *value = inl(PCI_CONFIG_DATA);
|
---|
83 | return PCIBIOS_SUCCESSFUL;
|
---|
84 | }
|
---|
85 | //******************************************************************************
|
---|
86 | //******************************************************************************
|
---|
87 | int pci_write_config_byte(struct pci_dev *dev, int where, u8 value)
|
---|
88 | {
|
---|
89 | outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
|
---|
90 | outb(value, PCI_CONFIG_DATA + (where&3));
|
---|
91 | return PCIBIOS_SUCCESSFUL;
|
---|
92 | }
|
---|
93 | //******************************************************************************
|
---|
94 | //******************************************************************************
|
---|
95 | int pci_write_config_word(struct pci_dev *dev, int where, u16 value)
|
---|
96 | {
|
---|
97 | outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
|
---|
98 | outw(value, PCI_CONFIG_DATA + (where&2));
|
---|
99 | return PCIBIOS_SUCCESSFUL;
|
---|
100 | }
|
---|
101 | //******************************************************************************
|
---|
102 | //******************************************************************************
|
---|
103 | int pci_write_config_dword(struct pci_dev *dev, int where, u32 value)
|
---|
104 | {
|
---|
105 | outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
|
---|
106 | outl(value, PCI_CONFIG_DATA);
|
---|
107 | return PCIBIOS_SUCCESSFUL;
|
---|
108 | }
|
---|
109 | //******************************************************************************
|
---|
110 | //******************************************************************************
|
---|
111 | int pcidev_prepare(struct pci_dev *dev)
|
---|
112 | {
|
---|
113 | dprintf(("pcidev_prepare %x not implemented", dev));
|
---|
114 | return 1; //todo: correct return value??
|
---|
115 | }
|
---|
116 | //******************************************************************************
|
---|
117 | //******************************************************************************
|
---|
118 | int pcidev_activate(struct pci_dev *dev)
|
---|
119 | {
|
---|
120 | dprintf(("pcidev_activate %x not implemented", dev));
|
---|
121 | return 1; //todo: correct return value??
|
---|
122 | }
|
---|
123 | //******************************************************************************
|
---|
124 | //******************************************************************************
|
---|
125 | int pcidev_deactivate(struct pci_dev *dev)
|
---|
126 | {
|
---|
127 | dprintf(("pcidev_deactivate %x not implemented", dev));
|
---|
128 | return 1; //todo: correct return value??
|
---|
129 | }
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Called by: pci_find_device, register_driver
|
---|
133 | *
|
---|
134 | * Find the next matching PCI device starting with the device specified by ulLast
|
---|
135 | * Returns: the found device, pcidev filled in. Returns zero if no device found.
|
---|
136 | */
|
---|
137 | static ULONG pci_query_device(const struct pci_device_id *pIdTable, struct pci_dev near *pcidev, ULONG ulLast)
|
---|
138 | {
|
---|
139 | int resNo, addr;
|
---|
140 | u32 devNr, busNr, funcNr, detectedId, cfgaddrreg, ulPciAdr, ulTmp1, ulTmp2;
|
---|
141 | u8 headerType;
|
---|
142 |
|
---|
143 | busNr = (ulLast >> 8) & 0xff;
|
---|
144 | devNr = PCI_SLOT(ulLast);
|
---|
145 | funcNr = PCI_FUNC(ulLast);
|
---|
146 | if (ulLast) funcNr++;
|
---|
147 |
|
---|
148 | cfgaddrreg = inl(PCI_CONFIG_ADDRESS);
|
---|
149 | for ( ; busNr<MAX_PCI_BUSSES; busNr++) //BusNumber<255
|
---|
150 | {
|
---|
151 | for( ; devNr<32; devNr++)
|
---|
152 | {
|
---|
153 | for( ; funcNr<8; funcNr++)
|
---|
154 | {
|
---|
155 | headerType = 0;
|
---|
156 | ulPciAdr = PCI_CONFIG_ENABLE | (busNr<<16) | (devNr<<11) | (funcNr<<8);
|
---|
157 | outl(ulPciAdr, PCI_CONFIG_ADDRESS);
|
---|
158 | detectedId = inl(PCI_CONFIG_DATA);
|
---|
159 |
|
---|
160 | if ( detectedId == 0xffffffff )
|
---|
161 | {
|
---|
162 | if ( funcNr == 0 ) break; /* if func 0 isn't there, the others aren't either */
|
---|
163 | continue;
|
---|
164 | }
|
---|
165 |
|
---|
166 | outl(ulPciAdr + PCI_CLASS_REVISION, PCI_CONFIG_ADDRESS);
|
---|
167 | ulTmp2 = inl(PCI_CONFIG_DATA) >> 8; /* get class */
|
---|
168 |
|
---|
169 | //dprintf(("Found: %x Class=%x need: %x%x class=%x", detectedId, ulTmp2, pIdTable->device&0xffff, pIdTable->vendor, pIdTable->class));
|
---|
170 |
|
---|
171 | if ( pIdTable->class )
|
---|
172 | {
|
---|
173 | if ( (ulTmp2 & pIdTable->class_mask) != pIdTable->class ) continue;
|
---|
174 | }
|
---|
175 |
|
---|
176 | if ( pIdTable->vendor && (pIdTable->vendor != (detectedId & 0xffff)) ) continue;
|
---|
177 | if ( pIdTable->device && (pIdTable->device != PCI_ANY_ID) && (pIdTable->device != (detectedId >> 16)) ) continue;
|
---|
178 |
|
---|
179 | outl(ulPciAdr | (PCI_HEADER_TYPE & ~3), PCI_CONFIG_ADDRESS);
|
---|
180 | headerType = inb(PCI_CONFIG_DATA + (PCI_HEADER_TYPE & 3));
|
---|
181 |
|
---|
182 | if ( (headerType & 0x7f) != PCI_HEADER_TYPE_NORMAL ) continue;
|
---|
183 |
|
---|
184 | memset((void near *)pcidev, 0, sizeof(struct pci_dev));
|
---|
185 |
|
---|
186 | pcidev->class = ulTmp2;
|
---|
187 | pcidev->vendor = detectedId & 0xffff;
|
---|
188 | pcidev->device = detectedId >> 16;
|
---|
189 | //pcidev->bus = &pci_busses[busNr];
|
---|
190 | pcidev->bus = kmalloc(sizeof(struct pci_bus), GFP_KERNEL);
|
---|
191 | if (pcidev->bus == NULL) return 0;
|
---|
192 | memset (pcidev->bus, 0, sizeof(struct pci_bus));
|
---|
193 | pcidev->bus->number = busNr;
|
---|
194 | pcidev->devfn = PCI_DEVFN(devNr, funcNr);
|
---|
195 | pcidev->hdr_type = headerType & 0x7f;
|
---|
196 |
|
---|
197 | pcidev->prepare = pcidev_prepare;
|
---|
198 | pcidev->activate = pcidev_activate;
|
---|
199 | pcidev->deactivate = pcidev_deactivate;
|
---|
200 | pcidev->active = 1;
|
---|
201 | pcidev->ro = 0;
|
---|
202 | pcidev->sibling = NULL;
|
---|
203 | pcidev->next = NULL;
|
---|
204 | pcidev->dma_mask = 0xffffffff;
|
---|
205 | pcidev->dev.dma_mask = &pcidev->dma_mask;
|
---|
206 | pcidev->dev.coherent_dma_mask = 0xffffffffull;
|
---|
207 |
|
---|
208 | // Subsystem ID
|
---|
209 | pci_read_config_word(pcidev, PCI_SUBSYSTEM_VENDOR_ID, &pcidev->subsystem_vendor);
|
---|
210 | pci_read_config_word(pcidev, PCI_SUBSYSTEM_ID, &pcidev->subsystem_device);
|
---|
211 |
|
---|
212 | // revision
|
---|
213 | pci_read_config_byte(pcidev, PCI_REVISION_ID, &pcidev->revision);
|
---|
214 |
|
---|
215 | // I/O and MEM
|
---|
216 | resNo = 0;
|
---|
217 | for( addr = PCI_BASE_ADDRESS_0; addr <= PCI_BASE_ADDRESS_5; addr += 4 )
|
---|
218 | {
|
---|
219 | pci_read_config_dword(pcidev, addr, &ulTmp1);
|
---|
220 | if( ulTmp1 != 0 && ulTmp1 != 0xffffffff )
|
---|
221 | {
|
---|
222 | pci_write_config_dword(pcidev, addr, 0xffffffff);
|
---|
223 | pci_read_config_dword(pcidev, addr, &ulTmp2);
|
---|
224 | pci_write_config_dword(pcidev, addr, ulTmp1);
|
---|
225 |
|
---|
226 | if( ulTmp1 & PCI_BASE_ADDRESS_SPACE_IO )
|
---|
227 | {
|
---|
228 | pcidev->resource[resNo].flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO;
|
---|
229 | pcidev->resource[resNo].start = ulTmp1 & PCI_BASE_ADDRESS_IO_MASK;
|
---|
230 | pcidev->resource[resNo].end = pcidev->resource[resNo].start +
|
---|
231 | ~(ulTmp2 & PCI_BASE_ADDRESS_IO_MASK) + 1;
|
---|
232 | }
|
---|
233 | else
|
---|
234 | {
|
---|
235 | pcidev->resource[resNo].flags = IORESOURCE_MEM | IORESOURCE_MEM_WRITEABLE;
|
---|
236 | pcidev->resource[resNo].start = ulTmp1 & PCI_BASE_ADDRESS_MEM_MASK;
|
---|
237 | pcidev->resource[resNo].end = pcidev->resource[resNo].start +
|
---|
238 | ~(ulTmp2 & PCI_BASE_ADDRESS_MEM_MASK) + 1;
|
---|
239 | }
|
---|
240 |
|
---|
241 | resNo++;
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | // IRQ and PIN
|
---|
246 | pci_read_config_dword(pcidev, PCI_INTERRUPT_LINE, &ulTmp1);
|
---|
247 | //rprintf(("pci_query_device: PCI config IRQ=%d", ulTmp1&0xff));
|
---|
248 | if( (u8)ulTmp1 && (u8)ulTmp1 != 0xff )
|
---|
249 | {
|
---|
250 | pcidev->irq_resource[0].flags = IORESOURCE_IRQ;
|
---|
251 | pcidev->irq_resource[0].start = pcidev->irq_resource[0].end = ulTmp1 & 0xffff;
|
---|
252 | pcidev->irq = (u8)ulTmp1; // This is the interrupt used for init time processing
|
---|
253 | pcidev->irq_pin = ulTmp1>>8;
|
---|
254 | }
|
---|
255 |
|
---|
256 | return ((busNr << 8) | PCI_DEVFN(devNr, funcNr));
|
---|
257 | } /* for funcNr */
|
---|
258 | funcNr = 0;
|
---|
259 | } /* for devNr */
|
---|
260 | devNr = 0;
|
---|
261 | }
|
---|
262 | outl(cfgaddrreg, PCI_CONFIG_ADDRESS);
|
---|
263 | return 0;
|
---|
264 | }
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * Called by: snd_pci_dev_present, various sound drivers
|
---|
268 | *
|
---|
269 | * Find the requested device
|
---|
270 | */
|
---|
271 | struct pci_dev *pci_find_device (unsigned int vendor, unsigned int device, struct pci_dev *from)
|
---|
272 | {
|
---|
273 | int i;
|
---|
274 | struct pci_device_id id_table;
|
---|
275 |
|
---|
276 | for(i=0; i<MAX_PCI_DEVICES; i++)
|
---|
277 | {
|
---|
278 | if ( pci_devices[i].devfn && (pci_devices[i].vendor == vendor) && (pci_devices[i].device == device) ) return &pci_devices[i];
|
---|
279 | }
|
---|
280 |
|
---|
281 | for(i=0; i<MAX_PCI_DEVICES; i++)
|
---|
282 | {
|
---|
283 | if(pci_devices[i].devfn == 0)
|
---|
284 | {
|
---|
285 | memset(&id_table, 0, sizeof(id_table));
|
---|
286 | id_table.vendor = vendor;
|
---|
287 | id_table.device = device;
|
---|
288 | if( pci_query_device(&id_table, (struct pci_dev near *)&pci_devices[i], 0) ) return &pci_devices[i];
|
---|
289 | else break;
|
---|
290 | }
|
---|
291 | }
|
---|
292 |
|
---|
293 | return NULL;
|
---|
294 | }
|
---|
295 |
|
---|
296 | /** __request_region
|
---|
297 | */
|
---|
298 | struct resource * __request_region(struct resource *a, unsigned long start, unsigned long n, const char *name)
|
---|
299 | {
|
---|
300 | struct resource *resource;
|
---|
301 |
|
---|
302 | if(a->flags & IORESOURCE_MEM) {
|
---|
303 | if(RMRequestMem(/*hResMgr,*/ start, n) == FALSE) {
|
---|
304 | printk("RMRequestIO failed for io %x, length %x\n", start, n);
|
---|
305 | return NULL;
|
---|
306 | }
|
---|
307 | }
|
---|
308 | else if(a->flags & IORESOURCE_IO) {
|
---|
309 | if(RMRequestIO(/*hResMgr,*/ start, n) == FALSE) {
|
---|
310 | printk("RMRequestIO failed for io %x, length %x\n", start, n);
|
---|
311 | return NULL;
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | resource = kmalloc(sizeof(struct resource), GFP_KERNEL);
|
---|
316 | if (resource == NULL)
|
---|
317 | return NULL;
|
---|
318 | resource->name = name;
|
---|
319 | resource->start = start;
|
---|
320 | resource->end = start + n; // - 1;
|
---|
321 | resource->flags = a->flags;
|
---|
322 | resource->parent =
|
---|
323 | resource->child = NULL;
|
---|
324 |
|
---|
325 | // insert in list
|
---|
326 | resource->sibling = a->sibling;
|
---|
327 | a->sibling = resource;
|
---|
328 |
|
---|
329 | return resource;
|
---|
330 | }
|
---|
331 |
|
---|
332 | /**
|
---|
333 | */
|
---|
334 | void __release_region(struct resource *a, unsigned long start, unsigned long n)
|
---|
335 | {
|
---|
336 | struct resource *resource;
|
---|
337 | struct resource **ppres = &a->sibling;
|
---|
338 | unsigned long end = start + n; // - 1;
|
---|
339 |
|
---|
340 | while( *ppres )
|
---|
341 | {
|
---|
342 | resource = *ppres;
|
---|
343 |
|
---|
344 | if( resource->start == start && resource->end == end )
|
---|
345 | {
|
---|
346 | // remove from list
|
---|
347 | *ppres = resource->sibling;
|
---|
348 | kfree(resource);
|
---|
349 | return;
|
---|
350 | }
|
---|
351 |
|
---|
352 | ppres = &resource->sibling;
|
---|
353 | }
|
---|
354 | }
|
---|
355 |
|
---|
356 | /**
|
---|
357 | */
|
---|
358 | int pci_get_flags (struct pci_dev *dev, int n_base)
|
---|
359 | {
|
---|
360 | if(n_base >= DEVICE_COUNT_RESOURCE || !dev->resource[n_base].flags) {
|
---|
361 | DebugInt3();
|
---|
362 | return 0;
|
---|
363 | }
|
---|
364 | return dev->resource[n_base].flags;
|
---|
365 | }
|
---|
366 |
|
---|
367 | /**
|
---|
368 | */
|
---|
369 | int pcibios_present(void)
|
---|
370 | {
|
---|
371 | printk("pcibios_present -> pretend BIOS present\n");
|
---|
372 | return 1;
|
---|
373 | }
|
---|
374 |
|
---|
375 | /**
|
---|
376 | */
|
---|
377 | struct pci_dev *pci_find_slot (unsigned int bus, unsigned int devfn)
|
---|
378 | {
|
---|
379 | printk("pci_find_slot %d %x not implemented!!\n", bus, devfn);
|
---|
380 | DebugInt3();
|
---|
381 | return NULL;
|
---|
382 | }
|
---|
383 |
|
---|
384 | /**
|
---|
385 | */
|
---|
386 | int pci_dma_supported(struct pci_dev *dev, unsigned long mask)
|
---|
387 | {
|
---|
388 | printk("pci_dma_supported: return TRUE\n");
|
---|
389 | return 1;
|
---|
390 | }
|
---|
391 |
|
---|
392 | /**
|
---|
393 | */
|
---|
394 | int pci_find_capability(struct pci_dev *dev, int cap)
|
---|
395 | {
|
---|
396 | u16 status;
|
---|
397 | u8 pos, id;
|
---|
398 | int ttl = 48;
|
---|
399 |
|
---|
400 | pci_read_config_word(dev, PCI_STATUS, &status);
|
---|
401 | if (!(status & PCI_STATUS_CAP_LIST))
|
---|
402 | return 0;
|
---|
403 | pci_read_config_byte(dev, PCI_CAPABILITY_LIST, &pos);
|
---|
404 | while (ttl-- && pos >= 0x40) {
|
---|
405 | pos &= ~3;
|
---|
406 | pci_read_config_byte(dev, pos + PCI_CAP_LIST_ID, &id);
|
---|
407 | if (id == 0xff)
|
---|
408 | break;
|
---|
409 | if (id == cap)
|
---|
410 | return pos;
|
---|
411 | pci_read_config_byte(dev, pos + PCI_CAP_LIST_NEXT, &pos);
|
---|
412 | }
|
---|
413 | return 0;
|
---|
414 | }
|
---|
415 |
|
---|
416 | /**
|
---|
417 | * Set power management state of a device. For transitions from state D3
|
---|
418 | * it isn't as straightforward as one could assume since many devices forget
|
---|
419 | * their configuration space during wakeup. Returns old power state.
|
---|
420 | */
|
---|
421 | int pci_set_power_state(struct pci_dev *dev, int new_state)
|
---|
422 | {
|
---|
423 | u32 base[5], romaddr;
|
---|
424 | u16 pci_command, pwr_command;
|
---|
425 | u8 pci_latency, pci_cacheline;
|
---|
426 | int i, old_state;
|
---|
427 | int pm = pci_find_capability(dev, PCI_CAP_ID_PM);
|
---|
428 |
|
---|
429 | if (!pm)
|
---|
430 | return 0;
|
---|
431 | pci_read_config_word(dev, pm + PCI_PM_CTRL, &pwr_command);
|
---|
432 | old_state = pwr_command & PCI_PM_CTRL_STATE_MASK;
|
---|
433 | if (old_state == new_state)
|
---|
434 | return old_state;
|
---|
435 | if (old_state == 3) {
|
---|
436 | pci_read_config_word(dev, PCI_COMMAND, &pci_command);
|
---|
437 | pci_write_config_word(dev, PCI_COMMAND, pci_command & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
|
---|
438 | for (i = 0; i < 5; i++)
|
---|
439 | pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + i*4, &base[i]);
|
---|
440 | pci_read_config_dword(dev, PCI_ROM_ADDRESS, &romaddr);
|
---|
441 | pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency);
|
---|
442 | pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &pci_cacheline);
|
---|
443 | pci_write_config_word(dev, pm + PCI_PM_CTRL, new_state);
|
---|
444 | for (i = 0; i < 5; i++)
|
---|
445 | pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + i*4, base[i]);
|
---|
446 | pci_write_config_dword(dev, PCI_ROM_ADDRESS, romaddr);
|
---|
447 | pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
|
---|
448 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, pci_cacheline);
|
---|
449 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, pci_latency);
|
---|
450 | pci_write_config_word(dev, PCI_COMMAND, pci_command);
|
---|
451 | } else
|
---|
452 | pci_write_config_word(dev, pm + PCI_PM_CTRL, (pwr_command & ~PCI_PM_CTRL_STATE_MASK) | new_state);
|
---|
453 | return old_state;
|
---|
454 | }
|
---|
455 |
|
---|
456 | /**
|
---|
457 | * Initialize device before it's used by a driver. Ask low-level code
|
---|
458 | * to enable I/O and memory. Wake up the device if it was suspended.
|
---|
459 | * Beware, this function can fail.
|
---|
460 | */
|
---|
461 | int pci_enable_device(struct pci_dev *dev)
|
---|
462 | {
|
---|
463 | u16 pci_command;
|
---|
464 |
|
---|
465 | dprintf(("pci_enable_device %x\n", dev));
|
---|
466 |
|
---|
467 | pci_read_config_word(dev, PCI_COMMAND, &pci_command);
|
---|
468 | pci_write_config_word(dev, PCI_COMMAND, pci_command | (PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
|
---|
469 | pci_set_power_state(dev, 0);
|
---|
470 | return 0;
|
---|
471 | }
|
---|
472 |
|
---|
473 | /** pci_register_driver
|
---|
474 | *
|
---|
475 | * probes and registers a sound driver with RM.
|
---|
476 | *
|
---|
477 | * Returns: number of cards found.
|
---|
478 | */
|
---|
479 | int pci_register_driver(struct pci_driver *driver)
|
---|
480 | {
|
---|
481 | int iNumCards, iTmp;
|
---|
482 | ULONG ulLast;
|
---|
483 | struct pci_dev *pcidev;
|
---|
484 | struct pci_device_id IdTable;
|
---|
485 | int iAdapter = 0;
|
---|
486 |
|
---|
487 | if (!driver->probe) return 0;
|
---|
488 |
|
---|
489 | iNumCards = 0;
|
---|
490 |
|
---|
491 | /* find an empty slot */
|
---|
492 | for (iTmp=0; iTmp<MAX_PCI_DEVICES; iTmp++)
|
---|
493 | {
|
---|
494 | if (pci_devices[iTmp].devfn == 0) break;
|
---|
495 | }
|
---|
496 | if (iTmp >= MAX_PCI_DEVICES) return 0;
|
---|
497 | pcidev = &pci_devices[iTmp];
|
---|
498 |
|
---|
499 | memset(&IdTable, 0, sizeof(IdTable));
|
---|
500 | IdTable.class = 0x000400 << 8; /* Any multimedia device */
|
---|
501 | IdTable.class_mask = 0xffff00 << 8;
|
---|
502 | ulLast = 0;
|
---|
503 | while( (ulLast = pci_query_device(&IdTable, pcidev, ulLast)) != 0 )
|
---|
504 | {
|
---|
505 | int iTableIx;
|
---|
506 |
|
---|
507 | rprintf(("pci_register_driver: query_device found %x %x:%x class=%x checking %s",
|
---|
508 | ulLast, pcidev->vendor, pcidev->device, pcidev->class, driver->name));
|
---|
509 |
|
---|
510 | for( iTableIx = 0; driver->id_table[iTableIx].vendor; iTableIx++)
|
---|
511 | {
|
---|
512 | struct pci_device_id const *pDriverId = &driver->id_table[iTableIx];
|
---|
513 |
|
---|
514 | if ( (pDriverId->class) && ((pcidev->class & pDriverId->class_mask) != pDriverId->class) ) continue;
|
---|
515 | if (pDriverId->vendor != pcidev->vendor) continue;
|
---|
516 | if ( (pDriverId->device != PCI_ANY_ID) && (pDriverId->device != pcidev->device) ) continue;
|
---|
517 |
|
---|
518 | rprintf(("pci_register_driver: matched %d %x:%x/%x with %x:%x/%x %x (%s)", iTableIx,
|
---|
519 | pcidev->vendor, pcidev->device, pcidev->class,
|
---|
520 | pDriverId->vendor, pDriverId->device, pDriverId->class, pDriverId->class_mask, driver->name));
|
---|
521 |
|
---|
522 | if ((iAdapterNumber >= 0) && (iAdapter < iAdapterNumber))
|
---|
523 | {
|
---|
524 | iAdapter++;
|
---|
525 | continue;
|
---|
526 | }
|
---|
527 |
|
---|
528 | RMInit();
|
---|
529 | if (driver->probe(pcidev, pDriverId) == 0)
|
---|
530 | {
|
---|
531 | pcidev->pcidriver = (void *)driver;
|
---|
532 | pcidev->current_state = 4;
|
---|
533 |
|
---|
534 | // create adapter
|
---|
535 | RMDone((pcidev->device << 16) | pcidev->vendor, &pcidev->hAdapter, &pcidev->hDevice);
|
---|
536 | iNumCards++;
|
---|
537 | pcidev = NULL; /* we need a new slot */
|
---|
538 | break;
|
---|
539 | }
|
---|
540 | RMDone(0, 0, 0);
|
---|
541 | } /* for id_table loop */
|
---|
542 |
|
---|
543 | if (pcidev)
|
---|
544 | {
|
---|
545 | kfree(pcidev->bus);
|
---|
546 | pcidev->devfn = 0;
|
---|
547 | }
|
---|
548 | else
|
---|
549 | {
|
---|
550 | if (iAdapterNumber >= 0) break;
|
---|
551 | /* find another empty slot */
|
---|
552 | for (iTmp=0; iTmp<MAX_PCI_DEVICES; iTmp++)
|
---|
553 | {
|
---|
554 | if (pci_devices[iTmp].devfn == 0) break;
|
---|
555 | }
|
---|
556 | if (iTmp >= MAX_PCI_DEVICES) break;
|
---|
557 | pcidev = &pci_devices[iTmp];
|
---|
558 | }
|
---|
559 | } /* pci_query_device loop */
|
---|
560 |
|
---|
561 | return iNumCards;
|
---|
562 | }
|
---|
563 |
|
---|
564 | /**
|
---|
565 | */
|
---|
566 | int pci_module_init(struct pci_driver *drv)
|
---|
567 | {
|
---|
568 | int res = pci_register_driver(drv);
|
---|
569 | if (res == 0) return -ENODEV;
|
---|
570 | return res;
|
---|
571 | }
|
---|
572 |
|
---|
573 | /**
|
---|
574 | */
|
---|
575 | int pci_unregister_driver(struct pci_driver *driver)
|
---|
576 | {
|
---|
577 | struct pci_dev *pcidev;
|
---|
578 | int i, j;
|
---|
579 |
|
---|
580 | for (i=0; driver->id_table[i].vendor; i++) {
|
---|
581 | for(j=0; j<MAX_PCI_DEVICES; j++) {
|
---|
582 | pcidev = &pci_devices[j];
|
---|
583 | if (pcidev->devfn == 0) continue;
|
---|
584 | if (pcidev->vendor != driver->id_table[i].vendor) continue;
|
---|
585 | if ( (driver->id_table[i].device != PCI_ANY_ID) && (pcidev->device != driver->id_table[i].device) ) continue;
|
---|
586 | dprintf(("pci unreg match: %x:%x %x:%x", pci_devices[j].vendor, pci_devices[j].device, driver->id_table[i].vendor, driver->id_table[i].device));
|
---|
587 | if (driver->remove) driver->remove(pcidev);
|
---|
588 | kfree(pcidev->bus);
|
---|
589 | pcidev->devfn = 0;
|
---|
590 | }
|
---|
591 | }
|
---|
592 | return 0;
|
---|
593 | }
|
---|
594 |
|
---|
595 | /**
|
---|
596 | */
|
---|
597 | void pci_set_master(struct pci_dev *dev)
|
---|
598 | {
|
---|
599 | u16 cmd;
|
---|
600 |
|
---|
601 | pci_read_config_word(dev, PCI_COMMAND, &cmd);
|
---|
602 | if (! (cmd & PCI_COMMAND_MASTER)) {
|
---|
603 | dprintf(("pci_set_master %x", dev));
|
---|
604 | cmd |= PCI_COMMAND_MASTER;
|
---|
605 | pci_write_config_word(dev, PCI_COMMAND, cmd);
|
---|
606 | }
|
---|
607 | return;
|
---|
608 | }
|
---|
609 |
|
---|
610 | /**
|
---|
611 | * Register a device with power management
|
---|
612 | */
|
---|
613 | struct pm_dev *pm_register(pm_dev_t type, unsigned long id, pm_callback callback)
|
---|
614 | {
|
---|
615 | dprintf(("pm_register STUB"));
|
---|
616 | DebugInt3();
|
---|
617 | return NULL;
|
---|
618 | }
|
---|
619 |
|
---|
620 | /**
|
---|
621 | * Unregister a device with power management
|
---|
622 | */
|
---|
623 | void pm_unregister(struct pm_dev *dev)
|
---|
624 | {
|
---|
625 | dprintf(("pm_unregister STUB"));
|
---|
626 | }
|
---|
627 |
|
---|
628 | /**
|
---|
629 | */
|
---|
630 | int __compat_get_order(unsigned long size)
|
---|
631 | {
|
---|
632 | int order;
|
---|
633 |
|
---|
634 | size = (size-1) >> (PAGE_SHIFT-1);
|
---|
635 | order = -1;
|
---|
636 | do {
|
---|
637 | size >>= 1;
|
---|
638 | order++;
|
---|
639 | } while (size);
|
---|
640 | return order;
|
---|
641 | }
|
---|
642 |
|
---|
643 | /**
|
---|
644 | */
|
---|
645 | void *pci_alloc_consistent(struct pci_dev *hwdev,
|
---|
646 | long size, dma_addr_t *dma_handle)
|
---|
647 | {
|
---|
648 | void *ret = NULL;
|
---|
649 | int gfp = GFP_ATOMIC;
|
---|
650 | int order;
|
---|
651 | dprintf(("pci_alloc_consistent %d mask %x", size, (hwdev) ? hwdev->dma_mask : 0));
|
---|
652 | if (hwdev == NULL || hwdev->dma_mask != 0xffffffff) {
|
---|
653 | //try not to exhaust low memory (< 16mb) so allocate from the high region first
|
---|
654 | //if that doesn't satisfy the dma mask requirement, then get it from the low
|
---|
655 | //region anyway
|
---|
656 | if(hwdev->dma_mask > 0x00ffffff) {
|
---|
657 | order = __compat_get_order(size);
|
---|
658 | ret = (void *)__get_free_pages(gfp|GFP_DMAHIGHMEM, order);
|
---|
659 | *dma_handle = virt_to_bus(ret);
|
---|
660 | if(*dma_handle > hwdev->dma_mask) {
|
---|
661 | free_pages((unsigned long)ret, __compat_get_order(size));
|
---|
662 | //be sure and allocate below 16 mb
|
---|
663 | gfp |= GFP_DMA;
|
---|
664 | ret = NULL;
|
---|
665 | }
|
---|
666 | }
|
---|
667 | else { //must always allocate below 16 mb
|
---|
668 | gfp |= GFP_DMA;
|
---|
669 | }
|
---|
670 | }
|
---|
671 | if(ret == NULL) {
|
---|
672 | ret = (void *)__get_free_pages(gfp, __compat_get_order(size));
|
---|
673 | }
|
---|
674 | if (ret != NULL) {
|
---|
675 | memset(ret, 0, size);
|
---|
676 | *dma_handle = virt_to_bus(ret);
|
---|
677 | }
|
---|
678 | return ret;
|
---|
679 | }
|
---|
680 |
|
---|
681 | #if 0
|
---|
682 | void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
|
---|
683 | dma_addr_t *dma_handle)
|
---|
684 | {
|
---|
685 | return dma_alloc_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, dma_handle, GFP_ATOMIC);
|
---|
686 | }
|
---|
687 | #endif
|
---|
688 | #if 0
|
---|
689 | void *dma_alloc_coherent(struct device *dev, size_t size,
|
---|
690 | dma_addr_t *dma_handle, gfp_t gfp)
|
---|
691 | {
|
---|
692 | void *ret = NULL;
|
---|
693 | int order;
|
---|
694 |
|
---|
695 | dprintf(("dma_alloc_coherent %d mask %x", size, (dev) ? dev->dma_mask : 0));
|
---|
696 | if (dev == NULL || *dev->dma_mask != 0xffffffff) {
|
---|
697 | dprintf(("dma_alloc_coherent"));
|
---|
698 | //try not to exhaust low memory (< 16mb) so allocate from the high region first
|
---|
699 | //if that doesn't satisfy the dma mask requirement, then get it from the low
|
---|
700 | //region anyway
|
---|
701 | if(*dev->dma_mask > 0x00ffffff) {
|
---|
702 | dprintf(("dma_alloc_coherent2"));
|
---|
703 | order = __compat_get_order(size);
|
---|
704 | ret = (void *)__get_free_pages(gfp|GFP_DMAHIGHMEM, order);
|
---|
705 | *dma_handle = virt_to_bus(ret);
|
---|
706 | if(*dma_handle > *dev->dma_mask) {
|
---|
707 | dprintf(("dma_alloc_coherent3"));
|
---|
708 | free_pages((unsigned long)ret, __compat_get_order(size));
|
---|
709 | //be sure and allocate below 16 mb
|
---|
710 | gfp |= GFP_DMA;
|
---|
711 | ret = NULL;
|
---|
712 | }
|
---|
713 | dprintf(("dma_alloc_coherent3a"));
|
---|
714 | }
|
---|
715 | else { //must always allocate below 16 mb
|
---|
716 | dprintf(("dma_alloc_coherent4"));
|
---|
717 | gfp |= GFP_DMA;
|
---|
718 | }
|
---|
719 | }
|
---|
720 | if(ret == NULL) {
|
---|
721 | dprintf(("dma_alloc_coherent5"));
|
---|
722 | ret = (void *)__get_free_pages(gfp, __compat_get_order(size));
|
---|
723 | }
|
---|
724 |
|
---|
725 | if (ret != NULL) {
|
---|
726 | memset(ret, 0, size);
|
---|
727 | *dma_handle = virt_to_bus(ret);
|
---|
728 | }
|
---|
729 | return ret;
|
---|
730 |
|
---|
731 | }
|
---|
732 | #endif
|
---|
733 |
|
---|
734 | int dma_supported(struct device *dev, u64 mask)
|
---|
735 | {
|
---|
736 | return 1;
|
---|
737 | }
|
---|
738 |
|
---|
739 | int dma_set_coherent_mask(struct device *dev, u64 mask)
|
---|
740 | {
|
---|
741 | /*
|
---|
742 | * Truncate the mask to the actually supported dma_addr_t width to
|
---|
743 | * avoid generating unsupportable addresses.
|
---|
744 | */
|
---|
745 | mask = (dma_addr_t)mask;
|
---|
746 |
|
---|
747 | if (!dma_supported(dev, mask))
|
---|
748 | return -EIO;
|
---|
749 |
|
---|
750 | dev->coherent_dma_mask = mask;
|
---|
751 | return 0;
|
---|
752 | }
|
---|
753 |
|
---|
754 | int dma_set_mask(struct device *dev, u64 mask)
|
---|
755 | {
|
---|
756 | /*
|
---|
757 | * Truncate the mask to the actually supported dma_addr_t width to
|
---|
758 | * avoid generating unsupportable addresses.
|
---|
759 | */
|
---|
760 | mask = (dma_addr_t)mask;
|
---|
761 |
|
---|
762 | if (!dev->dma_mask || !dma_supported(dev, mask))
|
---|
763 | return -EIO;
|
---|
764 |
|
---|
765 | *dev->dma_mask = mask;
|
---|
766 | return 0;
|
---|
767 | }
|
---|
768 |
|
---|
769 | /**
|
---|
770 | */
|
---|
771 | void pci_free_consistent(struct pci_dev *hwdev, long size,
|
---|
772 | void *vaddr, dma_addr_t dma_handle)
|
---|
773 | {
|
---|
774 | free_pages((unsigned long)vaddr, __compat_get_order(size));
|
---|
775 | }
|
---|
776 |
|
---|
777 | /**
|
---|
778 | */
|
---|
779 | void pci_set_driver_data (struct pci_dev *dev, void *driver_data)
|
---|
780 | {
|
---|
781 | if (dev)
|
---|
782 | dev->driver_data = driver_data;
|
---|
783 | }
|
---|
784 |
|
---|
785 | /**
|
---|
786 | */
|
---|
787 | void *pci_get_driver_data (struct pci_dev *dev)
|
---|
788 | {
|
---|
789 | if (dev)
|
---|
790 | return dev->driver_data;
|
---|
791 | return 0;
|
---|
792 | }
|
---|
793 |
|
---|
794 | /**
|
---|
795 | */
|
---|
796 | unsigned long pci_get_dma_mask (struct pci_dev *dev)
|
---|
797 | {
|
---|
798 | if (dev)
|
---|
799 | return dev->dma_mask;
|
---|
800 | return 0;
|
---|
801 | }
|
---|
802 |
|
---|
803 | /**
|
---|
804 | */
|
---|
805 | int release_resource(struct resource *newres)
|
---|
806 | {
|
---|
807 | return 0;
|
---|
808 | }
|
---|
809 |
|
---|
810 | /**
|
---|
811 | */
|
---|
812 | int pci_set_latency_time(struct pci_dev *dev, int latency)
|
---|
813 | {
|
---|
814 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, latency);
|
---|
815 | return 0;
|
---|
816 | }
|
---|
817 |
|
---|
818 | /**
|
---|
819 | * pci_save_state - save the PCI configuration space of a device before suspending
|
---|
820 | * @dev: - PCI device that we're dealing with
|
---|
821 | * @buffer: - buffer to hold config space context
|
---|
822 | *
|
---|
823 | * @buffer must be large enough to hold the entire PCI 2.2 config space
|
---|
824 | * (>= 64 bytes).
|
---|
825 | */
|
---|
826 | int pci_orig_save_state(struct pci_dev *dev, u32 *buffer)
|
---|
827 | {
|
---|
828 | int i;
|
---|
829 | if (buffer) {
|
---|
830 | /* XXX: 100% dword access ok here? */
|
---|
831 | for (i = 0; i < 16; i++)
|
---|
832 | pci_read_config_dword(dev, i * 4,&buffer[i]);
|
---|
833 | }
|
---|
834 | return 0;
|
---|
835 | }
|
---|
836 |
|
---|
837 | /**
|
---|
838 | * pci_restore_state - Restore the saved state of a PCI device
|
---|
839 | * @dev: - PCI device that we're dealing with
|
---|
840 | * @buffer: - saved PCI config space
|
---|
841 | *
|
---|
842 | */
|
---|
843 | int pci_orig_restore_state(struct pci_dev *dev, u32 *buffer)
|
---|
844 | {
|
---|
845 | int i;
|
---|
846 |
|
---|
847 | if (buffer) {
|
---|
848 | for (i = 0; i < 16; i++)
|
---|
849 | pci_write_config_dword(dev,i * 4, buffer[i]);
|
---|
850 | }
|
---|
851 | /*
|
---|
852 | * otherwise, write the context information we know from bootup.
|
---|
853 | * This works around a problem where warm-booting from Windows
|
---|
854 | * combined with a D3(hot)->D0 transition causes PCI config
|
---|
855 | * header data to be forgotten.
|
---|
856 | */
|
---|
857 | else {
|
---|
858 | for (i = 0; i < 6; i ++)
|
---|
859 | pci_write_config_dword(dev,
|
---|
860 | PCI_BASE_ADDRESS_0 + (i * 4),
|
---|
861 | dev->resource[i].start);
|
---|
862 | pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
|
---|
863 | }
|
---|
864 | return 0;
|
---|
865 | }
|
---|
866 |
|
---|
867 | struct saved_config_tbl {
|
---|
868 | struct pci_dev *pci;
|
---|
869 | u32 config[16];
|
---|
870 | };
|
---|
871 | static struct saved_config_tbl saved_tbl[16];
|
---|
872 |
|
---|
873 | int pci_save_state(struct pci_dev *pci)
|
---|
874 | {
|
---|
875 | int i;
|
---|
876 | /* FIXME: mutex needed for race? */
|
---|
877 | for (i = 0; i < ARRAY_SIZE(saved_tbl); i++) {
|
---|
878 | if (! saved_tbl[i].pci) {
|
---|
879 | saved_tbl[i].pci = pci;
|
---|
880 | pci_orig_save_state(pci, saved_tbl[i].config);
|
---|
881 | return 1;
|
---|
882 | }
|
---|
883 | }
|
---|
884 | printk(KERN_DEBUG "snd: no pci config space found!\n");
|
---|
885 | return 0;
|
---|
886 | }
|
---|
887 |
|
---|
888 | int pci_restore_state(struct pci_dev *pci)
|
---|
889 | {
|
---|
890 | int i;
|
---|
891 | /* FIXME: mutex needed for race? */
|
---|
892 | for (i = 0; i < ARRAY_SIZE(saved_tbl); i++) {
|
---|
893 | if (saved_tbl[i].pci == pci) {
|
---|
894 | saved_tbl[i].pci = NULL;
|
---|
895 | pci_orig_restore_state(pci, saved_tbl[i].config);
|
---|
896 | return 0;
|
---|
897 | }
|
---|
898 | }
|
---|
899 | printk(KERN_DEBUG "snd: no saved pci config!\n");
|
---|
900 | return 1;
|
---|
901 | }
|
---|
902 |
|
---|
903 | void pci_disable_device(struct pci_dev *dev)
|
---|
904 | {
|
---|
905 | u16 pci_command;
|
---|
906 |
|
---|
907 | pci_read_config_word(dev, PCI_COMMAND, &pci_command);
|
---|
908 | if (pci_command & PCI_COMMAND_MASTER) {
|
---|
909 | pci_command &= ~PCI_COMMAND_MASTER;
|
---|
910 | pci_write_config_word(dev, PCI_COMMAND, pci_command);
|
---|
911 | }
|
---|
912 | }
|
---|
913 |
|
---|
914 | int pci_request_region(struct pci_dev *pdev, int bar, char *res_name)
|
---|
915 | {
|
---|
916 | int flags;
|
---|
917 |
|
---|
918 | if (pci_resource_len(pdev, bar) == 0)
|
---|
919 | return 0;
|
---|
920 | flags = pci_get_flags(pdev, bar);
|
---|
921 | if (flags & IORESOURCE_IO) {
|
---|
922 | if (check_region(pci_resource_start(pdev, bar), pci_resource_len(pdev, bar)))
|
---|
923 | goto err_out;
|
---|
924 | request_region(pci_resource_start(pdev, bar),
|
---|
925 | pci_resource_len(pdev, bar), res_name);
|
---|
926 | }
|
---|
927 | else if (flags & IORESOURCE_MEM) {
|
---|
928 | if (check_mem_region(pci_resource_start(pdev, bar), pci_resource_len(pdev, bar)))
|
---|
929 | goto err_out;
|
---|
930 | request_mem_region(pci_resource_start(pdev, bar),
|
---|
931 | pci_resource_len(pdev, bar), res_name);
|
---|
932 | }
|
---|
933 |
|
---|
934 | return 0;
|
---|
935 |
|
---|
936 | err_out:
|
---|
937 | printk(KERN_WARNING "PCI: Unable to reserve %s region #%d:%lx@%lx for device %s\n",
|
---|
938 | flags & IORESOURCE_IO ? "I/O" : "mem",
|
---|
939 | bar + 1, /* PCI BAR # */
|
---|
940 | pci_resource_len(pdev, bar), pci_resource_start(pdev, bar),
|
---|
941 | res_name);
|
---|
942 | return -EBUSY;
|
---|
943 | }
|
---|
944 |
|
---|
945 | void pci_release_region(struct pci_dev *pdev, int bar)
|
---|
946 | {
|
---|
947 | int flags;
|
---|
948 |
|
---|
949 | if (pci_resource_len(pdev, bar) == 0)
|
---|
950 | return;
|
---|
951 | flags = pci_get_flags(pdev, bar);
|
---|
952 | if (flags & IORESOURCE_IO) {
|
---|
953 | release_region(pci_resource_start(pdev, bar),
|
---|
954 | pci_resource_len(pdev, bar));
|
---|
955 | }
|
---|
956 | else if (flags & IORESOURCE_MEM) {
|
---|
957 | release_mem_region(pci_resource_start(pdev, bar),
|
---|
958 | pci_resource_len(pdev, bar));
|
---|
959 | }
|
---|
960 | }
|
---|
961 |
|
---|
962 | int pci_request_regions(struct pci_dev *pdev, char *res_name)
|
---|
963 | {
|
---|
964 | int i;
|
---|
965 |
|
---|
966 | for (i = 0; i < 6; i++)
|
---|
967 | if (pci_request_region(pdev, i, res_name))
|
---|
968 | goto err;
|
---|
969 | return 0;
|
---|
970 | err:
|
---|
971 | while (--i >= 0)
|
---|
972 | pci_release_region(pdev, i);
|
---|
973 | return -EBUSY;
|
---|
974 | }
|
---|
975 |
|
---|
976 | void pci_release_regions(struct pci_dev *pdev)
|
---|
977 | {
|
---|
978 | int i;
|
---|
979 | for (i = 0; i < 6; i++)
|
---|
980 | pci_release_region(pdev, i);
|
---|
981 | }
|
---|
982 |
|
---|
983 | const struct pci_device_id * pci_match_id(const struct pci_device_id *ids, struct pci_dev *dev)
|
---|
984 | {
|
---|
985 | u16 subsystem_vendor, subsystem_device;
|
---|
986 |
|
---|
987 | pci_read_config_word(dev, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);
|
---|
988 | pci_read_config_word(dev, PCI_SUBSYSTEM_ID, &subsystem_device);
|
---|
989 |
|
---|
990 | while (ids->vendor || ids->subvendor || ids->class_mask) {
|
---|
991 | if ((ids->vendor == PCI_ANY_ID || ids->vendor == dev->vendor) &&
|
---|
992 | (ids->device == PCI_ANY_ID || ids->device == dev->device) &&
|
---|
993 | (ids->subvendor == PCI_ANY_ID || ids->subvendor == subsystem_vendor) &&
|
---|
994 | (ids->subdevice == PCI_ANY_ID || ids->subdevice == subsystem_device) &&
|
---|
995 | !((ids->class ^ dev->class) & ids->class_mask))
|
---|
996 | return ids;
|
---|
997 | ids++;
|
---|
998 | }
|
---|
999 | return NULL;
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 | /** snd_pci_dev_present
|
---|
1003 | * Called by: various sound drivers
|
---|
1004 | */
|
---|
1005 | int snd_pci_dev_present(const struct pci_device_id *ids)
|
---|
1006 | {
|
---|
1007 | while (ids->vendor || ids->subvendor)
|
---|
1008 | {
|
---|
1009 | if (pci_find_device(ids->vendor, ids->subvendor, NULL)) return 1;
|
---|
1010 | ids++;
|
---|
1011 | }
|
---|
1012 | return 0;
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | struct pci_driver_mapping {
|
---|
1016 | struct pci_dev *dev;
|
---|
1017 | struct pci_driver *drv;
|
---|
1018 | unsigned long dma_mask;
|
---|
1019 | void *driver_data;
|
---|
1020 | u32 saved_config[16];
|
---|
1021 | };
|
---|
1022 |
|
---|
1023 | #define PCI_MAX_MAPPINGS 64
|
---|
1024 | static struct pci_driver_mapping drvmap [PCI_MAX_MAPPINGS] = { { NULL, } , };
|
---|
1025 |
|
---|
1026 |
|
---|
1027 | static struct pci_driver_mapping *get_pci_driver_mapping(struct pci_dev *dev)
|
---|
1028 | {
|
---|
1029 | int i;
|
---|
1030 |
|
---|
1031 | for (i = 0; i < PCI_MAX_MAPPINGS; i++)
|
---|
1032 | if (drvmap[i].dev == dev)
|
---|
1033 | return &drvmap[i];
|
---|
1034 | return NULL;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | struct pci_driver *snd_pci_compat_get_pci_driver(struct pci_dev *dev)
|
---|
1038 | {
|
---|
1039 | struct pci_driver_mapping *map = get_pci_driver_mapping(dev);
|
---|
1040 | if (map)
|
---|
1041 | return map->drv;
|
---|
1042 | return NULL;
|
---|
1043 | }
|
---|
1044 | #if 0
|
---|
1045 | void * pci_get_drvdata (struct pci_dev *dev)
|
---|
1046 | {
|
---|
1047 | struct pci_driver_mapping *map = get_pci_driver_mapping(dev);
|
---|
1048 | if (map)
|
---|
1049 | return map->driver_data;
|
---|
1050 | return NULL;
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 |
|
---|
1054 | void pci_set_drvdata (struct pci_dev *dev, void *driver_data)
|
---|
1055 | {
|
---|
1056 | struct pci_driver_mapping *map = get_pci_driver_mapping(dev);
|
---|
1057 | if (map)
|
---|
1058 | map->driver_data = driver_data;
|
---|
1059 | }
|
---|
1060 | #endif
|
---|
1061 |
|
---|
1062 |
|
---|
1063 | //******************************************************************************
|
---|
1064 | //******************************************************************************
|
---|
1065 | OSSRET OSS32_APMResume()
|
---|
1066 | {
|
---|
1067 | int i;
|
---|
1068 | struct pci_driver *driver;
|
---|
1069 |
|
---|
1070 | dprintf(("OSS32_APMResume"));
|
---|
1071 |
|
---|
1072 | for(i=0;i<MAX_PCI_DEVICES;i++)
|
---|
1073 | {
|
---|
1074 | if(pci_devices[i].devfn)
|
---|
1075 | {
|
---|
1076 | RMSetHandles(pci_devices[i].hAdapter, pci_devices[i].hDevice); /* DAZ - dirty hack */
|
---|
1077 | driver = pci_devices[i].pcidriver;
|
---|
1078 | if(driver && driver->resume) {
|
---|
1079 | driver->resume(&pci_devices[i]);
|
---|
1080 | }
|
---|
1081 | }
|
---|
1082 | }
|
---|
1083 |
|
---|
1084 | return OSSERR_SUCCESS;
|
---|
1085 | }
|
---|
1086 | //******************************************************************************
|
---|
1087 | //******************************************************************************
|
---|
1088 | OSSRET OSS32_APMSuspend()
|
---|
1089 | {
|
---|
1090 | int i;
|
---|
1091 | struct pci_driver *driver;
|
---|
1092 |
|
---|
1093 | dprintf(("OSS32_APMSuspend 1"));
|
---|
1094 |
|
---|
1095 | for(i=0;i<MAX_PCI_DEVICES;i++)
|
---|
1096 | {
|
---|
1097 | if(pci_devices[i].devfn)
|
---|
1098 | {
|
---|
1099 | RMSetHandles(pci_devices[i].hAdapter, pci_devices[i].hDevice); /* DAZ - dirty hack */
|
---|
1100 | driver = pci_devices[i].pcidriver;
|
---|
1101 | if(driver && driver->suspend) {
|
---|
1102 | driver->suspend(&pci_devices[i], SNDRV_CTL_POWER_D3cold);
|
---|
1103 | }
|
---|
1104 | }
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | dprintf(("OSS32_APMSuspend 2"));
|
---|
1108 | return OSSERR_SUCCESS;
|
---|
1109 | }
|
---|
1110 |
|
---|
1111 | #ifdef USE_MSI
|
---|
1112 | extern int __syscall UniMsiAlloc(USHORT usBusDevFunc, ULONG *pulCount, UCHAR *pucIrq);
|
---|
1113 | int snd_pci_enable_msi(struct pci_dev *dev)
|
---|
1114 | {
|
---|
1115 | ULONG p;
|
---|
1116 | UCHAR irq;
|
---|
1117 |
|
---|
1118 | if (dev->irq_pin)
|
---|
1119 | {
|
---|
1120 | p = 1; /* int count */
|
---|
1121 | if (UniMsiAlloc((dev->bus->number<<8) | dev->devfn, &p, &irq)) return -1;
|
---|
1122 | /* we have an msi interrupt */
|
---|
1123 | dev->irq = irq;
|
---|
1124 | dev->irq_pin = 0;
|
---|
1125 | }
|
---|
1126 | return 0;
|
---|
1127 | }
|
---|
1128 | #else
|
---|
1129 | int snd_pci_enable_msi(struct pci_dev *dev)
|
---|
1130 | {
|
---|
1131 | return -1;
|
---|
1132 | }
|
---|
1133 | #endif
|
---|
1134 |
|
---|