1 | /* $Id: rm.hpp 151 2000-05-28 16:50:46Z sandervl $ */
|
---|
2 |
|
---|
3 | /* SCCSID = %W% %E% */
|
---|
4 | /****************************************************************************
|
---|
5 | * *
|
---|
6 | * Copyright (c) IBM Corporation 1994 - 1997. *
|
---|
7 | * *
|
---|
8 | * The following IBM OS/2 source code is provided to you solely for the *
|
---|
9 | * the purpose of assisting you in your development of OS/2 device drivers. *
|
---|
10 | * You may use this code in accordance with the IBM License Agreement *
|
---|
11 | * provided in the IBM Device Driver Source Kit for OS/2. *
|
---|
12 | * *
|
---|
13 | ****************************************************************************/
|
---|
14 | /**@internal %W%
|
---|
15 | * ResourceManager and LDev_Resources class definitions.
|
---|
16 | * @version %I%
|
---|
17 | * @context
|
---|
18 | * Unless otherwise noted, all interfaces are Ring-3, 16-bit, sysinit time
|
---|
19 | * execution context on the kernel stack.
|
---|
20 | * @notes
|
---|
21 | * The client of this object should query for their adapters and logical
|
---|
22 | * devices, and associated resources. If the detected logical devices have
|
---|
23 | * sufficient resources, then allocate those resources.
|
---|
24 | *
|
---|
25 | * Provides information to the audio driver on the detected devices and the
|
---|
26 | * resources required for device operation. Obtain required resources from
|
---|
27 | * Resource Manager as directed by the client of this object. The adapters
|
---|
28 | * and controllers will be owned by this driver. The detected resources
|
---|
29 | * that will be operated are normally reallocated as driver resources. This
|
---|
30 | * code is dumped after driver initialization is complete.
|
---|
31 | *
|
---|
32 | * @notes
|
---|
33 | * *. Component design documentation at bottom of file.
|
---|
34 | * *. PnP Device ID's are always in Compressed Ascii format.
|
---|
35 | * @history
|
---|
36 | */
|
---|
37 |
|
---|
38 |
|
---|
39 | #ifndef RM_HPP // Skip this file if already included.
|
---|
40 | #define RM_HPP
|
---|
41 |
|
---|
42 | #ifndef OS2_INCLUDED // Doesn't like being included twice.
|
---|
43 | extern "C" { // 16-bit header files are not C++ aware
|
---|
44 | #define INCL_NOPMAPI
|
---|
45 | #define INCL_DOSINFOSEG // Need Global info seg in rm.cpp algorithms
|
---|
46 | #include <os2.h>
|
---|
47 | }
|
---|
48 | #endif // end OS2_INCLUDED
|
---|
49 |
|
---|
50 | extern "C" {
|
---|
51 | #include <rmbase.h> // Resource manager definitions.
|
---|
52 | #include <rmcalls.h>
|
---|
53 | #include <rmioctl.h>
|
---|
54 | }
|
---|
55 |
|
---|
56 | #include <include.h> // Defn's for WatCom based drivers.
|
---|
57 | #include "sizedefs.h" // NumLogicalDevices
|
---|
58 |
|
---|
59 | #define MAX_DevID 1 // Maximum number of devices with a particular
|
---|
60 | // PnP Device ID that we're prepared to deal with.
|
---|
61 | // Intention is that this defines the number of
|
---|
62 | // adapters we're prepared to deal with.
|
---|
63 | #define MAX_DescTextLen MAX_TEXT_DATA
|
---|
64 | // MAX_TEXT_DATA in rmioctl.h. Max length
|
---|
65 | // of the descriptive text on any of the free
|
---|
66 | // ASCIIZ fields in the RM structures.
|
---|
67 |
|
---|
68 |
|
---|
69 |
|
---|
70 | /*
|
---|
71 | * --- LDev_Resources class.
|
---|
72 | */
|
---|
73 |
|
---|
74 | /* These "maximums" for number of I/O, IRQ, etc. per logical device, are defined
|
---|
75 | by PnP ISA spec Ver 1.0a 5/5/94, sect 4.6, p. 20. */
|
---|
76 |
|
---|
77 | #define MAX_ISA_Dev_IO 8
|
---|
78 | #define MAX_ISA_Dev_IRQ 2
|
---|
79 | #define MAX_ISA_Dev_DMA 2
|
---|
80 | #define MAX_ISA_Dev_MEM 4
|
---|
81 | #define MAX_ResourceCount ( MAX_ISA_Dev_IO + MAX_ISA_Dev_IRQ \
|
---|
82 | + MAX_ISA_Dev_DMA + MAX_ISA_Dev_MEM )
|
---|
83 |
|
---|
84 |
|
---|
85 | typedef struct
|
---|
86 | {
|
---|
87 | USHORT VendorID;
|
---|
88 | USHORT DeviceID;
|
---|
89 | USHORT Command;
|
---|
90 | USHORT Status;
|
---|
91 | UCHAR RevisionID;
|
---|
92 | UCHAR filler1[7];
|
---|
93 | ULONG Bar0;
|
---|
94 | ULONG Bar1;
|
---|
95 | ULONG filler2[5];
|
---|
96 | USHORT SubsystemVendorID;
|
---|
97 | USHORT SubsystemID;
|
---|
98 | ULONG filler3[3];
|
---|
99 | UCHAR InterruptLine;
|
---|
100 | UCHAR InterruptPin;
|
---|
101 | UCHAR Max_Gnt;
|
---|
102 | UCHAR Max_Lat;
|
---|
103 | UCHAR TRDY_Timeout;
|
---|
104 | UCHAR Retry_Timeout;
|
---|
105 | UCHAR filler4[0x9a];
|
---|
106 | UCHAR CapabilityID;
|
---|
107 | UCHAR NextItemPtr;
|
---|
108 | USHORT PowerMgtCapability;
|
---|
109 | USHORT PowerMgtCSR;
|
---|
110 | } PCIConfigData;
|
---|
111 |
|
---|
112 | // This value indicates an empty entry in an LDev_Resource data item.
|
---|
113 | const USHORT NoIOValue = 0xffff;
|
---|
114 |
|
---|
115 | class LDev_Resources { // A class to hold the collection of resources
|
---|
116 | // needed by a single logical device.
|
---|
117 | public:
|
---|
118 |
|
---|
119 | /* Public data. Any unused data member is set to all 0xF. Arrays are
|
---|
120 | * always initialized to all 0xF's, then filled in in order, from 0..N.
|
---|
121 | */
|
---|
122 | USHORT uIOBase[ MAX_ISA_Dev_IO ];
|
---|
123 | USHORT uIOLength[ MAX_ISA_Dev_IO ];
|
---|
124 | USHORT uIRQLevel[ MAX_ISA_Dev_IRQ ];
|
---|
125 | USHORT uDMAChannel[ MAX_ISA_Dev_DMA ];
|
---|
126 | ULONG uMemBase[ MAX_ISA_Dev_MEM ];
|
---|
127 | ULONG uMemLength[ MAX_ISA_Dev_MEM ];
|
---|
128 |
|
---|
129 | /* Information available from RM interface but not used:
|
---|
130 | * For all: Flags (Exclusive, Multiplexed, Shared, Grant-Yield)
|
---|
131 | * IO: IOAddressLines (10 or 16)
|
---|
132 | * IRQ: PCI Irq Pin (10 or 16)
|
---|
133 | * DMA: (Flags only)
|
---|
134 | * Memory: Base, Length
|
---|
135 | */
|
---|
136 |
|
---|
137 | // Are there any values in this structure?
|
---|
138 | BOOL isEmpty ( void );
|
---|
139 |
|
---|
140 | // Clear the structure (set all fields to "NoIOValue".
|
---|
141 | void vClear ( void );
|
---|
142 | };
|
---|
143 |
|
---|
144 |
|
---|
145 | /*
|
---|
146 | * --- ResourceManager class.
|
---|
147 | */
|
---|
148 |
|
---|
149 | enum RMObjectState { rmDriverCreated, rmDriverFailed, rmAdapterCreated, rmAdapterFailed };
|
---|
150 |
|
---|
151 | class ResourceManager { // A class to encapsulate system resource
|
---|
152 | // allocation issues. Ref. documentation
|
---|
153 | public: // at bottom of file.
|
---|
154 |
|
---|
155 | ResourceManager ( ULONG pciId );
|
---|
156 | // Register the device driver (this activates the RM interface).
|
---|
157 | // Intention is that only one ResourceManager object is created
|
---|
158 | // in driver, which will handle all audio.
|
---|
159 |
|
---|
160 | bool bIsDevDetected ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice);
|
---|
161 | // Return an indicator of whether or not named device is present.
|
---|
162 | // in: - PnP Device ID, compressed ASCII.
|
---|
163 | // - Search flags, ref rmbase.h SEARCH_ID_*; also documented
|
---|
164 | // as SearchFlags parm in PDD RM API RMDevIDToHandleList().
|
---|
165 | // Only one of the search flags can be selected.
|
---|
166 | // out: True iff at least one device is detected
|
---|
167 | // rem: It's expected that the 1st parm, the PnP DevID, will
|
---|
168 | // be a DEVICE ID and the
|
---|
169 |
|
---|
170 | //###
|
---|
171 | LDev_Resources* GetRMDetectedResources ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice );
|
---|
172 |
|
---|
173 | LDev_Resources* pGetDevResources ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice);
|
---|
174 |
|
---|
175 | inline RMObjectState getState() { return _state; };
|
---|
176 | // Return state of RM object.
|
---|
177 |
|
---|
178 | private:
|
---|
179 |
|
---|
180 | //--- Private data
|
---|
181 |
|
---|
182 | RMObjectState _state; // Current state of object, as enumerated above.
|
---|
183 |
|
---|
184 | BOOL _rmDetection; // TRUE if OS/2 RM detection services available.
|
---|
185 |
|
---|
186 | HDRIVER _hDriver; // Handle for our driver - assigned to us by RM.
|
---|
187 |
|
---|
188 | HADAPTER _hAdapter; // Handle for our adapter - output from RM.
|
---|
189 | // ### This will need to be an array & associated
|
---|
190 | // ### w/PnP ID's to handle mult adapters.
|
---|
191 |
|
---|
192 | //--- Private methods
|
---|
193 |
|
---|
194 | // Converts an LDevResource structure into an RESOURCELIST.
|
---|
195 | NPRESOURCELIST _makeResourceList( const LDev_Resources& resources );
|
---|
196 |
|
---|
197 | NPHANDLELIST _DevIDToHandleList ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice);
|
---|
198 | // Search the Resource Manager's "current detected" tree for
|
---|
199 | // the specified PnP ID, and return all matching RM handles.
|
---|
200 |
|
---|
201 | NPRM_GETNODE_DATA _RMHandleToNodeData ( RMHANDLE rmHandle );
|
---|
202 | // Return the list of resources requested by the device
|
---|
203 | // or logical device represented by the resource manager handle.
|
---|
204 |
|
---|
205 | NPRM_GETNODE_DATA _DevIDToNodeData( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice );
|
---|
206 | // Composes functions _DevIDToHandleList + _RMHandleToNodeData
|
---|
207 |
|
---|
208 | NPAHRESOURCE _pahRMAllocResources( NPRESOURCELIST pResourceList );
|
---|
209 |
|
---|
210 | APIRET _rmCreateAdapter();
|
---|
211 |
|
---|
212 | APIRET _rmCreateDevice( PSZ pszName, NPAHRESOURCE pahResource );
|
---|
213 |
|
---|
214 | BOOL getPCIConfiguration(ULONG pciId);
|
---|
215 |
|
---|
216 | ULONG PCIConfig[64];
|
---|
217 | PCIConfigData *pciConfigData;
|
---|
218 |
|
---|
219 | };
|
---|
220 |
|
---|
221 | #endif /* RM_HPP */
|
---|
222 |
|
---|