source: GPL/branches/DAZ/lib32/pci.c@ 580

Last change on this file since 580 was 580, checked in by David Azarewicz, 11 years ago

Cleanup build environment

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