| 1 | /* $Id: rm.hpp,v 1.1.1.1 2003/07/02 13:56:56 eleph Exp $ */
 | 
|---|
| 2 | /*
 | 
|---|
| 3 |  * OS/2 Resource Manager C++ interface header
 | 
|---|
| 4 |  *
 | 
|---|
| 5 |  * (C) 2000-2002 InnoTek Systemberatung GmbH
 | 
|---|
| 6 |  *
 | 
|---|
| 7 |  * This program is free software; you can redistribute it and/or
 | 
|---|
| 8 |  * modify it under the terms of the GNU General Public License as
 | 
|---|
| 9 |  * published by the Free Software Foundation; either version 2 of
 | 
|---|
| 10 |  * the License, or (at your option) any later version.
 | 
|---|
| 11 |  *
 | 
|---|
| 12 |  * This program is distributed in the hope that it will be useful,
 | 
|---|
| 13 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 14 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 15 |  * GNU General Public License for more details.
 | 
|---|
| 16 |  *
 | 
|---|
| 17 |  * You should have received a copy of the GNU General Public
 | 
|---|
| 18 |  * License along with this program; if not, write to the Free
 | 
|---|
| 19 |  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
 | 
|---|
| 20 |  * USA.
 | 
|---|
| 21 |  *
 | 
|---|
| 22 |  */
 | 
|---|
| 23 | 
 | 
|---|
| 24 | #ifndef RM_HPP                  // Skip this file if already included.
 | 
|---|
| 25 | #define RM_HPP
 | 
|---|
| 26 | 
 | 
|---|
| 27 | #define INCL_NOPMAPI
 | 
|---|
| 28 | #define INCL_DOSINFOSEG      // Need Global info seg in rm.cpp algorithms
 | 
|---|
| 29 | #include <os2.h>
 | 
|---|
| 30 | 
 | 
|---|
| 31 | #include <devtype.h>
 | 
|---|
| 32 | #include <devinfo.h>
 | 
|---|
| 33 | #include <include.h>            // Defn's for WatCom based drivers.
 | 
|---|
| 34 | 
 | 
|---|
| 35 | extern "C" {
 | 
|---|
| 36 |    #include <rmbase.h>          // Resource manager definitions.
 | 
|---|
| 37 |    #include "rmcalls.h"
 | 
|---|
| 38 |    #include <rmioctl.h>
 | 
|---|
| 39 | }
 | 
|---|
| 40 | 
 | 
|---|
| 41 | 
 | 
|---|
| 42 | #define NumLogicalDevices 5     // Number of PNP logical devices on adapter.
 | 
|---|
| 43 | 
 | 
|---|
| 44 | #define MAX_DevID 1             // Maximum number of devices with a particular
 | 
|---|
| 45 |                                 // PnP Device ID that we're prepared to deal with.
 | 
|---|
| 46 |                                 // Intention is that this defines the number of
 | 
|---|
| 47 |                                 // adapters we're prepared to deal with.
 | 
|---|
| 48 | #define MAX_DescTextLen MAX_TEXT_DATA
 | 
|---|
| 49 |                                 // MAX_TEXT_DATA in rmioctl.h.  Max length
 | 
|---|
| 50 |                                 // of the descriptive text on any of the free
 | 
|---|
| 51 |                                 // ASCIIZ fields in the RM structures.
 | 
|---|
| 52 | 
 | 
|---|
| 53 | 
 | 
|---|
| 54 | 
 | 
|---|
| 55 | /*
 | 
|---|
| 56 |  * --- LDev_Resources class.
 | 
|---|
| 57 |  */
 | 
|---|
| 58 | 
 | 
|---|
| 59 | /* These "maximums" for number of I/O, IRQ, etc. per logical device, are defined
 | 
|---|
| 60 |    by PnP ISA spec Ver 1.0a 5/5/94, sect 4.6, p. 20. */
 | 
|---|
| 61 | 
 | 
|---|
| 62 | #define MAX_ISA_Dev_IO   8
 | 
|---|
| 63 | #define MAX_ISA_Dev_IRQ  2
 | 
|---|
| 64 | #define MAX_ISA_Dev_DMA  2
 | 
