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