source: cmedia/trunk/Drv16/rm.hpp

Last change on this file was 354, checked in by stevenhl, 18 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 8.6 KB
RevLine 
[354]1/* $Id: rm.hpp,v 1.3 2001/04/30 21:07:58 sandervl Exp $ */
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.
43extern "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
50extern "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
85typedef 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
111// ULONG Bar0Extent;
112// ULONG Bar1Extent;
113} PCIConfigData;
114
115
116// This value indicates an empty entry in an LDev_Resource data item.
117const USHORT NoIOValue = 0xffff;
118
119class LDev_Resources { // A class to hold the collection of resources
120 // needed by a single logical device.
121 public:
122
123 /* Public data. Any unused data member is set to all 0xF. Arrays are
124 * always initialized to all 0xF's, then filled in in order, from 0..N.
125 */
126 USHORT uIOBase[ MAX_ISA_Dev_IO ];
127 USHORT uIOLength[ MAX_ISA_Dev_IO ];
128//Rudi:
129 USHORT uIOFlags[ MAX_ISA_Dev_IO ];
130 USHORT uIRQPin[ MAX_ISA_Dev_IRQ ];
131
132 USHORT uIRQLevel[ MAX_ISA_Dev_IRQ ];
133 USHORT uDMAChannel[ MAX_ISA_Dev_DMA ];
134 ULONG uMemBase[ MAX_ISA_Dev_MEM ];
135 ULONG uMemLength[ MAX_ISA_Dev_MEM ];
136
137 /* Information available from RM interface but not used:
138 * For all: Flags (Exclusive, Multiplexed, Shared, Grant-Yield)
139 * IO: IOAddressLines (10 or 16)
140 * IRQ: PCI Irq Pin (10 or 16)
141 * DMA: (Flags only)
142 * Memory: Base, Length
143 */
144
145 // Are there any values in this structure?
146 BOOL isEmpty ( void );
147
148 // Clear the structure (set all fields to "NoIOValue".
149 void vClear ( void );
150};
151
152
153/*
154 * --- ResourceManager class.
155 */
156
157enum RMObjectState { rmDriverCreated, rmDriverFailed, rmAdapterCreated, rmAdapterFailed, rmAllocFailed };
158
159class ResourceManager { // A class to encapsulate system resource
160 // allocation issues. Ref. documentation
161 public: // at bottom of file.
162
163 ResourceManager ( ULONG pciId );
164 // Register the device driver (this activates the RM interface).
165 // Intention is that only one ResourceManager object is created
166 // in driver, which will handle all audio.
167
168 bool bIsDevDetected ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice);
169 // Return an indicator of whether or not named device is present.
170 // in: - PnP Device ID, compressed ASCII.
171 // - Search flags, ref rmbase.h SEARCH_ID_*; also documented
172 // as SearchFlags parm in PDD RM API RMDevIDToHandleList().
173 // Only one of the search flags can be selected.
174 // out: True iff at least one device is detected
175 // rem: It's expected that the 1st parm, the PnP DevID, will
176 // be a DEVICE ID and the
177
178 //###
179 LDev_Resources* GetRMDetectedResources ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice, bool fJoystick );
180
181 LDev_Resources* pGetDevResources ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice, bool fJoystick = FALSE);
182
183 inline RMObjectState getState() { return _state; };
184 // Return state of RM object.
185
186 inline USHORT getResourceType() { return _restype; };
187
188 private:
189
190 //--- Private data
191
192 RMObjectState _state; // Current state of object, as enumerated above.
193
194 USHORT _restype; // resource type in case of failure
195
196 BOOL _rmDetection; // TRUE if OS/2 RM detection services available.
197
198 HDRIVER _hDriver; // Handle for our driver - assigned to us by RM.
199
200 HADAPTER _hAdapter; // Handle for our adapter - output from RM.
201 // ### This will need to be an array & associated
202 // ### w/PnP ID's to handle mult adapters.
203
204 //--- Private methods
205
206 // Converts an LDevResource structure into an RESOURCELIST.
207 NPRESOURCELIST _makeResourceList( const LDev_Resources& resources );
208
209 NPHANDLELIST _DevIDToHandleList ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice);
210 // Search the Resource Manager's "current detected" tree for
211 // the specified PnP ID, and return all matching RM handles.
212
213 NPRM_GETNODE_DATA _RMHandleToNodeData ( RMHANDLE rmHandle );
214 // Return the list of resources requested by the device
215 // or logical device represented by the resource manager handle.
216
217 NPRM_GETNODE_DATA _DevIDToNodeData( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice );
218 // Composes functions _DevIDToHandleList + _RMHandleToNodeData
219
220 NPAHRESOURCE _pahRMAllocResources( NPRESOURCELIST pResourceList );
221
222 APIRET _rmCreateAdapter();
223
224 APIRET _rmCreateDevice( PSZ pszName, USHORT usType, NPAHRESOURCE pahResource );
225
226 BOOL getPCIConfiguration(ULONG pciId);
227
228 union
229 {
230 ULONG PCIConfigArray[64];
231 PCIConfigData PCIConfig;
232 };
233};
234
235#endif /* RM_HPP */
236
Note: See TracBrowser for help on using the repository browser.