|---|
| 65 | #define MAX_ISA_Dev_MEM  8
 | 
|---|
| 66 | #define MAX_ResourceCount ( MAX_ISA_Dev_IO + MAX_ISA_Dev_IRQ \
 | 
|---|
| 67 |                           + MAX_ISA_Dev_DMA + MAX_ISA_Dev_MEM )
 | 
|---|
| 68 | 
 | 
|---|
| 69 | // This value indicates an empty entry in an LDev_Resource data item.
 | 
|---|
| 70 | #define NoIOValue 0xffff
 | 
|---|
| 71 | 
 | 
|---|
| 72 | class LDev_Resources {          // A class to hold the collection of resources
 | 
|---|
| 73 |                                 // needed by a single logical device.
 | 
|---|
| 74 |  public:
 | 
|---|
| 75 | 
 | 
|---|
| 76 |    /* Public data.  Any unused data member is set to all 0xF.  Arrays are
 | 
|---|
| 77 |     * always initialized to all 0xF's, then filled in in order, from 0..N.
 | 
|---|
| 78 |     */
 | 
|---|
| 79 |       USHORT uIOBase[ MAX_ISA_Dev_IO ];
 | 
|---|
| 80 |       USHORT uIOLength[ MAX_ISA_Dev_IO ];
 | 
|---|
| 81 |       USHORT uIRQLevel[ MAX_ISA_Dev_IRQ ];
 | 
|---|
| 82 |       USHORT uDMAChannel[ MAX_ISA_Dev_DMA ];
 | 
|---|
| 83 |       ULONG  uMemBase[ MAX_ISA_Dev_MEM ];
 | 
|---|
| 84 |       ULONG  uMemLength[ MAX_ISA_Dev_MEM ];
 | 
|---|
| 85 | 
 | 
|---|
| 86 |    /* Information available from RM interface but not used:
 | 
|---|
| 87 |     *   For all:  Flags (Exclusive, Multiplexed, Shared, Grant-Yield)
 | 
|---|
| 88 |     *   IO:       IOAddressLines (10 or 16)
 | 
|---|
| 89 |     *   IRQ:      PCI Irq Pin (10 or 16)
 | 
|---|
| 90 |     *   DMA:      (Flags only)
 | 
|---|
| 91 |     *   Memory:   Base, Length
 | 
|---|
| 92 |     */
 | 
|---|
| 93 | 
 | 
|---|
| 94 |    // Are there any values in this structure?
 | 
|---|
| 95 |    BOOL isEmpty ( void );
 | 
|---|
| 96 | 
 | 
|---|
| 97 |    // Clear the structure (set all fields to "NoIOValue".
 | 
|---|
| 98 |    void vClear ( void );
 | 
|---|
| 99 | };
 | 
|---|
| 100 | 
 | 
|---|
| 101 | #define MAX_PCI_BASE_ADDRESS    7
 | 
|---|
| 102 | 
 | 
|---|
| 103 | #pragma pack(1)
 | 
|---|
| 104 | typedef struct
 | 
|---|
| 105 | {
 | 
|---|
| 106 |         USHORT VendorID;
 | 
|---|
| 107 |         USHORT DeviceID;
 | 
|---|
| 108 |         USHORT Command;
 | 
|---|
| 109 |         USHORT Status;
 | 
|---|
| 110 |         UCHAR  RevisionID;
 | 
|---|
| 111 |         UCHAR  filler1[7];
 | 
|---|
| 112 |         ULONG  Bar[MAX_PCI_BASE_ADDRESS];
 | 
|---|
| 113 |         USHORT SubsystemVendorID;
 | 
|---|
| 114 |         USHORT SubsystemID;
 | 
|---|
| 115 |         ULONG  filler3[3];
 | 
|---|
| 116 |         UCHAR  InterruptLine;
 | 
|---|
| 117 |         UCHAR  InterruptPin;
 | 
|---|
| 118 |         UCHAR  Max_Gnt;
 | 
|---|
| 119 |         UCHAR  Max_Lat;
 | 
|---|
| 120 |         UCHAR  TRDY_Timeout;
 | 
|---|
| 121 |         UCHAR  Retry_Timeout;
 | 
|---|
| 122 |         UCHAR  filler4[0x9a];
 | 
|---|
| 123 |         UCHAR  CapabilityID;
 | 
|---|
| 124 |         UCHAR  NextItemPtr;
 | 
|---|
| 125 |         USHORT PowerMgtCapability;
 | 
|---|
| 126 |         USHORT PowerMgtCSR;
 | 
|---|
| 127 | } PCIConfigData;
 | 
