Changeset 63


Ignore:
Timestamp:
Jan 3, 2006, 11:33:10 PM (20 years ago)
Author:
vladest
Message:

(Patches by Ruediger Ihle)
Support for IRQs > 15
Fixed resource manager registration
Fixed crash on APM suspend/resume and system shutdown

Location:
GPL/trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk/alsa-kernel/include/sound/driver.h

    r34 r63  
    536536int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
    537537
     538void *kzalloc(size_t size, unsigned int flags);
     539
    538540/* init.c */
    539541
  • GPL/trunk/alsa-kernel/pci/intel8x0.c

    r35 r63  
    31643164    // { 0x8086, 0x7195, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },     /* 440MX */
    31653165    // { 0x1039, 0x7012, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },     /* SI7012 */
    3166     { 0x10de, 0x01b2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },        /* NFORCE */
     3166    //Rudi: this is not a joystick !!!!
     3167    //  { 0x10de, 0x01b2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },    /* NFORCE */
    31673168    //  { 0x10de, 0x006b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },    /* NFORCE2 */
    31683169    { 0x10de, 0x00db, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },        /* NFORCE3 */
  • GPL/trunk/drv32/init.c

    r34 r63  
    4444#include "parse.h"
    4545
    46 char copyright[]="@#Netlabs:1.13#@.Universal audio driver for OS/2 (c) Netlabs 2005\0x0\0x0\0xb";
    47 
    4846const char ERR_ERROR[]   = "ERROR: ";
    4947const char ERR_LOCK[]    = "Unable to lock 32 bit data & code segments, exiting...\r\r\n";
     
    5149const char ERR_NAMES[]    = "Query names failed\r\r\n";
    5250const char szALSA[]      = "\r\n\r\nOS/2 Universal Audio Core Driver v"ALSA_VERSION"\r\n";
     51
    5352const char szCopyRight1[]= "Copyright 2000-2002 InnoTek Systemberatung GmbH\r\n";
    5453const char szCopyRight2[]= "Copyright 2000-2002 The ALSA Project\r\n\r\n";
     54const char szCopyRight3[]= "Copyright 2005 Netlabs http://www.netlabs.org\r\n";
    5555//const char szCopyRight3[]= "Maintained by http://os2.kiev.ua/en/uniaud.php\r\n\r\n";
     56
    5657const char szCodeStartEnd[] = "Code 0x%0x - 0x%0x\r\n\r\n";
    5758const char szMixerFound[]= "Detected Mixer: ";
     
    218219        WriteString(szALSA, sizeof(szALSA)-1);
    219220        WriteString(szCopyRight1, sizeof(szCopyRight1)-1);
     221        WriteString(szCopyRight3, sizeof(szCopyRight3)-1);
    220222        WriteString(szCopyRight2, sizeof(szCopyRight2)-1);
    221223    }
    222224
    223     //    if(fDebug) {
    224     if(1) {
     225    if(fDebug) {
    225226        sprintf(debugmsg, szCodeStartEnd, OffsetBeginCS32, OffsetFinalCS32);
    226227        WriteString(debugmsg, strlen(debugmsg));
  • GPL/trunk/drv32/irq.cpp

    r34 r63  
    3535
    3636// List of handlers here.
    37 static FARPTR16 *pISR[NUM_IRQLEVELS] = {
    38    NULL,
    39    NULL,
    40    NULL,
     37static FARPTR16 *pISR[MAX_IRQ_SLOTS] = {
     38   &ISR00,
     39   &ISR01,
     40   &ISR02,
    4141   &ISR03,
    4242   &ISR04,
    4343   &ISR05,
    44    NULL,
    45    &ISR07,
    46    NULL,
    47    &ISR09,
    48    &ISR10,
    49    &ISR11,
    50    &ISR12,
    51    &ISR13,
    52    &ISR14,
    53    &ISR15,
     44   &ISR06,
     45   &ISR07
    5446};
    55 
    56 static PFNIRQ pfnAlsaIRQHandler = NULL;
    5747
    5848//******************************************************************************
    5949//******************************************************************************
    60 BOOL RMSetIrq(ULONG ulIrq, BOOL fShared, PFNIRQ pfnIrqHandler)
     50BOOL ALSA_SetIrq(ULONG ulIrq, ULONG ulSlotNo, BOOL fShared)
    6151{
    6252    USHORT rc = 1;
    6353
    64     if(pISR[ulIrq] == NULL) {
     54    if( ulSlotNo >= MAX_IRQ_SLOTS ) {
    6555        DebugInt3();
    6656        return FALSE;
    6757    }
    68     if(fShared)
     58
     59    if(fShared)
    6960    {
    70         rc = DevIRQSet((WORD16) *pISR[ ulIrq ],
     61        rc = DevIRQSet((WORD16) *pISR[ulSlotNo],
    7162                       (WORD16)ulIrq,
    7263                       1 );   // first try shared shared
    7364    }
     65
    7466    if (rc != 0) {                    // If error ...
    75         rc = DevIRQSet((WORD16) *pISR[ ulIrq ],
     67        rc = DevIRQSet((WORD16) *pISR[ulSlotNo],
    7668                       (WORD16)ulIrq,
    7769                       0);   // failed, so try exclusive instead
    7870    }
     71
    7972    if (rc != 0) {                    // If error ...
    80         dprintf(("ERROR: RMSetIrq %d %d %x FAILED!!", ulIrq, fShared, pfnIrqHandler));
     73        dprintf(("ERROR: RMSetIrq %d %d %x FAILED!!", ulIrq, fShared, ulSlotNo));
    8174        DebugInt3();
    8275        return FALSE;
    8376    }
    84     //Always called with the same handler
    85     if(pfnAlsaIRQHandler && (pfnAlsaIRQHandler != pfnIrqHandler)) {
    86         DebugInt3();
    87         return FALSE;
    88     }
    89     pfnAlsaIRQHandler = pfnIrqHandler;
     77
    9078    return TRUE;
    9179}
    9280//******************************************************************************
    9381//******************************************************************************
    94 BOOL RMFreeIrq(ULONG ulIrq)
     82BOOL ALSA_FreeIrq(ULONG ulIrq)
    9583{
    9684    return (DevIRQClear((WORD16)ulIrq) == 0);
     
    9886//******************************************************************************
    9987//******************************************************************************
    100 ULONG ALSA_Interrupt(ULONG irqnr);
     88ULONG ALSA_Interrupt(ULONG ulSlotNo);
    10189#pragma aux ALSA_Interrupt "ALSA_Interrupt" parm [ebx]
    102 ULONG ALSA_Interrupt(ULONG irqnr)
     90ULONG ALSA_Interrupt(ULONG ulSlotNo)
    10391{
    104    if(pfnAlsaIRQHandler == NULL) {
    105        DebugInt3();
    106        return FALSE;
    107    }
    108 #ifdef DEBUG
    109    dprintf2(("irq %d",irqnr));
    110 #endif
    111    if(pfnAlsaIRQHandler(irqnr)) {
    112        cli();
    113        // We've cleared all service requests.  Send EOI and clear
    114        // the carry flag (tells OS/2 kernel that Int was handled).
    115        DevEOI( (WORD16)irqnr );
    116        return TRUE;
     92    ULONG       ulIrqNo;
     93
     94    if( process_interrupt(ulSlotNo, &ulIrqNo) ) {
     95        cli();
     96        // We've cleared all service requests.  Send EOI and clear
     97        // the carry flag (tells OS/2 kernel that Int was handled).
     98        DevEOI( (WORD16)ulIrqNo );
     99        return TRUE;
    117100   }
    118101   // Indicate Interrupt not serviced by setting carry flag before
  • GPL/trunk/drv32/irq.h

    r34 r63  
    2525#define __IRQ_H__
    2626
    27 //#define NUM_IRQLEVELS         16
    28 #define NUM_IRQLEVELS           256 //ACPI
    29 
     27extern "C" FARPTR16 ISR00;
     28extern "C" FARPTR16 ISR01;
     29extern "C" FARPTR16 ISR02;
    3030extern "C" FARPTR16 ISR03;
    3131extern "C" FARPTR16 ISR04;
    3232extern "C" FARPTR16 ISR05;
     33extern "C" FARPTR16 ISR06;
    3334extern "C" FARPTR16 ISR07;
    34 extern "C" FARPTR16 ISR09;
    35 extern "C" FARPTR16 ISR10;
    36 extern "C" FARPTR16 ISR11;
    37 extern "C" FARPTR16 ISR12;
    38 extern "C" FARPTR16 ISR13;
    39 extern "C" FARPTR16 ISR14;
    40 extern "C" FARPTR16 ISR15;
    4135
    4236#endif //__IRQ_H__
  • GPL/trunk/drv32/makefile.os2

    r62 r63  
    3636TARGET   = uniaud32
    3737LNKFILE   = $(OBJDIR)\$(TARGET).lrf
     38DEFFILE   = $(OBJDIR)\$(TARGET).def
    3839MAKEFILE  = makefile.os2
    3940
     
    6061FILE4    = devhlp.obj
    6162FILE5    = idc.obj dispatch.obj
    62 FILE6    = rm.obj irq.obj util.obj
     63FILE6    = rmhelp.obj irq.obj util.obj
    6364FILE7    = impdos.lib
    6465!if "$(KEE)" == "1"
     
    8081
    8182!ifdef USE_WLINK
    82 $(OBJDIR)\$(TARGET).lrf: $(MAKEFILE)
     83$(LNKFILE): $(MAKEFILE)
    8384    @%write $^@ option quiet
    8485    @%write $^@ option verbose
     
    8788    @%write $^@ option alignment=16
    8889    @%write $^@ option map=$(WMAPNAME)
    89     @%write $^@ option description '@$#$(_VENDOR):$(_VERSION)$#@'
     90!if "$(KEE)" == "1"
     91    @%write $^@ option description '@$#$(BLDLVL_VENDOR):$(BLDLVL_REVISION)$#@$#$#1$#$# $(BLDLVL_DATETIME)      $(BLDLVL_MACHINE)::::$(BLDLVL_FILEVER)::@@$(BLDLVL_PRODUCT) (KEE)'
     92!else
     93    @%write $^@ option description '@$#$(BLDLVL_VENDOR):$(BLDLVL_REVISION)$#@$#$#1$#$# $(BLDLVL_DATETIME)      $(BLDLVL_MACHINE)::::$(BLDLVL_FILEVER)::@@$(BLDLVL_PRODUCT) (W4)'
     94!endif
    9095    @%write $^@ name $(OBJDIR)\$(TARGET).sys
    9196    @for %f in ($(FILES)) do @%append $^@ file $(OBJDIR)\%f
     
    9398    @%write $^@ library $(%WATCOM)\lib386\os2\clib3r.lib
    9499!else
    95 $(OBJDIR)\$(TARGET).lrf: $(MAKEFILE)
     100$(LNKFILE): $(MAKEFILE)
    96101    @%write $^@ /OUT:$(OBJDIR)\$(TARGET).sys
    97102    @%write $^@ /MAP:$(OBJDIR)\$(TARGET).map
     
    99104    @for %f in ($(LIBS)) do @%append $^@ %f
    100105    @%write $^@ $(%WATCOM)\lib386\os2\clib3r.lib
     106    @%write $^@ $(DEFFILE)
    101107!endif
    102108
    103 $(OBJDIR)\$(TARGET).def: $(MAKEFILE)
    104     @%write $^@ LIBRARY UNIAUD32
    105     @%write $^@ DESCRIPTION "@$#Netlabs:1.13$#@Universal audio driver for OS/2 (c) Netlabs 2005"
    106     @%write $^@ PROTMODE
     109$(OBJDIR)\$(TARGET).sys: $(LNKFILE) $(FILES) $(LIBS)
     110!if "$(KEE)" == "1"
     111     @%write $(DEFFILE) description '@$#$(BLDLVL_VENDOR):$(BLDLVL_REVISION)$#@$#$#1$#$# $(BLDLVL_DATETIME)      $(BLDLVL_MACHINE)::::$(BLDLVL_FILEVER)::@@$(BLDLVL_PRODUCT) (KEE)'
     112!else
     113     @%write $(DEFFILE) description '@$#$(BLDLVL_VENDOR):$(BLDLVL_REVISION)$#@$#$#1$#$# $(BLDLVL_DATETIME)      $(BLDLVL_MACHINE)::::$(BLDLVL_FILEVER)::@@$(BLDLVL_PRODUCT) (W4)'
     114!endif
    107115
    108 $(OBJDIR)\$(TARGET).sys: $(OBJDIR)\$(TARGET).lrf $(LNKFILE) $(FILES) $(LIBS) $(OBJDIR)\$(TARGET).def
    109      $(LINK) @$(OBJDIR)\$(TARGET).lrf $(OBJDIR)\$(TARGET).DEF
     116     $(LINK) @$(LNKFILE)
     117
    110118     copy $(OBJDIR)\$(TARGET).sys $(ALSA_BIN)
    111119!if "$(KEE)" == "1"
     
    130138     -@rm *.err 2>nul
    131139     @cd $(OBJDIR)
    132      -rm *.obj *.lnk *.sys *.sym *.lst *.map *.wmap *.lib 2>nul
     140     -rm *.obj *.lnk *.lrf *.def *.sys *.sym *.lst *.map *.wmap *.lib 2>nul
    133141     @cd ..\..
  • GPL/trunk/drv32/startup.asm

    r32 r63  
    904904
    905905                ALIGN 2
     906ISR00_16 proc far
     907                push    ebx
     908                mov     ebx, 0
     909                call    far ptr FLAT:Interrupt32
     910                pop     ebx
     911                retf
     912ISR00_16 endp
     913
     914                ALIGN 2
     915ISR01_16 proc far
     916                push    ebx
     917                mov     ebx, 1
     918                call    far ptr FLAT:Interrupt32
     919                pop     ebx
     920                retf
     921ISR01_16 endp
     922
     923                ALIGN 2
     924ISR02_16 proc far
     925                push    ebx
     926                mov     ebx, 2
     927                call    far ptr FLAT:Interrupt32
     928                pop     ebx
     929                retf
     930ISR02_16 endp
     931
     932                ALIGN 2
    906933ISR03_16 proc far
    907934                push    ebx
     
    931958
    932959                ALIGN 2
     960ISR06_16 proc far
     961                push    ebx
     962                mov     ebx, 6
     963                call    far ptr FLAT:Interrupt32
     964                pop     ebx
     965                retf
     966ISR06_16 endp
     967
     968                ALIGN 2
    933969ISR07_16 proc far
    934970                push    ebx
     
    938974                retf
    939975ISR07_16 endp
    940 
    941                 ALIGN 2
    942 ISR09_16 proc far
    943                 push    ebx
    944                 mov     ebx, 9
    945                 call    far ptr FLAT:Interrupt32
    946                 pop     ebx
    947                 retf
    948 ISR09_16 endp
    949 
    950                 ALIGN 2
    951 ISR10_16 proc far
    952                 push    ebx
    953                 mov     ebx, 10
    954                 call    far ptr FLAT:Interrupt32
    955                 pop     ebx
    956                 retf
    957 ISR10_16 endp
    958 
    959                 ALIGN 2
    960 ISR11_16 proc far
    961                 push    ebx
    962                 mov     ebx, 11
    963                 call    far ptr FLAT:Interrupt32
    964                 pop     ebx
    965                 retf
    966 ISR11_16 endp
    967 
    968                 ALIGN 2
    969 ISR12_16 proc far
    970                 push    ebx
    971                 mov     ebx, 12
    972                 call    far ptr FLAT:Interrupt32
    973                 pop     ebx
    974                 retf
    975 ISR12_16 endp
    976 
    977                 ALIGN 2
    978 ISR13_16 proc far
    979                 push    ebx
    980                 mov     ebx, 13
    981                 call    far ptr FLAT:Interrupt32
    982                 pop     ebx
    983                 retf
    984 ISR13_16 endp
    985 
    986                 ALIGN 2
    987 ISR14_16 proc far
    988                 push    ebx
    989                 mov     ebx, 14
    990                 call    far ptr FLAT:Interrupt32
    991                 pop     ebx
    992                 retf
    993 ISR14_16 endp
    994 
    995                 ALIGN 2
    996 ISR15_16 proc far
    997                 push    ebx
    998                 mov     ebx, 15
    999                 call    far ptr FLAT:Interrupt32
    1000                 pop     ebx
    1001                 retf
    1002 ISR15_16 endp
    1003976
    1004977;end of 16 bits code segment
     
    15411514    public  RMHandleToResourceHandleList1632
    15421515    public  _TimerHandler16
     1516    public  _ISR00
     1517    public  _ISR01
     1518    public  _ISR02
    15431519    public  _ISR03
    15441520    public  _ISR04
    15451521    public  _ISR05
     1522    public  _ISR06
    15461523    public  _ISR07
    1547     public  _ISR09
    1548     public  _ISR10
    1549     public  _ISR11
    1550     public  _ISR12
    1551     public  _ISR13
    1552     public  _ISR14
    1553     public  _ISR15
    15541524
    15551525IFDEF FLATSTACK
     
    16281598
    16291599;16:16 addresses of interrupt dispatchers
     1600    _ISR00               dw OFFSET CODE16:ISR00_16
     1601                         dw SEG CODE16:ISR00_16
     1602    _ISR01               dw OFFSET CODE16:ISR01_16
     1603                         dw SEG CODE16:ISR01_16
     1604    _ISR02               dw OFFSET CODE16:ISR02_16
     1605                         dw SEG CODE16:ISR02_16
    16301606    _ISR03               dw OFFSET CODE16:ISR03_16
    16311607                         dw SEG CODE16:ISR03_16
     
    16341610    _ISR05               dw OFFSET CODE16:ISR05_16
    16351611                         dw SEG CODE16:ISR05_16
     1612    _ISR06               dw OFFSET CODE16:ISR06_16
     1613                         dw SEG CODE16:ISR06_16
    16361614    _ISR07               dw OFFSET CODE16:ISR07_16
    16371615                         dw SEG CODE16:ISR07_16
    1638     _ISR09               dw OFFSET CODE16:ISR09_16
    1639                          dw SEG CODE16:ISR09_16
    1640     _ISR10               dw OFFSET CODE16:ISR10_16
    1641                          dw SEG CODE16:ISR10_16
    1642     _ISR11               dw OFFSET CODE16:ISR11_16
    1643                          dw SEG CODE16:ISR11_16
    1644     _ISR12               dw OFFSET CODE16:ISR12_16
    1645                          dw SEG CODE16:ISR12_16
    1646     _ISR13               dw OFFSET CODE16:ISR13_16
    1647                          dw SEG CODE16:ISR13_16
    1648     _ISR14               dw OFFSET CODE16:ISR14_16
    1649                          dw SEG CODE16:ISR14_16
    1650     _ISR15               dw OFFSET CODE16:ISR15_16
    1651                          dw SEG CODE16:ISR15_16
    16521616DATA32 ends
    16531617
  • GPL/trunk/drv32/util.cpp

    r32 r63  
    2222 *
    2323 */
     24#define INCL_NOPMAPI
     25#define INCL_DOSINFOSEG
     26#include <os2.h>
    2427
    25 
    26 #include "rm.hpp"                      // Will include os2.h, etc.
    2728#include <devhelp.h>
    2829#include <devinfo.h>
  • GPL/trunk/howtobuild.txt

    r37 r63  
     1NOTE! Use OpenWatcom 1.4rc1 or later
     2
    131. Run Configure.cmd
     4
    252. Enter path to watcom and ddk base
     6
    373. within created makefile.inc check for:
    4 ALSA_SRC
    5 ALSA_LIB_
    6 ALSA_BIN_
    7 defines and create corresponding directories
    8 4. add following state if not added by configure
    9 ################################################################################
    10 # Include the right watcom makefile
    11 ################################################################################
    12 !ifdef 32BIT
    13 !include E:\DEV\USS\test\GPL\include\watcom32.mk
    14 !include E:\DEV\USS\test\GPL\include\watcom32.mak
    15 !else
    16 !include E:\DEV\USS\ua2\OCO\include\watcom16.mk
    17 !include E:\DEV\USS\ua2\OCO\include\watcom16.mak
    18 !endif
     8   ALSA_SRC
     9   ALSA_LIB_
     10   ALSA_BIN_
     11   define and create corresponding directories
    1912
    20 DDK_BASE       = e:\ddk\base
    21 WATCOM         = e:\owatcom
     134. add following state if not added by configure:
     14   ################################################################################
     15   # Include the right watcom makefile
     16   ################################################################################
     17   !ifdef 32BIT
     18   !include E:\DEV\USS\test\GPL\include\watcom32.mk
     19   !include E:\DEV\USS\test\GPL\include\watcom32.mak
     20   !else
     21   !include E:\DEV\USS\ua2\OCO\include\watcom16.mk
     22   !include E:\DEV\USS\ua2\OCO\include\watcom16.mak
     23   !endif
     24
     25   DDK_BASE       = e:\ddk\base
     26   WATCOM         = e:\owatcom
     27
     285. run !m_kee.cmd or !m_v4.cmd scrips
     29
  • GPL/trunk/include/asm/string.h

    r32 r63  
    1010int   strncmp (const char *string1, const char *string2, size_t count);
    1111
     12size_t strlcpy(char *dst, const char *src, size_t size);
     13
    1214#endif
    1315
  • GPL/trunk/include/irqos2.h

    r34 r63  
    2525#define __IRQOS2_H__
    2626
    27 //#define MAX_SHAREDIRQS          16
    28 //#define MAX_IRQS              16
    29 #define MAX_SHAREDIRQS          256 // ACPI
    30 #define MAX_IRQS                256 // ACPI
     27#define MAX_SHAREDIRQS          8
     28#define MAX_IRQ_SLOTS           8
    3129
    32 //typedef void (NEAR * IRQHANDLER)(int, void *, void *);
    33 typedef int (NEAR * IRQHANDLER)(int, void *, void *);
     30
     31typedef int (NEAR * IRQHANDLER)(int, void *, struct pt_regs *);
    3432
    3533typedef struct {
     
    4038} IRQHANDLER_INFO;
    4139
    42 typedef BOOL (*PFNIRQ)(int irq);
     40typedef struct
     41{
     42  unsigned              irqNo;
     43  unsigned              fEOI;
     44  unsigned              flHandlers;
     45  IRQHANDLER_INFO       irqHandlers[MAX_SHAREDIRQS];
     46} IRQ_SLOT;
     47
    4348
    4449#ifdef __cplusplus
     
    4651#endif
    4752
    48 BOOL RMSetIrq(ULONG ulIrq, BOOL fShared, PFNIRQ pfnIrqHandler);
    49 BOOL RMFreeIrq(ULONG ulIrq);
     53BOOL ALSA_SetIrq(ULONG ulIrq, ULONG ulSlotNo, BOOL fShared);
     54BOOL ALSA_FreeIrq(ULONG ulIrq);
    5055
    51 BOOL oss_process_interrupt(int irq);
     56BOOL process_interrupt(ULONG ulSlotNo, ULONG *pulIrq);
    5257
    5358ULONG os2gettimemsec();
    5459ULONG os2gettimesec();
    55 
    5660
    5761#ifdef __cplusplus
  • GPL/trunk/include/osspci.h

    r32 r63  
    3030#endif
    3131
    32 #define MAX_RES_IRQ     2
    33 #define MAX_RES_DMA     2
    34 #define MAX_RES_IO      8
    35 #define MAX_RES_MEM     8
    36 
    37 #define RM_PNP_DEVICE   0
    38 #define RM_PCI_DEVICE   1
    39 
    40 #define MAX_PCI_DEVICES         16
    41 #define MAX_PCI_BUSSES      16
    42 
    43     //#pragma pack(4) !!! by vladest
    44 #pragma pack(1)
    45 
    46 typedef struct
    47 {
    48     ULONG  busnr;
    49     ULONG  devnr;
    50     ULONG  funcnr;
    51     ULONG  devfn;
    52         USHORT irq[MAX_RES_IRQ];
    53         USHORT dma[MAX_RES_DMA];
    54         USHORT io[MAX_RES_IO];
    55         USHORT iolength[MAX_RES_IO];
    56         ULONG  mem[MAX_RES_MEM];
    57         ULONG  memlength[MAX_RES_MEM];
    58 } IDC_RESOURCE;
    59 
    60 #pragma pack()
    61 
    62 typedef ULONG HRESMGR;
    63 
    64 HRESMGR RMFindPCIDevice(ULONG vendorid, ULONG deviceid, IDC_RESOURCE *lpResource, int idx);
    65 BOOL    RMRequestIO(HRESMGR hResMgr, ULONG ulIOBase, ULONG ulIOLength);
    66 BOOL    RMRequestMem(HRESMGR hResMgr, ULONG ulMemBase, ULONG ulMemLength);
    67 BOOL    RMRequestIRQ(HRESMGR hResMgr, ULONG ulIrq, BOOL fShared);
    68 BOOL    RMRequestDMA(HRESMGR hResMgr, ULONG ulDMA);
    69 //register resources & destroy resource manager object
    70 void    RMFinialize(HRESMGR hResMgr);
    71 //destroy resource manager object
    72 void    RMDestroy(HRESMGR hResMgr);
    73 
    74 extern HRESMGR hResMgr;
    75 
     32VOID    RMInit(VOID);
     33BOOL    RMRequestIO(ULONG ulIOBase, ULONG ulIOLength);
     34BOOL    RMRequestMem(ULONG ulMemBase, ULONG ulMemLength);
     35BOOL    RMRequestIRQ(ULONG ulIrq, BOOL fShared);
     36VOID    RMDone(ULONG DevID);
    7637
    7738#ifdef __cplusplus
  • GPL/trunk/include/version.h

    r32 r63  
    2626#define __UNIAUDVERSION_H__
    2727
     28
     29#define BUILDER_NAME            "Netlabs"
     30#define PRODUCT_NAME            "OS/2 Universal Audio Driver"
     31#define VENDOR_NAME             "Netlabs"
     32#define PRODUCT_VERSION         "1.1.4"         // version
     33#define PRODUCT_TIMESTAMP       20051231L       // YYYYMMDD
     34
     35
    2836#define ALSA_VERSION            "1.1.3"
    2937#define RM_DRIVER_NAME          "UNIAUD32.SYS"
     
    3139#define RM_ADAPTER_NAME         "OS/2 Universal Audio"
    3240#define RM_DRIVER_VENDORNAME    "InnoTek Systemberatung GmbH"
    33 #define RM_DRIVER_BUILDYEAR     2005
    34 #define RM_DRIVER_BUILDMONTH    01
    35 #define RM_DRIVER_BUILDDAY      06
    36 #define UNIAUD_VERSION          113
     41#define RM_DRIVER_BUILDYEAR     (PRODUCT_TIMESTAMP / 10000)
     42#define RM_DRIVER_BUILDMONTH    ((PRODUCT_TIMESTAMP / 100) % 100)
     43#define RM_DRIVER_BUILDDAY      (PRODUCT_TIMESTAMP % 100)
     44#define UNIAUD_VERSION          114
     45
    3746
    3847#endif //__UNIAUDVERSION_H__
  • GPL/trunk/include/version.mak

    r32 r63  
    1 # $Id: version.mak,v 1.1.1.1 2003/07/02 13:56:58 eleph Exp $
    2 
    31#
    4 
    52#       VERSION.MAK
    63#
    74#       Current build level for File Versioning
    85#
    9 #       This file should reside in the same place as COMMON.MAK
     6#       Generated file, do NOT edit !
    107#
    118
    12 _VENDOR = "OS/2 Universal Audio Driver"
    13 _VERSION = 1.13.001
    14 
    15 FILEVER = @^#$(_VENDOR):$(_VERSION)^#@
    16 
     9BLDLVL_VENDOR = NETLABS
     10BLDLVL_PRODUCT = OS/2 Universal Audio Driver
     11BLDLVL_REVISION = 1.1
     12BLDLVL_FILEVER = 4
     13BLDLVL_DATETIME = 04.01.2006 00:19:06
     14BLDLVL_MACHINE = VLAD
  • GPL/trunk/lib32/irq.c

    r34 r63  
    3737
    3838
    39 static IRQHANDLER_INFO irqHandlers[MAX_IRQS][MAX_SHAREDIRQS] = {0};
    40 static ULONG           nrIrqHandlers[MAX_IRQS] = {0};
    41 static ULONG           eoiIrq[MAX_IRQS] = {0};
    42 
    4339BOOL fInInterrupt = FALSE;
    4440extern BOOL fSuspended; //pci.c
    4541
    46 //******************************************************************************
    47 //******************************************************************************
     42
     43//******************************************************************************
     44//******************************************************************************
     45
     46static IRQ_SLOT         arSlots[MAX_IRQ_SLOTS] = { 0 };
     47
     48
     49//******************************************************************************
     50//******************************************************************************
     51static IRQ_SLOT *FindSlot(unsigned irq)
     52{
     53  IRQ_SLOT      *pSlot;
     54
     55  for( pSlot = arSlots; pSlot != &arSlots[MAX_IRQ_SLOTS]; pSlot++ )
     56  {
     57    if( pSlot->irqNo == irq )   return pSlot;
     58  }
     59
     60  return NULL;
     61}
     62
     63
     64//******************************************************************************
     65//******************************************************************************
     66
    4867int request_irq(unsigned int irq,
    4968                int (near *handler)(int, void *, struct pt_regs *),
    5069                unsigned long x0, const char *x1, void *x2)
    5170{
    52     int i;
    53 
    54     if(RMRequestIRQ(hResMgr, irq, (x0 & SA_SHIRQ) ? TRUE : FALSE) == FALSE) {
    55         dprintf(("RMRequestIRQ failed for irq %d", irq));
    56         return 0;
    57     }
    58 
    59     if(irq > 0xF) {
    60         DebugInt3();
    61         return 0;
    62     }
    63 
    64     for(i=0;i<MAX_SHAREDIRQS;i++)
    65     {
    66         if(irqHandlers[irq][i].handler == 0)
    67         {
    68             irqHandlers[irq][i].handler = handler;
    69             irqHandlers[irq][i].x0      = x0;
    70             irqHandlers[irq][i].x1      = (char *)x1;
    71             irqHandlers[irq][i].x2      = x2;
    72             nrIrqHandlers[irq]++;
    73 
    74             if(nrIrqHandlers[irq] == 1)
    75             {
    76                 if(RMSetIrq(irq, (x0 & SA_SHIRQ) ? TRUE : FALSE, &oss_process_interrupt) == FALSE)
     71    IRQ_SLOT    *pSlot = FindSlot(irq);
     72    unsigned    u, uSlotNo = (unsigned)-1;
     73  if( !pSlot )
     74  {
     75    // find empty slot
     76    for( uSlotNo = 0; uSlotNo < MAX_IRQ_SLOTS; uSlotNo++ )
     77    {
     78      if( arSlots[uSlotNo].flHandlers == 0 )
     79      {
     80        pSlot = &arSlots[uSlotNo];      break;
     81      }
     82    }
     83
     84    }
     85
     86  if( pSlot )
     87  {
     88    if(RMRequestIRQ(/*hResMgr,*/ irq, (x0 & SA_SHIRQ) != 0) == FALSE) {
     89        dprintf(("RMRequestIRQ failed for irq %d", irq));
     90//      return 0;
     91    }
     92
     93    for( u = 0; u < MAX_SHAREDIRQS; u++ )
     94    {
     95      if( pSlot->irqHandlers[u].handler == NULL )
     96      {
     97          pSlot->irqNo = irq;
     98        pSlot->irqHandlers[u].handler = handler;
     99        pSlot->irqHandlers[u].x0 = x0;
     100        pSlot->irqHandlers[u].x1 = (char *)x1;
     101        pSlot->irqHandlers[u].x2 = x2;
     102
     103        if( pSlot->flHandlers != 0 ||
     104            ALSA_SetIrq(irq, uSlotNo, (x0 & SA_SHIRQ) != 0) )
    77105                {
    78                     break;
     106          pSlot->flHandlers |= 1 << u;
     107          return 0;
    79108                }
     109
     110        break;
    80111            }
    81             return 0;
    82112        }
    83113    }
    84     dprintf(("request_irq: Unable to register irq handler for irq %d\n", irq));
     114
     115  dprintf(("request_irq: Unable to register irq handler for irq %d\n", irq));
    85116    return 1;
    86117}
     118
     119
    87120//******************************************************************************
    88121//******************************************************************************
    89122void free_irq(unsigned int irq, void *userdata)
    90123{
    91     int i;
    92 
    93     for(i=0;i<MAX_SHAREDIRQS;i++)
    94     {
    95         if(irqHandlers[irq][i].x2 == userdata) {
    96             irqHandlers[irq][i].handler = 0;
    97             irqHandlers[irq][i].x0      = 0;
    98             irqHandlers[irq][i].x1      = 0;
    99             irqHandlers[irq][i].x2      = 0;
    100             if(--nrIrqHandlers[irq] == 0) {
    101                 RMFreeIrq(irq);
     124  unsigned      u;
     125  IRQ_SLOT      *pSlot;
     126
     127  if( (pSlot = FindSlot(irq)) != NULL )
     128  {
     129    for( u = 0; u < MAX_SHAREDIRQS; u++ )
     130    {
     131      if( pSlot->irqHandlers[u].x2 == userdata )
     132      {
     133        pSlot->flHandlers &= ~(1 << u);
     134        if( pSlot->flHandlers == 0 )
     135        {
     136          ALSA_FreeIrq(pSlot->irqNo);
     137          pSlot->irqNo = 0;
     138//        pSlot->fEOI = 0;
    102139            }
    103             break;
    104         }
    105     }
    106 }
     140
     141        pSlot->irqHandlers[u].handler = NULL;
     142        pSlot->irqHandlers[u].x0 = 0;
     143        pSlot->irqHandlers[u].x1 = NULL;
     144        pSlot->irqHandlers[u].x2 = NULL;
     145
     146        return;
     147
     148      }
     149    }
     150}
     151}
     152
     153
    107154//******************************************************************************
    108155//******************************************************************************
    109156void eoi_irq(unsigned int irq)
    110157{
    111     if(irq > 0xff) {
    112         DebugInt3();
    113         return;
    114     }
    115     eoiIrq[irq]++;
    116 }
    117 //******************************************************************************
    118 //******************************************************************************
    119 BOOL oss_process_interrupt(int irq)
    120 {
     158  (void)irq;
     159/*
     160  IRQ_SLOT      *pSlot = FindSlot(irq);
     161
     162  if( pSlot )   pSlot->fEOI = 1;
     163*/
     164}
     165
     166
     167//******************************************************************************
     168//******************************************************************************
     169BOOL process_interrupt(ULONG ulSlotNo, ULONG *pulIrq)
     170{
     171  unsigned      u;
    121172 int rc;
    122  int  i;
     173  IRQ_SLOT      *pSlot;
    123174
    124175#ifdef DEBUG
     
    137188    }
    138189
    139     for(i=0;i<MAX_SHAREDIRQS;i++)
    140     {
    141         if(irqHandlers[irq][i].handler != 0)
     190  if( ulSlotNo < MAX_IRQ_SLOTS )
     191    {
     192    pSlot = &arSlots[ulSlotNo];
     193
     194    for( u = 0; u < MAX_SHAREDIRQS; u++ )
     195    {
     196      if( pSlot->irqHandlers[u].handler )
    142197        {
    143198            fInInterrupt = TRUE;
    144             rc = irqHandlers[irq][i].handler(irq, irqHandlers[irq][i].x2, 0);
    145             //rc = (eoiIrq[irq] > 0);
     199        rc = pSlot->irqHandlers[u].handler(pSlot->irqNo,
     200                                           pSlot->irqHandlers[u].x2, 0);
    146201            fInInterrupt = FALSE;
    147             if(rc == 1) {
     202
     203        if( rc /*== 1 || pSlot->fEOI*/ ) {
     204
     205            *pulIrq = pSlot->irqNo;
     206//          pSlot->fEOI = 0;
     207
    148208                //ok, this interrupt was intended for us; notify the 16 bits MMPM/2 driver
    149209                OSS32_ProcessIRQ();
    150                 eoiIrq[irq] = 0;
    151210                return TRUE;
    152211            }
    153212        }
    154213    }
     214    }
     215
    155216    return FALSE;
    156217}
     218
     219
    157220//******************************************************************************
    158221//******************************************************************************
     
    161224    return fInInterrupt;
    162225}
     226
     227
    163228//******************************************************************************
    164229//******************************************************************************
     
    167232    dprintf(("disable_irq %d NOT implemented", irq));
    168233}
    169 //******************************************************************************
    170 //******************************************************************************
     234
     235//******************************************************************************
     236//******************************************************************************
     237
     238
     239
  • GPL/trunk/lib32/pci.c

    r35 r63  
    4141#include <osspci.h>
    4242
     43#define MAX_PCI_BUSSES          16
     44#define MAX_PCI_DEVICES         16
     45
    4346struct pci_dev pci_devices[MAX_PCI_DEVICES] = {0};
    4447struct pci_bus pci_busses[MAX_PCI_BUSSES] = {0};
    4548
    46 HRESMGR hResMgr = 0;
    47 
    4849BOOL    fSuspended = FALSE;
    4950extern int nrCardsDetected;
    50 //******************************************************************************
    51 //******************************************************************************
    52 OSSRET OSS32_APMResume()
    53 {
    54     int i;
    55     struct pci_driver *driver;
    56 
    57     dprintf(("OSS32_APMResume"));
    58     for(i=0;i<MAX_PCI_DEVICES;i++)
    59     {
    60         if(pci_devices[i].devfn)
    61         {
    62             driver = pci_devices[i].pcidriver;
    63             if(driver && driver->resume) {
    64                 driver->resume(&pci_devices[i]);
    65                 fSuspended = FALSE;
    66             }
    67         }
    68     }
    69     fSuspended = FALSE;
    70     return OSSERR_SUCCESS;
    71 }
    72 //******************************************************************************
    73 //******************************************************************************
    74 OSSRET OSS32_APMSuspend()
    75 {
    76     int i;
    77     struct pci_driver *driver;
    78 
    79     dprintf(("OSS32_APMSuspend"));
    80     fSuspended = TRUE;
    81     for(i=0;i<MAX_PCI_DEVICES;i++)
    82     {
    83         if(pci_devices[i].devfn)
    84         {
    85             driver = pci_devices[i].pcidriver;
    86             if(driver && driver->suspend) {
    87                 driver->suspend(&pci_devices[i], SNDRV_CTL_POWER_D3cold);
    88             }
    89         }
    90     }
    91     return OSSERR_SUCCESS;
    92 }
    93 //******************************************************************************
    94 //******************************************************************************
    95 int pcidev_prepare(struct pci_dev *dev)
    96 {
    97     dprintf(("pcidev_prepare %x not implemented", dev));
    98     return 1; //todo: correct return value??
    99 }
    100 //******************************************************************************
    101 //******************************************************************************
    102 int pcidev_activate(struct pci_dev *dev)
    103 {
    104     dprintf(("pcidev_activate %x not implemented", dev));
    105     return 1; //todo: correct return value??
    106 }
    107 //******************************************************************************
    108 //******************************************************************************
    109 int pcidev_deactivate(struct pci_dev *dev)
    110 {
    111     dprintf(("pcidev_deactivate %x not implemented", dev));
    112     return 1; //todo: correct return value??
    113 }
     51
    11452
    11553#define PCI_CONFIG_ENABLE       0x80000000
    11654#define PCI_CONFIG_ADDRESS      0xCF8
    11755#define PCI_CONFIG_DATA         0xCFC
    118 /*
    119  * get number of devices of given PCIID
    120  */
    121 int pci_get_dev_num(ULONG pciId)
    122 {
    123     ULONG devNr, busNr, funcNr, temp, cfgaddrreg, detectedId;
    124     int found = 0;
     56
     57
     58//******************************************************************************
     59#define CONFIG_CMD(dev, where)  \
     60    (PCI_CONFIG_ENABLE | (dev->bus->number<<16) | (dev->devfn<<8) | (where & ~3))
     61//******************************************************************************
     62int pci_read_config_byte(struct pci_dev *dev, int where, u8 *value)
     63{
     64    outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
     65    *value = inb(PCI_CONFIG_DATA + (where&3));
     66    return PCIBIOS_SUCCESSFUL;
     67}
     68//******************************************************************************
     69//******************************************************************************
     70int pci_read_config_word(struct pci_dev *dev, int where, u16 *value)
     71{
     72    outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
     73    *value = inw(PCI_CONFIG_DATA + (where&2));
     74    return PCIBIOS_SUCCESSFUL;
     75}
     76//******************************************************************************
     77//******************************************************************************
     78int pci_read_config_dword(struct pci_dev *dev, int where, u32 *value)
     79{
     80    outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
     81    *value = inl(PCI_CONFIG_DATA);
     82    return PCIBIOS_SUCCESSFUL;
     83}
     84//******************************************************************************
     85//******************************************************************************
     86int pci_write_config_byte(struct pci_dev *dev, int where, u8 value)
     87{
     88    outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
     89    outb(value, PCI_CONFIG_DATA + (where&3));
     90    return PCIBIOS_SUCCESSFUL;
     91}
     92//******************************************************************************
     93//******************************************************************************
     94int pci_write_config_word(struct pci_dev *dev, int where, u16 value)
     95{
     96    outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
     97    outw(value, PCI_CONFIG_DATA + (where&2));
     98    return PCIBIOS_SUCCESSFUL;
     99}
     100//******************************************************************************
     101//******************************************************************************
     102int pci_write_config_dword(struct pci_dev *dev, int where, u32 value)
     103{
     104    outl(CONFIG_CMD(dev,where), PCI_CONFIG_ADDRESS);
     105    outl(value, PCI_CONFIG_DATA);
     106    return PCIBIOS_SUCCESSFUL;
     107}
     108//******************************************************************************
     109//******************************************************************************
     110int pcidev_prepare(struct pci_dev *dev)
     111{
     112    dprintf(("pcidev_prepare %x not implemented", dev));
     113    return 1; //todo: correct return value??
     114}
     115//******************************************************************************
     116//******************************************************************************
     117int pcidev_activate(struct pci_dev *dev)
     118{
     119    dprintf(("pcidev_activate %x not implemented", dev));
     120    return 1; //todo: correct return value??
     121}
     122//******************************************************************************
     123//******************************************************************************
     124int pcidev_deactivate(struct pci_dev *dev)
     125{
     126    dprintf(("pcidev_deactivate %x not implemented", dev));
     127    return 1; //todo: correct return value??
     128}
     129
     130
     131
     132//******************************************************************************
     133//******************************************************************************
     134static int pci_query_device(unsigned int vendor, unsigned int device,
     135                            struct pci_dev near *pcidev, int idx)
     136{
     137    int         resNo, addr, found = 0;
     138    u32         devNr, busNr, funcNr, detectedId, pciId, cfgaddrreg, temp, temp2;
     139    u8          headerType;
     140
     141    pciId = (device << 16) | vendor;
    125142
    126143    cfgaddrreg = inl(PCI_CONFIG_ADDRESS);
     
    131148            for(funcNr=0;funcNr<8;funcNr++)
    132149            {
    133                 temp = ((ULONG)((ULONG)devNr<<11UL) + ((ULONG)busNr<<16UL) + ((ULONG)funcNr << 8UL));
    134 
    135                 outl(PCI_CONFIG_ENABLE|temp, PCI_CONFIG_ADDRESS);
     150                headerType = 0;
     151                temp = PCI_CONFIG_ENABLE | (busNr<<16) | (devNr<<11) | (funcNr<<8);
     152                outl(temp, PCI_CONFIG_ADDRESS);
    136153                detectedId = inl(PCI_CONFIG_DATA);
    137 //                printk("det: %x, need: %x\n", detectedId, pciId);
    138                 if(detectedId == pciId)
    139                     found++;
     154                if( detectedId != 0xffffffff )
     155                {
     156                    outl(temp | (PCI_HEADER_TYPE & ~3), PCI_CONFIG_ADDRESS);
     157                    headerType = inb(PCI_CONFIG_DATA + (PCI_HEADER_TYPE & 3));
     158                }
     159                //              printk("det: %x (%x), need: %x\n", detectedId, headerType, pciId);
     160
     161                if( detectedId == pciId &&
     162                   (headerType & 0x7f) == PCI_HEADER_TYPE_NORMAL )
     163                {
     164                    if( found++ == idx )
     165                    {
     166                        memset((void near *)pcidev, 0, sizeof(struct pci_dev));
     167
     168                        pcidev->vendor      = vendor;
     169                        pcidev->device      = device;
     170                        pcidev->bus         = &pci_busses[busNr];
     171                        pcidev->bus->number = busNr;
     172                        pcidev->devfn       = (devNr << 3) | funcNr;
     173                        pcidev->hdr_type    = headerType & 0x7f;
     174
     175                        pcidev->prepare    = pcidev_prepare;
     176                        pcidev->activate   = pcidev_activate;
     177                        pcidev->deactivate = pcidev_deactivate;
     178                        pcidev->active     = 1;
     179                        pcidev->ro         = 0;
     180                        pcidev->sibling    = NULL;
     181                        pcidev->next       = NULL;
     182                        pcidev->dma_mask   = 0xFFFFFFFF;
     183
     184                        // Subsystem ID
     185                        pci_read_config_word(pcidev, PCI_SUBSYSTEM_VENDOR_ID,
     186                                             &pcidev->subsystem_vendor);
     187                        pci_read_config_word(pcidev, PCI_SUBSYSTEM_ID,
     188                                             &pcidev->subsystem_device);
     189
     190                        // I/O  and MEM
     191                        resNo = 0;
     192                        for( addr = PCI_BASE_ADDRESS_0; addr <= PCI_BASE_ADDRESS_5; addr += 4 )
     193                        {
     194                            pci_read_config_dword(pcidev, addr, &temp);
     195                            if( temp != 0 && temp != 0xffffffff )
     196                            {
     197                                pci_write_config_dword(pcidev, addr, 0xffffffff);
     198                                pci_read_config_dword(pcidev, addr, &temp2);
     199                                pci_write_config_dword(pcidev, addr, temp);
     200
     201                                if( temp & PCI_BASE_ADDRESS_SPACE_IO )
     202                                {
     203                                    pcidev->resource[resNo].flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO;
     204                                    pcidev->resource[resNo].start = temp & PCI_BASE_ADDRESS_IO_MASK;
     205                                    pcidev->resource[resNo].end   = pcidev->resource[resNo].start +
     206                                        ~(temp2 & PCI_BASE_ADDRESS_IO_MASK) + 1;
     207                                }
     208                                else
     209                                {
     210                                    pcidev->resource[resNo].flags = IORESOURCE_MEM | IORESOURCE_MEM_WRITEABLE;
     211                                    pcidev->resource[resNo].start = temp & PCI_BASE_ADDRESS_MEM_MASK;
     212                                    pcidev->resource[resNo].end   = pcidev->resource[resNo].start +
     213                                        ~(temp2 & PCI_BASE_ADDRESS_MEM_MASK) + 1;
     214                                }
     215
     216                                resNo++;
     217
     218                            }
     219                        }
     220
     221                        // IRQ and PIN
     222                        pci_read_config_dword(pcidev, PCI_INTERRUPT_LINE, &temp);
     223                        if( (u8)temp && (u8)temp != 0xff )
     224                        {
     225                            pcidev->irq_resource[0].flags = IORESOURCE_IRQ;
     226                            pcidev->irq_resource[0].start =
     227                                pcidev->irq_resource[0].end   = temp & 0xffff;
     228                            pcidev->irq = (u8)temp;
     229                        }
     230
     231                        return 1;
     232                    }
     233                }
     234
     235                // don't need to check more, if function 0 not present or single
     236                if( funcNr == 0 && !(headerType & 0x80) )               break;
    140237            }
    141238        }
    142    }
    143 
    144     if(!found) {
    145         outl(cfgaddrreg, PCI_CONFIG_ADDRESS);
    146         return 0;
    147     }
    148     return found;
    149 }
    150 //******************************************************************************
    151 //TODO: Doesn't completely fill in the pci_dev structure
    152 //******************************************************************************
    153 int FindPCIDevice(unsigned int vendor, unsigned int device, struct pci_dev near *pcidev, int idx)
    154 {
    155     IDC_RESOURCE idcres;
    156     int i, residx = 0;
    157 
    158     pcidev->prepare    = pcidev_prepare;
    159     pcidev->activate   = pcidev_activate;
    160     pcidev->deactivate = pcidev_deactivate;
    161     pcidev->active     = 1;
    162     pcidev->ro         = 0;
    163     pcidev->sibling    = NULL;
    164     pcidev->next       = NULL;
    165     pcidev->vendor     = vendor;
    166     pcidev->device     = device;
    167     pcidev->dma_mask   = 0xFFFFFFFF;
    168 
    169 
    170     //    printk("FindPCIDevice vend: %x, id: %x\n",vendor, device);
    171     hResMgr = 0;
    172     hResMgr = RMFindPCIDevice(vendor, device, &idcres, idx);
    173     if(hResMgr == 0) {
    174         return FALSE;
    175     }
    176     pcidev->devfn = idcres.devfn;
    177     //pcidev->devfn = idcres.devfn + 1;
    178 
    179     for(i=0;i<MAX_RES_IO;i++) {
    180         if(idcres.io[i] != 0xffff) {
    181             pcidev->resource[residx].name  = 0;
    182             pcidev->resource[residx].child = 0;
    183             pcidev->resource[residx].sibling = 0;
    184             pcidev->resource[residx].parent = 0;
    185             pcidev->resource[residx].start = idcres.io[i];
    186             pcidev->resource[residx].end   = idcres.io[i] + idcres.iolength[i]; //inclusive??
    187             pcidev->resource[residx].flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO;
    188 
    189             residx++;
    190         }
    191     }
    192     for(i=0;i<MAX_RES_MEM;i++) {
    193         if(idcres.mem[i] != 0xffffffff) {
    194             pcidev->resource[residx].name  = 0;
    195             pcidev->resource[residx].child = 0;
    196             pcidev->resource[residx].sibling = 0;
    197             pcidev->resource[residx].parent = 0;
    198             pcidev->resource[residx].start = idcres.mem[i];
    199             pcidev->resource[residx].end   = idcres.mem[i] + idcres.memlength[i]; //inclusive??
    200             pcidev->resource[residx].flags = IORESOURCE_MEM | IORESOURCE_MEM_WRITEABLE;
    201             printk("residx: %i start: %x\n", residx, pcidev->resource[residx].start);
    202             residx++;
    203         }
    204     }
    205     for(i=0;i<MAX_RES_DMA;i++) {
    206         if(idcres.dma[i] != 0xffff) {
    207             pcidev->dma_resource[i].name  = 0;
    208             pcidev->dma_resource[i].child = 0;
    209             pcidev->dma_resource[i].sibling = 0;
    210             pcidev->dma_resource[i].parent = 0;
    211             pcidev->dma_resource[i].start = idcres.dma[i];
    212             pcidev->dma_resource[i].end   = idcres.dma[i];
    213             //todo: 8/16 bits
    214             pcidev->dma_resource[i].flags = IORESOURCE_DMA;
    215         }
    216     }
    217     for(i=0;i<MAX_RES_IRQ;i++) {
    218         if(idcres.irq[i] != 0xffff) {
    219             pcidev->irq_resource[i].name  = 0;
    220             pcidev->irq_resource[i].child = 0;
    221             pcidev->irq_resource[i].sibling = 0;
    222             pcidev->irq_resource[i].parent = 0;
    223             pcidev->irq_resource[i].start = idcres.irq[i];
    224             pcidev->irq_resource[i].end   = idcres.irq[i];
    225             //todo: irq flags
    226             pcidev->irq_resource[9].flags = IORESOURCE_IRQ;
    227         }
    228     }
    229     if(pcidev->irq_resource[0].start != 0xffff) {
    230          pcidev->irq = pcidev->irq_resource[0].start;
    231     }
    232     else pcidev->irq = 0;
    233 
    234     if(idcres.busnr > MAX_PCI_BUSSES) {
    235         DebugInt3();
    236         return FALSE;
    237     }
    238     pcidev->bus = &pci_busses[idcres.busnr];
    239     pcidev->bus->number = idcres.busnr;
    240 
    241     pci_read_config_word(pcidev, PCI_SUBSYSTEM_VENDOR_ID, &pcidev->subsystem_vendor);
    242     pci_read_config_word(pcidev, PCI_SUBSYSTEM_ID, &pcidev->subsystem_device);
    243 
    244     return TRUE;
    245 }
     239    }
     240    outl(cfgaddrreg, PCI_CONFIG_ADDRESS);
     241    return 0;
     242
     243}
     244
    246245//******************************************************************************
    247246//******************************************************************************
     
    249248{
    250249    int i, idx;
    251     HRESMGR hResMgrTmp = 0;
    252250
    253251    if((int)from < 8) {
    254252        idx = (int)from; // dirty hack
    255 //        return 0;
     253        //        return 0;
    256254    } else
    257255        idx = 0;
    258 //    printk("searching device. vendor %x, pci id %x, idx %i\n",vendor,device, idx);
    259     //not very pretty
    260     if(hResMgr) {
    261         hResMgrTmp = hResMgr;
    262         hResMgr    = 0;
    263     }
     256
    264257    for(i=0;i<MAX_PCI_DEVICES;i++)
    265258    {
    266259        if(pci_devices[i].devfn == 0)
    267260        {
    268             if(FindPCIDevice(vendor, device, (struct pci_dev near *)&pci_devices[i], idx) == TRUE) {
    269                 if(hResMgrTmp) {
    270                     RMDestroy(hResMgr);
    271                     hResMgr = hResMgrTmp;
    272                 }
    273 //                pci_read_config_dword(&pci_devices[i], PCI_CLASS_REVISION, &pci_devices[i]._class);
    274 //                if (((pci_devices[i]._class >> 8) & 0xffff) == PCI_CLASS_MULTIMEDIA_AUDIO)
    275                     return &pci_devices[i];
    276             }
    277 #ifdef DEBUG
    278                 printk("wrong device. vendor %x, pci id %x\n",vendor,device);
    279 #endif
    280             break;
    281         }
    282     }
    283     if(hResMgrTmp) {
    284         RMDestroy(hResMgr);
    285         hResMgr = hResMgrTmp;
    286     }
    287     return 0;
    288 }
    289 //******************************************************************************
    290 //******************************************************************************
    291 struct resource * __request_region(struct resource *a, unsigned long start, unsigned long n, const char *name)
    292 {
    293         struct resource *resource;
     261            if( pci_query_device(vendor, device, (struct pci_dev near *)&pci_devices[i], idx) )
     262                return &pci_devices[i];
     263            else
     264                break;
     265        }
     266    }
     267
     268    return NULL;
     269}
     270//******************************************************************************
     271//******************************************************************************
     272struct resource * __request_region(struct resource *a, unsigned long start,
     273                                   unsigned long n, const char *name)
     274{
     275    struct resource *resource;
    294276
    295277    if(a->flags & IORESOURCE_MEM) {
    296         if(RMRequestMem(hResMgr, start, n) == FALSE) {
     278        if(RMRequestMem(/*hResMgr,*/ start, n) == FALSE) {
    297279            printk("RMRequestIO failed for io %x, length %x\n", start, n);
    298280            return NULL;
    299281        }
    300282    }
    301     else
    302     if(a->flags & IORESOURCE_IO) {
    303         if(RMRequestIO(hResMgr, start, n) == FALSE) {
     283    else if(a->flags & IORESOURCE_IO) {
     284        if(RMRequestIO(/*hResMgr,*/ start, n) == FALSE) {
    304285            printk("RMRequestIO failed for io %x, length %x\n", start, n);
    305286            return NULL;
     
    307288    }
    308289
    309         resource = kmalloc(sizeof(struct resource), GFP_KERNEL);
    310         if (resource == NULL)
    311                 return NULL;
    312         resource->name  = name;
    313         resource->start = start;
    314         resource->end   = start + n - 1;
    315         resource->flags = a->flags;
    316         return resource;
    317 }
    318 //******************************************************************************
    319 //******************************************************************************
    320 void __release_region(struct resource *resource, unsigned long b, unsigned long c)
    321 {
    322     if(resource) {
    323         kfree(resource);
     290    resource = kmalloc(sizeof(struct resource), GFP_KERNEL);
     291    if (resource == NULL)
     292        return NULL;
     293    resource->name  = name;
     294    resource->start = start;
     295    resource->end     = start + n; // - 1;
     296    resource->flags = a->flags;
     297    resource->parent  =
     298        resource->child   = NULL;
     299
     300    // insert in list
     301    resource->sibling = a->sibling;
     302    a->sibling = resource;
     303
     304    return resource;
     305}
     306//******************************************************************************
     307//******************************************************************************
     308void __release_region(struct resource *a,
     309                      unsigned long start, unsigned long n)
     310{
     311    struct resource     *resource;
     312    struct resource     **ppres = &a->sibling;
     313    unsigned long       end = start + n; // - 1;
     314
     315    while( *ppres )
     316    {
     317        resource = *ppres;
     318
     319        if( resource->start == start && resource->end == end )
     320        {
     321            // remove from list
     322            *ppres = resource->sibling;
     323            kfree(resource);
     324            return;
     325        }
     326
     327        ppres = &resource->sibling;
    324328    }
    325329}
     
    335339}
    336340//******************************************************************************
    337 #define CONFIG_CMD(dev, where)   (0x80000000 | (dev->bus->number << 16) | (dev->devfn << 8) | (where & ~3))
    338 //******************************************************************************
    339 int pci_read_config_byte(struct pci_dev *dev, int where, u8 *value)
    340 {
    341     outl(CONFIG_CMD(dev,where), 0xCF8);
    342     *value = inb(0xCFC + (where&3));
    343     return PCIBIOS_SUCCESSFUL;
    344 }
    345 //******************************************************************************
    346 //******************************************************************************
    347 int pci_read_config_word(struct pci_dev *dev, int where, u16 *value)
    348 {
    349     outl(CONFIG_CMD(dev,where), 0xCF8);
    350     *value = inw(0xCFC + (where&2));
    351     return PCIBIOS_SUCCESSFUL;
    352 }
    353 //******************************************************************************
    354 //******************************************************************************
    355 int pci_read_config_dword(struct pci_dev *dev, int where, u32 *value)
    356 {
    357     outl(CONFIG_CMD(dev,where), 0xCF8);
    358     *value = inl(0xCFC);
    359     return PCIBIOS_SUCCESSFUL;
    360 }
    361 //******************************************************************************
    362 //******************************************************************************
    363 int pci_write_config_byte(struct pci_dev *dev, int where, u8 value)
    364 {
    365     outl(CONFIG_CMD(dev,where), 0xCF8);
    366     outb(value, 0xCFC + (where&3));
    367     return PCIBIOS_SUCCESSFUL;
    368 }
    369 //******************************************************************************
    370 //******************************************************************************
    371 int pci_write_config_word(struct pci_dev *dev, int where, u16 value)
    372 {
    373     outl(CONFIG_CMD(dev,where), 0xCF8);
    374     outw(value, 0xCFC + (where&2));
    375     return PCIBIOS_SUCCESSFUL;
    376 }
    377 //******************************************************************************
    378 //******************************************************************************
    379 int pci_write_config_dword(struct pci_dev *dev, int where, u32 value)
    380 {
    381     outl(CONFIG_CMD(dev,where), 0xCF8);
    382     outl(value, 0xCFC);
    383     return PCIBIOS_SUCCESSFUL;
    384 }
    385 //******************************************************************************
    386341//******************************************************************************
    387342int pcibios_present(void)
     
    409364int pci_find_capability(struct pci_dev *dev, int cap)
    410365{
    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;
     366    u16 status;
     367    u8 pos, id;
     368    int ttl = 48;
     369
     370    pci_read_config_word(dev, PCI_STATUS, &status);
     371    if (!(status & PCI_STATUS_CAP_LIST))
     372        return 0;
     373    pci_read_config_byte(dev, PCI_CAPABILITY_LIST, &pos);
     374    while (ttl-- && pos >= 0x40) {
     375        pos &= ~3;
     376        pci_read_config_byte(dev, pos + PCI_CAP_LIST_ID, &id);
     377        if (id == 0xff)
     378            break;
     379        if (id == cap)
     380            return pos;
     381        pci_read_config_byte(dev, pos + PCI_CAP_LIST_NEXT, &pos);
     382    }
     383    return 0;
    429384}
    430385//******************************************************************************
     
    437392int pci_set_power_state(struct pci_dev *dev, int new_state)
    438393{
    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;
     394    u32 base[5], romaddr;
     395    u16 pci_command, pwr_command;
     396    u8  pci_latency, pci_cacheline;
     397    int i, old_state;
     398    int pm = pci_find_capability(dev, PCI_CAP_ID_PM);
     399
     400    if (!pm)
     401        return 0;
     402    pci_read_config_word(dev, pm + PCI_PM_CTRL, &pwr_command);
     403    old_state = pwr_command & PCI_PM_CTRL_STATE_MASK;
     404    if (old_state == new_state)
     405        return old_state;
     406    if (old_state == 3) {
     407        pci_read_config_word(dev, PCI_COMMAND, &pci_command);
     408        pci_write_config_word(dev, PCI_COMMAND, pci_command & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
     409        for (i = 0; i < 5; i++)
     410            pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + i*4, &base[i]);
     411        pci_read_config_dword(dev, PCI_ROM_ADDRESS, &romaddr);
     412        pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency);
     413        pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &pci_cacheline);
     414        pci_write_config_word(dev, pm + PCI_PM_CTRL, new_state);
     415        for (i = 0; i < 5; i++)
     416            pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + i*4, base[i]);
     417        pci_write_config_dword(dev, PCI_ROM_ADDRESS, romaddr);
     418        pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
     419        pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, pci_cacheline);
     420        pci_write_config_byte(dev, PCI_LATENCY_TIMER, pci_latency);
     421        pci_write_config_word(dev, PCI_COMMAND, pci_command);
     422    } else
     423        pci_write_config_word(dev, pm + PCI_PM_CTRL, (pwr_command & ~PCI_PM_CTRL_STATE_MASK) | new_state);
     424    return old_state;
    470425}
    471426//******************************************************************************
     
    478433int pci_enable_device(struct pci_dev *dev)
    479434{
    480         u16 pci_command;
    481 
    482         printk("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;
     435    u16 pci_command;
     436
     437    printk("pci_enable_device %x\n", dev);
     438
     439    pci_read_config_word(dev, PCI_COMMAND, &pci_command);
     440    pci_write_config_word(dev, PCI_COMMAND, pci_command | (PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
     441    pci_set_power_state(dev, 0);
     442    return 0;
    488443}
    489444//******************************************************************************
     
    491446int pci_register_driver(struct pci_driver *driver)
    492447{
    493     struct pci_dev *pcidev = NULL;
    494     int i = 0, j;
    495     int dev_num;
    496     ULONG pcidevid;
    497 
    498     while(driver->id_table[i].vendor)
     448    int i, j, dev_num;
     449    struct pci_dev *pcidev;
     450
     451    for( i = 0; driver->id_table[i].vendor; i++)
    499452    {
    500         pcidevid = ((ULONG)driver->id_table[i].device << 16) |
    501             (ULONG)driver->id_table[i].vendor;
    502         dev_num = pci_get_dev_num(pcidevid);
    503 
    504         if (dev_num) {
    505             printk("found: %i number of %x, id: %x\n",dev_num,driver->id_table[i].vendor, driver->id_table[i].device);
    506 
    507             for (j=0; j < dev_num; j++) // dirty hack for multiply cards with same PCIID
    508             {
    509                 pcidev = pci_find_device(driver->id_table[i].vendor, driver->id_table[i].device, (struct pci_dev *)j);
    510                 //        printk("checking pci vend: %x, id: %x %i\n",driver->id_table[i].vendor, driver->id_table[i].device, i);
    511 #ifdef DEBUG
    512                 //        dprintf(("checked device: vendor %x, pci id %x, pcidev %x, probe %x",
    513                 //                 driver->id_table[i].vendor,driver->id_table[i].device, pcidev, driver->probe));
    514 #endif
    515                 if(pcidev && driver->probe) {
    516                     printk("found: %x, id: %x idx %i\n",driver->id_table[i].vendor, driver->id_table[i].device, j);
    517 
    518                     if(driver->probe(pcidev, &driver->id_table[i]) == 0) {
    519                         //remove resource manager object for this device and
    520                         //register resources with RM
    521                         RMFinialize(hResMgr);
    522                         hResMgr = 0;
    523 
    524                         //save driver pointer for suspend/resume calls
    525                         pcidev->pcidriver = (void *)driver;
    526                         pcidev->current_state = 4;
    527                         //return 1;
    528                     }
    529                     else pcidev->devfn = 0;
    530 
    531                     RMDestroy(hResMgr);
    532                     hResMgr = 0;
     453        dev_num = 0;
     454        while( (pcidev = pci_find_device(driver->id_table[i].vendor,
     455                                         driver->id_table[i].device,
     456                                         (struct pci_dev *)dev_num)) != NULL )
     457        {
     458            RMInit();
     459            if( driver->probe) {
     460                printk("found: %x, id: %x idx %i\n",driver->id_table[i].vendor, driver->id_table[i].device, dev_num);
     461
     462                if(driver->probe(pcidev, &driver->id_table[i]) == 0) {
     463                    pcidev->pcidriver = (void *)driver;
     464                    pcidev->current_state = 4;
     465
     466                    // create adapter
     467                    RMDone((driver->id_table[i].vendor << 16) | driver->id_table[i].device);
     468
     469                    return 1;
    533470                }
    534             } // for j
    535             return dev_num;
    536         }
    537         i++;
     471                else pcidev->devfn = 0;
     472            }
     473
     474            RMDone(0);
     475
     476            dev_num++;
     477
     478        }
    538479    }
    539480    return 0;
     
    578519void pci_set_master(struct pci_dev *dev)
    579520{
    580         u16 cmd;
    581 
    582         pci_read_config_word(dev, PCI_COMMAND, &cmd);
    583         if (! (cmd & PCI_COMMAND_MASTER)) {
     521    u16 cmd;
     522
     523    pci_read_config_word(dev, PCI_COMMAND, &cmd);
     524    if (! (cmd & PCI_COMMAND_MASTER)) {
    584525        dprintf(("pci_set_master %x", dev));
    585                 cmd |= PCI_COMMAND_MASTER;
    586                 pci_write_config_word(dev, PCI_COMMAND, cmd);
    587         }
     526        cmd |= PCI_COMMAND_MASTER;
     527        pci_write_config_word(dev, PCI_COMMAND, cmd);
     528    }
    588529    return;
    589530}
     
    722663int pci_orig_save_state(struct pci_dev *dev, u32 *buffer)
    723664{
    724         int i;
    725         if (buffer) {
    726                 /* XXX: 100% dword access ok here? */
    727                 for (i = 0; i < 16; i++)
    728                         pci_read_config_dword(dev, i * 4,&buffer[i]);
    729         }
    730         return 0;
     665    int i;
     666    if (buffer) {
     667        /* XXX: 100% dword access ok here? */
     668        for (i = 0; i < 16; i++)
     669            pci_read_config_dword(dev, i * 4,&buffer[i]);
     670    }
     671    return 0;
    731672}
    732673
     
    740681pci_orig_restore_state(struct pci_dev *dev, u32 *buffer)
    741682{
    742         int i;
    743 
    744         if (buffer) {
    745                 for (i = 0; i < 16; i++)
    746                         pci_write_config_dword(dev,i * 4, buffer[i]);
    747         }
    748         /*
    749         * otherwise, write the context information we know from bootup.
    750         * This works around a problem where warm-booting from Windows
    751         * combined with a D3(hot)->D0 transition causes PCI config
    752         * header data to be forgotten.
    753         */
    754         else {
    755                 for (i = 0; i < 6; i ++)
    756                         pci_write_config_dword(dev,
    757                                                PCI_BASE_ADDRESS_0 + (i * 4),
    758                                                dev->resource[i].start);
    759                 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
    760         }
    761         return 0;
     683    int i;
     684
     685    if (buffer) {
     686        for (i = 0; i < 16; i++)
     687            pci_write_config_dword(dev,i * 4, buffer[i]);
     688    }
     689    /*
     690    * otherwise, write the context information we know from bootup.
     691    * This works around a problem where warm-booting from Windows
     692    * combined with a D3(hot)->D0 transition causes PCI config
     693    * header data to be forgotten.
     694    */
     695    else {
     696        for (i = 0; i < 6; i ++)
     697            pci_write_config_dword(dev,
     698                                   PCI_BASE_ADDRESS_0 + (i * 4),
     699                                   dev->resource[i].start);
     700        pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
     701    }
     702    return 0;
    762703}
    763704
    764705struct saved_config_tbl {
    765         struct pci_dev *pci;
    766         u32 config[16];
     706    struct pci_dev *pci;
     707    u32 config[16];
    767708};
    768709static struct saved_config_tbl saved_tbl[16];
     
    770711void pci_save_state(struct pci_dev *pci)
    771712{
    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) {
    776                         saved_tbl[i].pci = pci;
    777                         pci_orig_save_state(pci, saved_tbl[i].config);
    778                         return;
    779                 }
    780         }
    781         printk(KERN_DEBUG "snd: no pci config space found!\n");
     713    int i;
     714    /* FIXME: mutex needed for race? */
     715    for (i = 0; i < ARRAY_SIZE(saved_tbl); i++) {
     716        if (! saved_tbl[i].pci) {
     717            saved_tbl[i].pci = pci;
     718            pci_orig_save_state(pci, saved_tbl[i].config);
     719            return;
     720        }
     721    }
     722    printk(KERN_DEBUG "snd: no pci config space found!\n");
    782723}
    783724
    784725void pci_restore_state(struct pci_dev *pci)
    785726{
    786         int i;
    787         /* FIXME: mutex needed for race? */
    788         for (i = 0; i < ARRAY_SIZE(saved_tbl); i++) {
    789                 if (saved_tbl[i].pci == pci) {
    790                         saved_tbl[i].pci = NULL;
    791                         pci_orig_restore_state(pci, saved_tbl[i].config);
    792                         return;
    793                 }
    794         }
    795         printk(KERN_DEBUG "snd: no saved pci config!\n");
     727    int i;
     728    /* FIXME: mutex needed for race? */
     729    for (i = 0; i < ARRAY_SIZE(saved_tbl); i++) {
     730        if (saved_tbl[i].pci == pci) {
     731            saved_tbl[i].pci = NULL;
     732            pci_orig_restore_state(pci, saved_tbl[i].config);
     733            return;
     734        }
     735    }
     736    printk(KERN_DEBUG "snd: no saved pci config!\n");
    796737}
    797738
     
    809750int pci_request_region(struct pci_dev *pdev, int bar, char *res_name)
    810751{
    811         int flags;
    812 
    813         if (pci_resource_len(pdev, bar) == 0)
    814                 return 0;
    815         flags = pci_get_flags(pdev, bar);
    816         if (flags & IORESOURCE_IO) {
    817                 if (check_region(pci_resource_start(pdev, bar), pci_resource_len(pdev, bar)))
    818                     goto err_out;
    819                 request_region(pci_resource_start(pdev, bar),
    820                                pci_resource_len(pdev, bar), res_name);
    821         }
    822         return 0;
     752    int flags;
     753
     754    if (pci_resource_len(pdev, bar) == 0)
     755        return 0;
     756    flags = pci_get_flags(pdev, bar);
     757    if (flags & IORESOURCE_IO) {
     758        if (check_region(pci_resource_start(pdev, bar), pci_resource_len(pdev, bar)))
     759            goto err_out;
     760        request_region(pci_resource_start(pdev, bar),
     761                       pci_resource_len(pdev, bar), res_name);
     762    }
     763    else if (flags & IORESOURCE_MEM) {
     764        if (check_mem_region(pci_resource_start(pdev, bar), pci_resource_len(pdev, bar)))
     765            goto err_out;
     766        request_mem_region(pci_resource_start(pdev, bar),
     767                           pci_resource_len(pdev, bar), res_name);
     768    }
     769
     770    return 0;
    823771
    824772err_out:
    825         printk(KERN_WARNING "PCI: Unable to reserve %s region #%d:%lx@%lx for device %s\n",
    826                 flags & IORESOURCE_IO ? "I/O" : "mem",
    827                 bar + 1, /* PCI BAR # */
    828                 pci_resource_len(pdev, bar), pci_resource_start(pdev, bar),
    829                 res_name);
    830         return -EBUSY;
     773    printk(KERN_WARNING "PCI: Unable to reserve %s region #%d:%lx@%lx for device %s\n",
     774           flags & IORESOURCE_IO ? "I/O" : "mem",
     775           bar + 1, /* PCI BAR # */
     776           pci_resource_len(pdev, bar), pci_resource_start(pdev, bar),
     777           res_name);
     778    return -EBUSY;
    831779}
    832780
    833781void pci_release_region(struct pci_dev *pdev, int bar)
    834782{
    835         int flags;
    836 
    837         if (pci_resource_len(pdev, bar) == 0)
    838                 return;
    839         flags = pci_get_flags(pdev, bar);
    840         if (flags & IORESOURCE_IO) {
    841                 release_region(pci_resource_start(pdev, bar),
    842                                pci_resource_len(pdev, bar));
    843         }
     783    int flags;
     784
     785    if (pci_resource_len(pdev, bar) == 0)
     786        return;
     787    flags = pci_get_flags(pdev, bar);
     788    if (flags & IORESOURCE_IO) {
     789        release_region(pci_resource_start(pdev, bar),
     790                       pci_resource_len(pdev, bar));
     791    }
     792    else if (flags & IORESOURCE_MEM) {
     793        release_mem_region(pci_resource_start(pdev, bar),
     794                           pci_resource_len(pdev, bar));
     795    }
    844796}
    845797
    846798int pci_request_regions(struct pci_dev *pdev, char *res_name)
    847799{
    848         int i;
    849 
    850         for (i = 0; i < 6; i++)
    851                 if (pci_request_region(pdev, i, res_name))
    852                         goto err;
    853         return 0;
    854  err:
    855         while (--i >= 0)
    856                 pci_release_region(pdev, i);
    857         return -EBUSY;
     800    int i;
     801
     802    for (i = 0; i < 6; i++)
     803        if (pci_request_region(pdev, i, res_name))
     804            goto err;
     805    return 0;
     806    err:
     807        while (--i >= 0)
     808            pci_release_region(pdev, i);
     809        return -EBUSY;
    858810}
    859811
    860812void pci_release_regions(struct pci_dev *pdev)
    861813{
    862         int i;
    863         for (i = 0; i < 6; i++)
    864                 pci_release_region(pdev, i);
     814    int i;
     815    for (i = 0; i < 6; i++)
     816        pci_release_region(pdev, i);
    865817}
    866818
     
    886838int snd_pci_dev_present(const struct pci_device_id *ids)
    887839{
    888         while (ids->vendor || ids->subvendor) {
    889                 if (pci_find_device(ids->vendor, ids->subvendor, NULL))
    890                         return 1;
    891                 ids++;
    892         }
    893         return 0;
     840    while (ids->vendor || ids->subvendor) {
     841        if (pci_find_device(ids->vendor, ids->subvendor, NULL))
     842            return 1;
     843        ids++;
     844    }
     845    return 0;
    894846}
    895847
     
    940892}
    941893#endif
     894
     895
     896//******************************************************************************
     897//******************************************************************************
     898OSSRET OSS32_APMResume()
     899{
     900    int i;
     901    struct pci_driver *driver;
     902
     903    dprintf(("OSS32_APMResume"));
     904
     905    for(i=0;i<MAX_PCI_DEVICES;i++)
     906    {
     907        if(pci_devices[i].devfn)
     908        {
     909            driver = pci_devices[i].pcidriver;
     910            if(driver && driver->resume) {
     911                driver->resume(&pci_devices[i]);
     912                //              fSuspended = FALSE;
     913            }
     914        }
     915    }
     916
     917    fSuspended = FALSE;
     918
     919    return OSSERR_SUCCESS;
     920}
     921//******************************************************************************
     922//******************************************************************************
     923OSSRET OSS32_APMSuspend()
     924{
     925    int i;
     926    struct pci_driver *driver;
     927
     928    dprintf(("OSS32_APMSuspend"));
     929
     930    fSuspended = TRUE;
     931
     932    for(i=0;i<MAX_PCI_DEVICES;i++)
     933    {
     934        if(pci_devices[i].devfn)
     935        {
     936            driver = pci_devices[i].pcidriver;
     937            if(driver && driver->suspend) {
     938                driver->suspend(&pci_devices[i], SNDRV_CTL_POWER_D3cold);
     939            }
     940        }
     941    }
     942
     943    return OSSERR_SUCCESS;
     944}
     945
Note: See TracChangeset for help on using the changeset viewer.