source: GPL/branches/uniaud32-2.1.x/lib32/pci.c@ 592

Last change on this file since 592 was 592, checked in by David Azarewicz, 8 years ago

Remove dead code. update build system. Fix api interrupt defect.

File size: 30.5 KB
Line 
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 *
8 * Parts based on Linux kernel sources
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
27#include "linux.h"
28#include <linux/init.h>
29#include <linux/poll.h>
30#include <asm/uaccess.h>
31#include <asm/hardirq.h>
32#include <asm/io.h>
33#include <sound/config.h>
34#include <sound/core.h>
35#include <sound/asound.h>
36
37#define LINUX
38#include <ossidc.h>
39#include <stacktoflat.h>
40#include <dbgos2.h>
41#include <osspci.h>
42
43#define MAX_PCI_BUSSES 256
44#define MAX_PCI_DEVICES 16
45
46struct pci_dev pci_devices[MAX_PCI_DEVICES] = {0};
47//struct pci_bus pci_busses[MAX_PCI_BUSSES] = {0};
48
49extern int nrCardsDetected;
50
51
52#define PCI_CONFIG_ENABLE 0x80000000
53#define PCI_CONFIG_ADDRESS 0xCF8
54#define PCI_CONFIG_DATA 0xCFC
55
56//******************************************************************************
57#define CONFIG_CMD(dev, where) \
58 (PCI_CONFIG_ENABLE | (dev->bus->number<<16) | (dev->devfn<<8) | (where & ~3))
59//******************************************************************************
60int pci_read_config_byte(struct pci_dev *dev, int where, u8 *value)
61{
62 outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
63 *value = inb(PCI_CONFIG_DATA + (where&3));
64 return PCIBIOS_SUCCESSFUL;
65}
66//******************************************************************************
67//******************************************************************************
68int pci_read_config_word(struct pci_dev *dev, int where, u16 *value)
69{
70 outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
71 *value = inw(PCI_CONFIG_DATA + (where&2));
72 return PCIBIOS_SUCCESSFUL;
73}
74//******************************************************************************
75//******************************************************************************
76int pci_read_config_dword(struct pci_dev *dev, int where, u32 *value)
77{
78 outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
79 *value = inl(PCI_CONFIG_DATA);
80 return PCIBIOS_SUCCESSFUL;
81}
82//******************************************************************************
83//******************************************************************************
84int pci_write_config_byte(struct pci_dev *dev, int where, u8 value)
85{
86 outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
87 outb(value, PCI_CONFIG_DATA + (where&3));
88 return PCIBIOS_SUCCESSFUL;
89}
90//******************************************************************************
91//******************************************************************************
92int pci_write_config_word(struct pci_dev *dev, int where, u16 value)
93{
94 outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
95 outw(value, PCI_CONFIG_DATA + (where&2));
96 return PCIBIOS_SUCCESSFUL;
97}
98//******************************************************************************
99//******************************************************************************
100int pci_write_config_dword(struct pci_dev *dev, int where, u32 value)
101{
102 outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
103 outl(value, PCI_CONFIG_DATA);
104 return PCIBIOS_SUCCESSFUL;
105}
106//******************************************************************************
107//******************************************************************************
108int pcidev_prepare(struct pci_dev *dev)
109{
110 dprintf(("pcidev_prepare %x not implemented", dev));
111 return 1; //todo: correct return value??
112}
113//******************************************************************************
114//******************************************************************************
115int pcidev_activate(struct pci_dev *dev)
116{
117 dprintf(("pcidev_activate %x not implemented", dev));
118 return 1; //todo: correct return value??
119}
120//******************************************************************************
121//******************************************************************************
122int pcidev_deactivate(struct pci_dev *dev)
123{
124 dprintf(("pcidev_deactivate %x not implemented", dev));
125 return 1; //todo: correct return value??
126}
127
128
129
130//******************************************************************************
131//******************************************************************************
132//Find the next matching PCI device starting with the device specified by pcidev
133static ULONG pci_query_device(const struct pci_device_id *id_table, struct pci_dev near *pcidev, ULONG ulLast)
134{
135 int resNo, addr;
136 u32 devNr, busNr, funcNr, detectedId, cfgaddrreg, ulPciAdr, ulTmp1, ulTmp2;
137 u8 headerType;
138
139 busNr = (ulLast >> 8) & 0xff;
140 devNr = PCI_SLOT(ulLast);
141 funcNr = PCI_FUNC(ulLast);
142 if (ulLast) funcNr++;
143
144 cfgaddrreg = inl(PCI_CONFIG_ADDRESS);
145 for(;busNr<MAX_PCI_BUSSES;busNr++) { //BusNumber<255
146 for(;devNr<32;devNr++) {
147 for(;funcNr<8;funcNr++) {
148 headerType = 0;
149 ulPciAdr = PCI_CONFIG_ENABLE | (busNr<<16) | (devNr<<11) | (funcNr<<8);
150 outl(ulPciAdr, PCI_CONFIG_ADDRESS);
151 detectedId = inl(PCI_CONFIG_DATA);
152
153 if ( detectedId == 0xffffffff ) {
154 if ( funcNr == 0 ) break; /* if func 0 isn't there, the others aren't either */
155 continue;
156 }
157
158 outl(ulPciAdr + PCI_CLASS_REVISION, PCI_CONFIG_ADDRESS);
159 ulTmp2 = inl(PCI_CONFIG_DATA) >> 8; /* get class */
160
161 //dprintf(("det=%x(%x) %x need=%x%x %x", detectedId, headerType, ulTmp2, id_table->device&0xffff, id_table->vendor, id_table->class));
162
163 if ( id_table->class ) {
164 if ( (ulTmp2 & id_table->class_mask) != id_table->class ) continue;
165 } else {
166 if ( (id_table->device == PCI_ANY_ID) && ((ulTmp2 >> 8) != PCI_CLASS_MULTIMEDIA_AUDIO) ) continue;
167 }
168
169 if (id_table->vendor != (detectedId & 0xffff)) continue;
170 if ( (id_table->device != PCI_ANY_ID) && (id_table->device != (detectedId >> 16)) ) continue;
171
172 outl(ulPciAdr | (PCI_HEADER_TYPE & ~3), PCI_CONFIG_ADDRESS);
173 headerType = inb(PCI_CONFIG_DATA + (PCI_HEADER_TYPE & 3));
174
175 if ( (headerType & 0x7f) != PCI_HEADER_TYPE_NORMAL ) continue;
176
177 memset((void near *)pcidev, 0, sizeof(struct pci_dev));
178
179 pcidev->vendor = detectedId & 0xffff;
180 pcidev->device = detectedId >> 16;
181 //pcidev->bus = &pci_busses[busNr];
182 pcidev->bus = kmalloc(sizeof(struct pci_bus), GFP_KERNEL);
183 if (pcidev->bus == NULL) return 0;
184 memset (pcidev->bus, 0, sizeof(struct pci_bus));
185 pcidev->bus->number = busNr;
186 pcidev->devfn = PCI_DEVFN(devNr, funcNr);
187 pcidev->hdr_type = headerType & 0x7f;
188
189 pcidev->prepare = pcidev_prepare;
190 pcidev->activate = pcidev_activate;
191 pcidev->deactivate = pcidev_deactivate;
192 pcidev->active = 1;
193 pcidev->ro = 0;
194 pcidev->sibling = NULL;
195 pcidev->next = NULL;
196 pcidev->dma_mask = 0xFFFFFFFF;
197
198 // Subsystem ID
199 pci_read_config_word(pcidev, PCI_SUBSYSTEM_VENDOR_ID, &pcidev->subsystem_vendor);
200 pci_read_config_word(pcidev, PCI_SUBSYSTEM_ID, &pcidev->subsystem_device);
201
202 // I/O and MEM
203 resNo = 0;
204 for( addr = PCI_BASE_ADDRESS_0; addr <= PCI_BASE_ADDRESS_5; addr += 4 ) {
205 pci_read_config_dword(pcidev, addr, &ulTmp1);
206 if( ulTmp1 != 0 && ulTmp1 != 0xffffffff ) {
207 pci_write_config_dword(pcidev, addr, 0xffffffff);
208 pci_read_config_dword(pcidev, addr, &ulTmp2);
209 pci_write_config_dword(pcidev, addr, ulTmp1);
210
211 if( ulTmp1 & PCI_BASE_ADDRESS_SPACE_IO ) {
212 pcidev->resource[resNo].flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO;
213 pcidev->resource[resNo].start = ulTmp1 & PCI_BASE_ADDRESS_IO_MASK;
214 pcidev->resource[resNo].end = pcidev->resource[resNo].start +
215 ~(ulTmp2 & PCI_BASE_ADDRESS_IO_MASK) + 1;
216 }
217 else
218 {
219 pcidev->resource[resNo].flags = IORESOURCE_MEM | IORESOURCE_MEM_WRITEABLE;
220 pcidev->resource[resNo].start = ulTmp1 & PCI_BASE_ADDRESS_MEM_MASK;
221 pcidev->resource[resNo].end = pcidev->resource[resNo].start +
222 ~(ulTmp2 & PCI_BASE_ADDRESS_MEM_MASK) + 1;
223 }
224
225 resNo++;
226 }
227 }
228
229 // IRQ and PIN
230 pci_read_config_dword(pcidev, PCI_INTERRUPT_LINE, &ulTmp1);
231 rprintf(("pci_query_device: PCI config IRQ=%d", ulTmp1&0xff));
232 if( (u8)ulTmp1 && (u8)ulTmp1 != 0xff ) {
233 pcidev->irq_resource[0].flags = IORESOURCE_IRQ;
234 pcidev->irq_resource[0].start = pcidev->irq_resource[0].end = ulTmp1 & 0xffff;
235 pcidev->irq = (u8)ulTmp1; // This is the interrupt used for init time processing
236 }
237
238 return (0x8000 | (busNr << 8) | PCI_DEVFN(devNr, funcNr));
239 } /* for funcNr */
240 funcNr = 0;
241 } /* for devNr */
242 devNr = 0;
243 }
244 outl(cfgaddrreg, PCI_CONFIG_ADDRESS);
245 return 0;
246}
247
248//******************************************************************************
249//******************************************************************************
250// Called from:
251//if from==NULL search pci bus
252//if from!=NULL only search already found devices starting with from
253struct pci_dev *pci_find_device (unsigned int vendor, unsigned int device, struct pci_dev *from)
254{
255 int i;
256 struct pci_device_id id_table;
257
258 for(i=0;i<MAX_PCI_DEVICES;i++) {
259 if ( pci_devices[i].devfn && (pci_devices[i].vendor == vendor) && (pci_devices[i].device == device) ) return &pci_devices[i];
260 }
261
262 for(i=0;i<MAX_PCI_DEVICES;i++) {
263 if(pci_devices[i].devfn == 0) {
264 memset(&id_table, 0, sizeof(id_table));
265 id_table.vendor = vendor;
266 id_table.device = device;
267 if( pci_query_device(&id_table, (struct pci_dev near *)&pci_devices[i], 0) ) return &pci_devices[i];
268 else break;
269 }
270 }
271
272 return NULL;
273}
274//******************************************************************************
275//******************************************************************************
276struct resource * __request_region(struct resource *a, unsigned long start,
277 unsigned long n, const char *name)
278{
279 struct resource *resource;
280
281 if(a->flags & IORESOURCE_MEM) {
282 if(RMRequestMem(/*hResMgr,*/ start, n) == FALSE) {
283 printk("RMRequestIO failed for io %x, length %x\n", start, n);
284 return NULL;
285 }
286 }
287 else if(a->flags & IORESOURCE_IO) {
288 if(RMRequestIO(/*hResMgr,*/ start, n) == FALSE) {
289 printk("RMRequestIO failed for io %x, length %x\n", start, n);
290 return NULL;
291 }
292 }
293
294 resource = kmalloc(sizeof(struct resource), GFP_KERNEL);
295 if (resource == NULL)
296 return NULL;
297 resource->name = name;
298 resource->start = start;
299 resource->end = start + n; // - 1;
300 resource->flags = a->flags;
301 resource->parent =
302 resource->child = NULL;
303
304 // insert in list
305 resource->sibling = a->sibling;
306 a->sibling = resource;
307
308 return resource;
309}
310//******************************************************************************
311//******************************************************************************
312void __release_region(struct resource *a,
313 unsigned long start, unsigned long n)
314{
315 struct resource *resource;
316 struct resource **ppres = &a->sibling;
317 unsigned long end = start + n; // - 1;
318
319 while( *ppres )
320 {
321 resource = *ppres;
322
323 if( resource->start == start && resource->end == end )
324 {
325 // remove from list
326 *ppres = resource->sibling;
327 kfree(resource);
328 return;
329 }
330
331 ppres = &resource->sibling;
332 }
333}
334//******************************************************************************
335//******************************************************************************
336int pci_get_flags (struct pci_dev *dev, int n_base)
337{
338 if(n_base >= DEVICE_COUNT_RESOURCE || !dev->resource[n_base].flags) {
339 DebugInt3();
340 return 0;
341 }
342 return dev->resource[n_base].flags;
343}
344//******************************************************************************
345//******************************************************************************
346int pcibios_present(void)
347{
348 printk("pcibios_present -> pretend BIOS present\n");
349 return 1;
350}
351//******************************************************************************
352//******************************************************************************
353struct pci_dev *pci_find_slot (unsigned int bus, unsigned int devfn)
354{
355 printk("pci_find_slot %d %x not implemented!!\n", bus, devfn);
356 DebugInt3();
357 return NULL;
358}
359//******************************************************************************
360//******************************************************************************
361int pci_dma_supported(struct pci_dev *dev, unsigned long mask)
362{
363 printk("pci_dma_supported: return TRUE\n");
364 return 1;
365}
366//******************************************************************************
367//******************************************************************************
368int pci_find_capability(struct pci_dev *dev, int cap)
369{
370 u16 status;
371 u8 pos, id;
372 int ttl = 48;
373
374 pci_read_config_word(dev, PCI_STATUS, &status);
375 if (!(status & PCI_STATUS_CAP_LIST))
376 return 0;
377 pci_read_config_byte(dev, PCI_CAPABILITY_LIST, &pos);
378 while (ttl-- && pos >= 0x40) {
379 pos &= ~3;
380 pci_read_config_byte(dev, pos + PCI_CAP_LIST_ID, &id);
381 if (id == 0xff)
382 break;
383 if (id == cap)
384 return pos;
385 pci_read_config_byte(dev, pos + PCI_CAP_LIST_NEXT, &pos);
386 }
387 return 0;
388}
389//******************************************************************************
390/*
391 * Set power management state of a device. For transitions from state D3
392 * it isn't as straightforward as one could assume since many devices forget
393 * their configuration space during wakeup. Returns old power state.
394 */
395//******************************************************************************
396int pci_set_power_state(struct pci_dev *dev, int new_state)
397{
398 u32 base[5], romaddr;
399 u16 pci_command, pwr_command;
400 u8 pci_latency, pci_cacheline;
401 int i, old_state;
402 int pm = pci_find_capability(dev, PCI_CAP_ID_PM);
403
404 if (!pm)
405 return 0;
406 pci_read_config_word(dev, pm + PCI_PM_CTRL, &pwr_command);
407 old_state = pwr_command & PCI_PM_CTRL_STATE_MASK;
408 if (old_state == new_state)
409 return old_state;
410 if (old_state == 3) {
411 pci_read_config_word(dev, PCI_COMMAND, &pci_command);
412 pci_write_config_word(dev, PCI_COMMAND, pci_command & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
413 for (i = 0; i < 5; i++)
414 pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + i*4, &base[i]);
415 pci_read_config_dword(dev, PCI_ROM_ADDRESS, &romaddr);
416 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency);
417 pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &pci_cacheline);
418 pci_write_config_word(dev, pm + PCI_PM_CTRL, new_state);
419 for (i = 0; i < 5; i++)
420 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + i*4, base[i]);
421 pci_write_config_dword(dev, PCI_ROM_ADDRESS, romaddr);
422 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
423 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, pci_cacheline);
424 pci_write_config_byte(dev, PCI_LATENCY_TIMER, pci_latency);
425 pci_write_config_word(dev, PCI_COMMAND, pci_command);
426 } else
427 pci_write_config_word(dev, pm + PCI_PM_CTRL, (pwr_command & ~PCI_PM_CTRL_STATE_MASK) | new_state);
428 return old_state;
429}
430//******************************************************************************
431/*
432 * Initialize device before it's used by a driver. Ask low-level code
433 * to enable I/O and memory. Wake up the device if it was suspended.
434 * Beware, this function can fail.
435 */
436//******************************************************************************
437int pci_enable_device(struct pci_dev *dev)
438{
439 u16 pci_command;
440
441 dprintf(("pci_enable_device %x\n", dev));
442
443 pci_read_config_word(dev, PCI_COMMAND, &pci_command);
444 pci_write_config_word(dev, PCI_COMMAND, pci_command | (PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
445 pci_set_power_state(dev, 0);
446 return 0;
447}
448//******************************************************************************
449//******************************************************************************
450int pci_register_driver(struct pci_driver *driver)
451{
452 int iTableIx, iNumCards, iTmp;
453 ULONG ulLast;
454 struct pci_dev *pcidev;
455
456 if (!driver->probe) return 0;
457
458 iNumCards = 0;
459
460 /* find an empty slot */
461 for (iTmp=0; iTmp<MAX_PCI_DEVICES; iTmp++) {
462 if (pci_devices[iTmp].devfn == 0) break;
463 }
464 if (iTmp >= MAX_PCI_DEVICES) return 0;
465 pcidev = &pci_devices[iTmp];
466
467 for( iTableIx = 0; driver->id_table[iTableIx].vendor; iTableIx++) {
468 ulLast = 0;
469 while( (ulLast = pci_query_device(&driver->id_table[iTableIx], pcidev, ulLast)) ) {
470
471 RMInit();
472 dprintf(("pci_register_driver: found=%x:%x searching for %x:%x with %s",
473 pcidev->vendor, pcidev->device, driver->id_table[iTableIx].vendor, driver->id_table[iTableIx].device, driver->name));
474
475 if(driver->probe(pcidev, &driver->id_table[iTableIx]) == 0) {
476 pcidev->pcidriver = (void *)driver;
477 pcidev->current_state = 4;
478
479 // create adapter
480 RMDone((pcidev->device << 16) | pcidev->vendor, &pcidev->hAdapter, &pcidev->hDevice);
481 iNumCards++;
482
483 /* find another empty slot */
484 for (iTmp=0; iTmp<MAX_PCI_DEVICES; iTmp++) {
485 if (pci_devices[iTmp].devfn == 0) break;
486 }
487 if (iTmp >= MAX_PCI_DEVICES) break;
488 pcidev = &pci_devices[iTmp];
489 } else {
490 kfree(pcidev->bus);
491 pcidev->devfn = 0;
492 }
493
494 RMDone(0, 0, 0);
495 }
496 }
497
498 return iNumCards;
499}
500//******************************************************************************
501//******************************************************************************
502int pci_module_init(struct pci_driver *drv)
503{
504 int res = pci_register_driver(drv);
505 if (res == 0) return -ENODEV;
506 return res;
507}
508//******************************************************************************
509//******************************************************************************
510int pci_unregister_driver(struct pci_driver *driver)
511{
512 struct pci_dev *pcidev;
513 int i, j;
514
515 for (i=0; driver->id_table[i].vendor; i++) {
516 for(j=0; j<MAX_PCI_DEVICES; j++) {
517 pcidev = &pci_devices[j];
518 if (pcidev->devfn == 0) continue;
519 if (pcidev->vendor != driver->id_table[i].vendor) continue;
520 if ( (driver->id_table[i].device != PCI_ANY_ID) && (pcidev->device != driver->id_table[i].device) ) continue;
521 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));
522 if (driver->remove) driver->remove(pcidev);
523 kfree(pcidev->bus);
524 pcidev->devfn = 0;
525 }
526 }
527 return 0;
528}
529//******************************************************************************
530//******************************************************************************
531void pci_set_master(struct pci_dev *dev)
532{
533 u16 cmd;
534
535 pci_read_config_word(dev, PCI_COMMAND, &cmd);
536 if (! (cmd & PCI_COMMAND_MASTER)) {
537 dprintf(("pci_set_master %x", dev));
538 cmd |= PCI_COMMAND_MASTER;
539 pci_write_config_word(dev, PCI_COMMAND, cmd);
540 }
541 return;
542}
543//******************************************************************************
544// * Register a device with power management
545//******************************************************************************
546struct pm_dev *pm_register(pm_dev_t type, unsigned long id, pm_callback callback)
547{
548 dprintf(("pm_register STUB"));
549 DebugInt3();
550 return NULL;
551}
552//******************************************************************************
553// * Unregister a device with power management
554//******************************************************************************
555void pm_unregister(struct pm_dev *dev)
556{
557 dprintf(("pm_unregister STUB"));
558}
559//******************************************************************************
560//******************************************************************************
561int __compat_get_order(unsigned long size)
562{
563 int order;
564
565 size = (size-1) >> (PAGE_SHIFT-1);
566 order = -1;
567 do {
568 size >>= 1;
569 order++;
570 } while (size);
571 return order;
572}
573//******************************************************************************
574//******************************************************************************
575void *pci_alloc_consistent(struct pci_dev *hwdev,
576 long size, dma_addr_t *dma_handle)
577{
578 void *ret = NULL;
579 int gfp = GFP_ATOMIC;
580 int order;
581 dprintf(("pci_alloc_consistent %d mask %x", size, (hwdev) ? hwdev->dma_mask : 0));
582 if (hwdev == NULL || hwdev->dma_mask != 0xffffffff) {
583 //try not to exhaust low memory (< 16mb) so allocate from the high region first
584 //if that doesn't satisfy the dma mask requirement, then get it from the low
585 //regino anyway
586 if(hwdev->dma_mask > 0x00ffffff) {
587 order = __compat_get_order(size);
588 ret = (void *)__get_free_pages(gfp|GFP_DMAHIGHMEM, order);
589 *dma_handle = virt_to_bus(ret);
590 if(*dma_handle > hwdev->dma_mask) {
591 free_pages((unsigned long)ret, __compat_get_order(size));
592 //be sure and allocate below 16 mb
593 gfp |= GFP_DMA;
594 ret = NULL;
595 }
596 }
597 else { //must always allocate below 16 mb
598 gfp |= GFP_DMA;
599 }
600 }
601 if(ret == NULL) {
602 ret = (void *)__get_free_pages(gfp, __compat_get_order(size));
603 }
604
605 if (ret != NULL) {
606 memset(ret, 0, size);
607 *dma_handle = virt_to_bus(ret);
608 }
609 return ret;
610}
611//******************************************************************************
612//******************************************************************************
613void pci_free_consistent(struct pci_dev *hwdev, long size,
614 void *vaddr, dma_addr_t dma_handle)
615{
616 free_pages((unsigned long)vaddr, __compat_get_order(size));
617}
618//******************************************************************************
619//******************************************************************************
620void pci_set_driver_data (struct pci_dev *dev, void *driver_data)
621{
622 if (dev)
623 dev->driver_data = driver_data;
624}
625//******************************************************************************
626//******************************************************************************
627void *pci_get_driver_data (struct pci_dev *dev)
628{
629 if (dev)
630 return dev->driver_data;
631 return 0;
632}
633//******************************************************************************
634//******************************************************************************
635unsigned long pci_get_dma_mask (struct pci_dev *dev)
636{
637 if (dev)
638 return dev->dma_mask;
639 return 0;
640}
641//******************************************************************************
642//******************************************************************************
643int release_resource(struct resource *newres)
644{
645 return 0;
646}
647
648//******************************************************************************
649//******************************************************************************
650int pci_set_latency_time(struct pci_dev *dev, int latency)
651{
652 pci_write_config_byte(dev, PCI_LATENCY_TIMER, latency);
653 return 0;
654}
655
656//******************************************************************************
657//******************************************************************************
658/**
659 * pci_save_state - save the PCI configuration space of a device before suspending
660 * @dev: - PCI device that we're dealing with
661 * @buffer: - buffer to hold config space context
662 *
663 * @buffer must be large enough to hold the entire PCI 2.2 config space
664 * (>= 64 bytes).
665 */
666int pci_orig_save_state(struct pci_dev *dev, u32 *buffer)
667{
668 int i;
669 if (buffer) {
670 /* XXX: 100% dword access ok here? */
671 for (i = 0; i < 16; i++)
672 pci_read_config_dword(dev, i * 4,&buffer[i]);
673 }
674 return 0;
675}
676
677/**
678 * pci_restore_state - Restore the saved state of a PCI device
679 * @dev: - PCI device that we're dealing with
680 * @buffer: - saved PCI config space
681 *
682 */
683int
684pci_orig_restore_state(struct pci_dev *dev, u32 *buffer)
685{
686 int i;
687
688 if (buffer) {
689 for (i = 0; i < 16; i++)
690 pci_write_config_dword(dev,i * 4, buffer[i]);
691 }
692 /*
693 * otherwise, write the context information we know from bootup.
694 * This works around a problem where warm-booting from Windows
695 * combined with a D3(hot)->D0 transition causes PCI config
696 * header data to be forgotten.
697 */
698 else {
699 for (i = 0; i < 6; i ++)
700 pci_write_config_dword(dev,
701 PCI_BASE_ADDRESS_0 + (i * 4),
702 dev->resource[i].start);
703 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
704 }
705 return 0;
706}
707
708struct saved_config_tbl {
709 struct pci_dev *pci;
710 u32 config[16];
711};
712static struct saved_config_tbl saved_tbl[16];
713
714int pci_save_state(struct pci_dev *pci)
715{
716 int i;
717 /* FIXME: mutex needed for race? */
718 for (i = 0; i < ARRAY_SIZE(saved_tbl); i++) {
719 if (! saved_tbl[i].pci) {
720 saved_tbl[i].pci = pci;
721 pci_orig_save_state(pci, saved_tbl[i].config);
722 return 1;
723 }
724 }
725 printk(KERN_DEBUG "snd: no pci config space found!\n");
726 return 0;
727}
728
729int pci_restore_state(struct pci_dev *pci)
730{
731 int i;
732 /* FIXME: mutex needed for race? */
733 for (i = 0; i < ARRAY_SIZE(saved_tbl); i++) {
734 if (saved_tbl[i].pci == pci) {
735 saved_tbl[i].pci = NULL;
736 pci_orig_restore_state(pci, saved_tbl[i].config);
737 return 0;
738 }
739 }
740 printk(KERN_DEBUG "snd: no saved pci config!\n");
741 return 1;
742}
743
744void pci_disable_device(struct pci_dev *dev)
745{
746 u16 pci_command;
747
748 pci_read_config_word(dev, PCI_COMMAND, &pci_command);
749 if (pci_command & PCI_COMMAND_MASTER) {
750 pci_command &= ~PCI_COMMAND_MASTER;
751 pci_write_config_word(dev, PCI_COMMAND, pci_command);
752 }
753}
754
755int pci_request_region(struct pci_dev *pdev, int bar, char *res_name)
756{
757 int flags;
758
759 if (pci_resource_len(pdev, bar) == 0)
760 return 0;
761 flags = pci_get_flags(pdev, bar);
762 if (flags & IORESOURCE_IO) {
763 if (check_region(pci_resource_start(pdev, bar), pci_resource_len(pdev, bar)))
764 goto err_out;
765 request_region(pci_resource_start(pdev, bar),
766 pci_resource_len(pdev, bar), res_name);
767 }
768 else if (flags & IORESOURCE_MEM) {
769 if (check_mem_region(pci_resource_start(pdev, bar), pci_resource_len(pdev, bar)))
770 goto err_out;
771 request_mem_region(pci_resource_start(pdev, bar),
772 pci_resource_len(pdev, bar), res_name);
773 }
774
775 return 0;
776
777err_out:
778 printk(KERN_WARNING "PCI: Unable to reserve %s region #%d:%lx@%lx for device %s\n",
779 flags & IORESOURCE_IO ? "I/O" : "mem",
780 bar + 1, /* PCI BAR # */
781 pci_resource_len(pdev, bar), pci_resource_start(pdev, bar),
782 res_name);
783 return -EBUSY;
784}
785
786void pci_release_region(struct pci_dev *pdev, int bar)
787{
788 int flags;
789
790 if (pci_resource_len(pdev, bar) == 0)
791 return;
792 flags = pci_get_flags(pdev, bar);
793 if (flags & IORESOURCE_IO) {
794 release_region(pci_resource_start(pdev, bar),
795 pci_resource_len(pdev, bar));
796 }
797 else if (flags & IORESOURCE_MEM) {
798 release_mem_region(pci_resource_start(pdev, bar),
799 pci_resource_len(pdev, bar));
800 }
801}
802
803int pci_request_regions(struct pci_dev *pdev, char *res_name)
804{
805 int i;
806
807 for (i = 0; i < 6; i++)
808 if (pci_request_region(pdev, i, res_name))
809 goto err;
810 return 0;
811 err:
812 while (--i >= 0)
813 pci_release_region(pdev, i);
814 return -EBUSY;
815}
816
817void pci_release_regions(struct pci_dev *pdev)
818{
819 int i;
820 for (i = 0; i < 6; i++)
821 pci_release_region(pdev, i);
822}
823
824const struct pci_device_id * pci_match_device(const struct pci_device_id *ids, struct pci_dev *dev)
825{
826 u16 subsystem_vendor, subsystem_device;
827
828 pci_read_config_word(dev, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);
829 pci_read_config_word(dev, PCI_SUBSYSTEM_ID, &subsystem_device);
830
831 while (ids->vendor || ids->subvendor || ids->class_mask) {
832 if ((ids->vendor == PCI_ANY_ID || ids->vendor == dev->vendor) &&
833 (ids->device == PCI_ANY_ID || ids->device == dev->device) &&
834 (ids->subvendor == PCI_ANY_ID || ids->subvendor == subsystem_vendor) &&
835 (ids->subdevice == PCI_ANY_ID || ids->subdevice == subsystem_device) &&
836 !((ids->class ^ dev->_class) & ids->class_mask))
837 return ids;
838 ids++;
839 }
840 return NULL;
841}
842
843int snd_pci_dev_present(const struct pci_device_id *ids)
844{
845 while (ids->vendor || ids->subvendor) {
846 if (pci_find_device(ids->vendor, ids->subvendor, NULL))
847 return 1;
848 ids++;
849 }
850 return 0;
851}
852
853struct pci_driver_mapping {
854 struct pci_dev *dev;
855 struct pci_driver *drv;
856 unsigned long dma_mask;
857 void *driver_data;
858 u32 saved_config[16];
859};
860
861#define PCI_MAX_MAPPINGS 64
862static struct pci_driver_mapping drvmap [PCI_MAX_MAPPINGS] = { { NULL, } , };
863
864
865static struct pci_driver_mapping *get_pci_driver_mapping(struct pci_dev *dev)
866{
867 int i;
868
869 for (i = 0; i < PCI_MAX_MAPPINGS; i++)
870 if (drvmap[i].dev == dev)
871 return &drvmap[i];
872 return NULL;
873}
874
875struct pci_driver *snd_pci_compat_get_pci_driver(struct pci_dev *dev)
876{
877 struct pci_driver_mapping *map = get_pci_driver_mapping(dev);
878 if (map)
879 return map->drv;
880 return NULL;
881}
882#if 0
883void * pci_get_drvdata (struct pci_dev *dev)
884{
885 struct pci_driver_mapping *map = get_pci_driver_mapping(dev);
886 if (map)
887 return map->driver_data;
888 return NULL;
889}
890
891
892void pci_set_drvdata (struct pci_dev *dev, void *driver_data)
893{
894 struct pci_driver_mapping *map = get_pci_driver_mapping(dev);
895 if (map)
896 map->driver_data = driver_data;
897}
898#endif
899
900
901//******************************************************************************
902//******************************************************************************
903OSSRET OSS32_APMResume()
904{
905 int i;
906 struct pci_driver *driver;
907
908 dprintf(("OSS32_APMResume"));
909
910 for(i=0;i<MAX_PCI_DEVICES;i++)
911 {
912 if(pci_devices[i].devfn)
913 {
914 RMSetHandles(pci_devices[i].hAdapter, pci_devices[i].hDevice); /* DAZ - dirty hack */
915 driver = pci_devices[i].pcidriver;
916 if(driver && driver->resume) {
917 driver->resume(&pci_devices[i]);
918 }
919 }
920 }
921
922 return OSSERR_SUCCESS;
923}
924//******************************************************************************
925//******************************************************************************
926OSSRET OSS32_APMSuspend()
927{
928 int i;
929 struct pci_driver *driver;
930
931 dprintf(("OSS32_APMSuspend 1"));
932
933 for(i=0;i<MAX_PCI_DEVICES;i++)
934 {
935 if(pci_devices[i].devfn)
936 {
937 RMSetHandles(pci_devices[i].hAdapter, pci_devices[i].hDevice); /* DAZ - dirty hack */
938 driver = pci_devices[i].pcidriver;
939 if(driver && driver->suspend) {
940 driver->suspend(&pci_devices[i], SNDRV_CTL_POWER_D3cold);
941 }
942 }
943 }
944
945 dprintf(("OSS32_APMSuspend 2"));
946 return OSSERR_SUCCESS;
947}
948
Note: See TracBrowser for help on using the repository browser.