1 | /* $Id: rm.hpp 142 2000-04-23 14:55:46Z ktk $ */
|
---|
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 | // This value indicates an empty entry in an LDev_Resource data item.
|
---|
86 | const USHORT NoIOValue = 0xffff;
|
---|
87 |
|
---|
88 | class LDev_Resources { // A class to hold the collection of resources
|
---|
89 | // needed by a single logical device.
|
---|
90 | public:
|
---|
91 |
|
---|
92 | /* Public data. Any unused data member is set to all 0xF. Arrays are
|
---|
93 | * always initialized to all 0xF's, then filled in in order, from 0..N.
|
---|
94 | */
|
---|
95 | USHORT uIOBase[ MAX_ISA_Dev_IO ];
|
---|
96 | USHORT uIOLength[ MAX_ISA_Dev_IO ];
|
---|
97 | USHORT uIRQLevel[ MAX_ISA_Dev_IRQ ];
|
---|
98 | USHORT uDMAChannel[ MAX_ISA_Dev_DMA ];
|
---|
99 | ULONG uMemBase[ MAX_ISA_Dev_MEM ];
|
---|
100 | ULONG uMemLength[ MAX_ISA_Dev_MEM ];
|
---|
101 |
|
---|
102 | /* Information available from RM interface but not used:
|
---|
103 | * For all: Flags (Exclusive, Multiplexed, Shared, Grant-Yield)
|
---|
104 | * IO: IOAddressLines (10 or 16)
|
---|
105 | * IRQ: PCI Irq Pin (10 or 16)
|
---|
106 | * DMA: (Flags only)
|
---|
107 | * Memory: Base, Length
|
---|
108 | */
|
---|
109 |
|
---|
110 | // Are there any values in this structure?
|
---|
111 | BOOL isEmpty ( void );
|
---|
112 |
|
---|
113 | // Clear the structure (set all fields to "NoIOValue".
|
---|
114 | void vClear ( void );
|
---|
115 | };
|
---|
116 |
|
---|
117 |
|
---|
118 | /*
|
---|
119 | * --- ResourceManager class.
|
---|
120 | */
|
---|
121 |
|
---|
122 | enum RMObjectState { rmDriverCreated, rmDriverFailed, rmAdapterCreated, rmAdapterFailed };
|
---|
123 |
|
---|
124 | class ResourceManager { // A class to encapsulate system resource
|
---|
125 | // allocation issues. Ref. documentation
|
---|
126 | public: // at bottom of file.
|
---|
127 |
|
---|
128 | ResourceManager ( void );
|
---|
129 | // Register the device driver (this activates the RM interface).
|
---|
130 | // Intention is that only one ResourceManager object is created
|
---|
131 | // in driver, which will handle all audio.
|
---|
132 |
|
---|
133 | bool bIsDevDetected ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice);
|
---|
134 | // Return an indicator of whether or not named device is present.
|
---|
135 | // in: - PnP Device ID, compressed ASCII.
|
---|
136 | // - Search flags, ref rmbase.h SEARCH_ID_*; also documented
|
---|
137 | // as SearchFlags parm in PDD RM API RMDevIDToHandleList().
|
---|
138 | // Only one of the search flags can be selected.
|
---|
139 | // out: True iff at least one device is detected
|
---|
140 | // rem: It's expected that the 1st parm, the PnP DevID, will
|
---|
141 | // be a DEVICE ID and the
|
---|
142 |
|
---|
143 | //###
|
---|
144 | LDev_Resources* GetRMDetectedResources ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice );
|
---|
145 |
|
---|
146 | LDev_Resources* pGetDevResources ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice);
|
---|
147 |
|
---|
148 | inline RMObjectState getState() { return _state; };
|
---|
149 | // Return state of RM object.
|
---|
150 |
|
---|
151 | private:
|
---|
152 |
|
---|
153 | //--- Private data
|
---|
154 |
|
---|
155 | RMObjectState _state; // Current state of object, as enumerated above.
|
---|
156 |
|
---|
157 | BOOL _rmDetection; // TRUE if OS/2 RM detection services available.
|
---|
158 |
|
---|
159 | HDRIVER _hDriver; // Handle for our driver - assigned to us by RM.
|
---|
160 |
|
---|
161 | HADAPTER _hAdapter; // Handle for our adapter - output from RM.
|
---|
162 | // ### This will need to be an array & associated
|
---|
163 | // ### w/PnP ID's to handle mult adapters.
|
---|
164 |
|
---|
165 | //--- Private methods
|
---|
166 |
|
---|
167 | // Converts an LDevResource structure into an RESOURCELIST.
|
---|
168 | NPRESOURCELIST _makeResourceList( const LDev_Resources& resources );
|
---|
169 |
|
---|
170 | NPHANDLELIST _DevIDToHandleList ( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice);
|
---|
171 | // Search the Resource Manager's "current detected" tree for
|
---|
172 | // the specified PnP ID, and return all matching RM handles.
|
---|
173 |
|
---|
174 | NPRM_GETNODE_DATA _RMHandleToNodeData ( RMHANDLE rmHandle );
|
---|
175 | // Return the list of resources requested by the device
|
---|
176 | // or logical device represented by the resource manager handle.
|
---|
177 |
|
---|
178 | NPRM_GETNODE_DATA _DevIDToNodeData( DEVID DevID , ULONG ulSearchFlags, bool fPciDevice );
|
---|
179 | // Composes functions _DevIDToHandleList + _RMHandleToNodeData
|
---|
180 |
|
---|
181 | NPAHRESOURCE _pahRMAllocResources( NPRESOURCELIST pResourceList );
|
---|
182 |
|
---|
183 | APIRET _rmCreateAdapter();
|
---|
184 |
|
---|
185 | APIRET _rmCreateDevice( PSZ pszName, NPAHRESOURCE pahResource );
|
---|
186 |
|
---|
187 | };
|
---|
188 |
|
---|
189 | #endif /* RM_HPP */
|
---|
190 |
|
---|