|---|
| 128 | #pragma pack()
 | 
|---|
| 129 | 
 | 
|---|
| 130 | #define PCI_CONFIG_ENABLE       0x80000000
 | 
|---|
| 131 | #define PCI_CONFIG_ADDRESS      0xCF8
 | 
|---|
| 132 | #define PCI_CONFIG_DATA         0xCFC
 | 
|---|
| 133 | 
 | 
|---|
| 134 | void _outpd(int port, unsigned long data);
 | 
|---|
| 135 | #pragma aux _outpd =       \
 | 
|---|
| 136 |   "out dx, eax"                  \
 | 
|---|
| 137 |   parm [dx] [eax];
 | 
|---|
| 138 | 
 | 
|---|
| 139 | unsigned long _inpd(int port);
 | 
|---|
| 140 | #pragma aux _inpd =       \
 | 
|---|
| 141 |   "in eax,dx"            \
 | 
|---|
| 142 |   parm [dx]             \
 | 
|---|
| 143 |   value [eax];
 | 
|---|
| 144 | 
 | 
|---|
| 145 | 
 | 
|---|
| 146 | #define CONFIG_CMD(busnr, devfn, where)   (0x80000000 | (busnr << 16) | (devfn << 8) | (where & ~3))
 | 
|---|
| 147 | 
 | 
|---|
| 148 | /*
 | 
|---|
| 149 |  * --- ResourceManager class.
 | 
|---|
| 150 |  */
 | 
|---|
| 151 | 
 | 
|---|
| 152 | enum RMObjectState { rmDriverCreated, rmDriverFailed, rmAdapterCreated, rmAdapterFailed, rmAllocFailed };
 | 
|---|
| 153 | 
 | 
|---|
| 154 | class ResourceManager {         // A class to encapsulate system resource
 | 
|---|
| 155 |                                 // allocation issues.  Ref. documentation
 | 
|---|
| 156 |  public:                        // at bottom of file.
 | 
|---|
| 157 | 
 | 
|---|
| 158 |    ResourceManager (  );
 | 
|---|
| 159 |         // Register the device driver (this activates the RM interface).
 | 
|---|
| 160 |         // Intention is that only one ResourceManager object is created
 | 
|---|
| 161 |         // in driver, which will handle all audio.
 | 
|---|
| 162 | 
 | 
|---|
| 163 |    int bIsDevDetected ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice, int idx);
 | 
|---|
| 164 |         // Return an indicator of whether or not named device is present.
 | 
|---|
| 165 |         // in:   - PnP Device ID, compressed ASCII.
 | 
|---|
| 166 |         //       - Search flags, ref rmbase.h SEARCH_ID_*;  also documented
 | 
|---|
| 167 |         //         as SearchFlags parm in PDD RM API RMDevIDToHandleList().
 | 
|---|
| 168 |         //         Only one of the search flags can be selected.
 | 
|---|
| 169 |         // out:    True iff at least one device is detected
 | 
|---|
| 170 |         // rem:    It's expected that the 1st parm, the PnP DevID, will
 | 
|---|
| 171 |         //         be a DEVICE ID and the
 | 
|---|
| 172 | 
 | 
|---|
| 173 |    //###
 | 
|---|
| 174 |    BOOL GetRMDetectedResources ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice );
 | 
|---|
| 175 | 
 | 
|---|
| 176 |    LDev_Resources* pGetDevResources ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice);
 | 
|---|
| 177 | 
 | 
|---|
| 178 |    inline RMObjectState getState() { return _state; };
 | 
|---|
| 179 |         // Return state of RM object.
 | 
|---|
| 180 | 
 | 
|---|
| 181 |    BOOL requestIORange(ULONG ulBase, ULONG ulLength);
 | 
|---|
| 182 |    BOOL requestMemRange(ULONG ulBase, ULONG ulLength);
 | 
|---|
| 183 |    BOOL requestIRQ(USHORT usIRQ, BOOL fShared);
 | 
|---|
| 184 |    BOOL requestDMA(USHORT usDMA);
 | 
|---|
| 185 |    void releaseAllResources();
 | 
|---|
| 186 | 
 | 
|---|
| 187 |    BOOL registerResources();
 | 
|---|
| 188 | 
 | 
|---|
| 189 |    inline ULONG getBusNr()         { return busnr; };
 | 
|---|
| 190 |    inline ULONG getDeviceNr()      { return devnr; };
 | 
|---|
| 191 |    inline ULONG getFunctionNr()    { return funcnr; };
 | 
|---|
| 192 |    inline ULONG getDevFuncNr()     { return devfn; };
 | 
|---|
| 193 | 
 | 
|---|
| 194 |  private:
 | 
|---|
| 195 | 
 | 
|---|
| 196 |    //--- Private data
 | 
|---|
| 197 | 
 | 
|---|
| 198 |    RMObjectState _state;   // Current state of object, as enumerated above.
 | 
|---|
| 199 | 
 | 
|---|
| 200 |    BOOL  _rmDetection;     // TRUE if OS/2 RM detection services available.
 | 
|---|
| 201 | 
 | 
|---|
| 202 |    //--- Private methods
 | 
|---|
| 203 | 
 | 
|---|
| 204 |    BOOL _pahRMAllocDetectedResources();
 | 
|---|
| 205 | 
 | 
|---|
| 206 |    APIRET _rmCreateAdapter();
 | 
|---|
| 207 |    APIRET _rmCreateDevice( char *lpszDeviceName );
 | 
|---|
| 208 | 
 | 
|---|
| 209 |    BOOL   isPartOfAllocatedResources(int type, ULONG ulBase, ULONG ulLength);
 | 
|---|
| 210 | 
 | 
|---|
| 211 |    int    getPCIConfiguration(ULONG pciId, int idx);
 | 
|---|
| 212 |    void   pci_write_config_dword(ULONG where, ULONG value);
 | 
|---|
| 213 |    void   pci_read_config_dword(ULONG where, ULONG *pValue);
 | 
|---|
| 214 | 
 | 
|---|
| 215 |    ULONG          PCIConfig[64];
 | 
|---|
| 216 |    PCIConfigData *pciConfigData;
 | 
|---|
| 217 |    ULONG          busnr, devfn, devnr, funcnr;
 | 
|---|
| 218 | 
 | 
|---|
| 219 |    HRESOURCE      hResource[MAX_ResourceCount];
 | 
|---|
| 220 |    int            idxRes;
 | 
|---|
| 221 | 
 | 
|---|
| 222 |    DEVID          DevID;
 | 
|---|
| 223 | 
 | 
|---|
| 224 |    LDev_Resources detectedResources;
 | 
|---|
| 225 |    LDev_Resources resources;
 | 
|---|
| 226 | 
 | 
|---|
| 227 | static HDRIVER    _hDriver;    // Handle for our driver - assigned to us by RM.
 | 
|---|
| 228 | static HADAPTER   _hAdapter;   // Handle for our adapter - output from RM.
 | 
|---|
| 229 | 
 | 
|---|
| 230 | };
 | 
|---|
| 231 | 
 | 
|---|
| 232 | extern ResourceManager* pRM;               // Resource manager object.
 | 
|---|
| 233 | 
 | 
|---|
| 234 | 
 | 
|---|
| 235 | // definitions for 16 bits resource manager buffers
 | 
|---|
| 236 | // (also in startup.inc!!)
 | 
|---|
| 237 | #define MAXSIZE_RMNodeData      1024
 | 
|---|
| 238 | #define MAXSIZE_RMResources     128
 | 
|---|
| 239 | #define MAXSIZE_RMHandleList    128
 | 
|---|
| 240 | #define MAXSIZE_RMResourceList  256
 | 
|---|
| 241 | 
 | 
|---|
| 242 | #endif  /* RM_HPP */
 | 
|---|
| 243 | 
 | 
|---|