]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/InternalIsaBus.h
ISA Bus driver code scrub.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaBusDxe / InternalIsaBus.h
1 /**@file
2 The header file for ISA bus driver
3
4 Copyright (c) 2006 - 2009, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _INTERNAL_ISA_BUS_H_
16 #define _INTERNAL_ISA_BUS_H_
17
18
19 #include <PiDxe.h>
20 #include <FrameworkDxe.h>
21
22 #include <Protocol/PciIo.h>
23 #include <Protocol/ComponentName.h>
24 #include <Protocol/IsaIo.h>
25 #include <Protocol/DevicePath.h>
26 #include <Protocol/IsaAcpi.h>
27 #include <Protocol/DriverBinding.h>
28 #include <Protocol/GenericMemoryTest.h>
29 #include <Guid/StatusCodeDataTypeId.h>
30
31 #include <Library/DebugLib.h>
32 #include <Library/UefiDriverEntryPoint.h>
33 #include <Library/UefiLib.h>
34 #include <Library/DevicePathLib.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Library/UefiBootServicesTableLib.h>
38 #include <Library/ReportStatusCodeLib.h>
39 #include <Library/PcdLib.h>
40
41 #include "ComponentName.h"
42
43 //
44 // 8237 DMA registers
45 //
46 #define R_8237_DMA_BASE_CA_CH0 0x00
47 #define R_8237_DMA_BASE_CA_CH1 0x02
48 #define R_8237_DMA_BASE_CA_CH2 0x04
49 #define R_8237_DMA_BASE_CA_CH3 0xd6
50 #define R_8237_DMA_BASE_CA_CH5 0xc4
51 #define R_8237_DMA_BASE_CA_CH6 0xc8
52 #define R_8237_DMA_BASE_CA_CH7 0xcc
53
54 #define R_8237_DMA_BASE_CC_CH0 0x01
55 #define R_8237_DMA_BASE_CC_CH1 0x03
56 #define R_8237_DMA_BASE_CC_CH2 0x05
57 #define R_8237_DMA_BASE_CC_CH3 0xd7
58 #define R_8237_DMA_BASE_CC_CH5 0xc6
59 #define R_8237_DMA_BASE_CC_CH6 0xca
60 #define R_8237_DMA_BASE_CC_CH7 0xce
61
62 #define R_8237_DMA_MEM_LP_CH0 0x87
63 #define R_8237_DMA_MEM_LP_CH1 0x83
64 #define R_8237_DMA_MEM_LP_CH2 0x81
65 #define R_8237_DMA_MEM_LP_CH3 0x82
66 #define R_8237_DMA_MEM_LP_CH5 0x8B
67 #define R_8237_DMA_MEM_LP_CH6 0x89
68 #define R_8237_DMA_MEM_LP_CH7 0x8A
69
70
71 #define R_8237_DMA_COMMAND_CH0_3 0x08
72 #define R_8237_DMA_COMMAND_CH4_7 0xd0
73 #define B_8237_DMA_COMMAND_GAP 0x10
74 #define B_8237_DMA_COMMAND_CGE 0x04
75
76
77 #define R_8237_DMA_STA_CH0_3 0xd8
78 #define R_8237_DMA_STA_CH4_7 0xd0
79
80 #define R_8237_DMA_WRSMSK_CH0_3 0x0a
81 #define R_8237_DMA_WRSMSK_CH4_7 0xd4
82 #define B_8237_DMA_WRSMSK_CMS 0x04
83
84
85 #define R_8237_DMA_CHMODE_CH0_3 0x0b
86 #define R_8237_DMA_CHMODE_CH4_7 0xd6
87 #define V_8237_DMA_CHMODE_DEMAND 0x00
88 #define V_8237_DMA_CHMODE_SINGLE 0x40
89 #define V_8237_DMA_CHMODE_CASCADE 0xc0
90 #define B_8237_DMA_CHMODE_DECREMENT 0x20
91 #define B_8237_DMA_CHMODE_INCREMENT 0x00
92 #define B_8237_DMA_CHMODE_AE 0x10
93 #define V_8237_DMA_CHMODE_VERIFY 0
94 #define V_8237_DMA_CHMODE_IO2MEM 0x04
95 #define V_8237_DMA_CHMODE_MEM2IO 0x08
96
97 #define R_8237_DMA_CBPR_CH0_3 0x0c
98 #define R_8237_DMA_CBPR_CH4_7 0xd8
99
100 #define R_8237_DMA_MCR_CH0_3 0x0d
101 #define R_8237_DMA_MCR_CH4_7 0xda
102
103 #define R_8237_DMA_CLMSK_CH0_3 0x0e
104 #define R_8237_DMA_CLMSK_CH4_7 0xdc
105
106 #define R_8237_DMA_WRMSK_CH0_3 0x0f
107 #define R_8237_DMA_WRMSK_CH4_7 0xde
108
109 typedef enum {
110 IsaAccessTypeUnknown,
111 IsaAccessTypeIo,
112 IsaAccessTypeMem,
113 IsaAccessTypeMaxType
114 } ISA_ACCESS_TYPE;
115
116 //
117 // 16 MB Memory Range
118 //
119 #define ISA_MAX_MEMORY_ADDRESS 0x1000000
120 //
121 // 64K I/O Range
122 //
123 #define ISA_MAX_IO_ADDRESS 0x10000
124
125 typedef struct {
126 UINT8 Address;
127 UINT8 Page;
128 UINT8 Count;
129 } EFI_ISA_DMA_REGISTERS;
130
131 //
132 // ISA I/O Device Structure
133 //
134 #define ISA_IO_DEVICE_SIGNATURE SIGNATURE_32 ('i', 's', 'a', 'i')
135
136 typedef struct {
137 UINT32 Signature;
138 EFI_HANDLE Handle;
139 EFI_ISA_IO_PROTOCOL IsaIo;
140 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
141 EFI_PCI_IO_PROTOCOL *PciIo;
142 } ISA_IO_DEVICE;
143
144 #define ISA_IO_DEVICE_FROM_ISA_IO_THIS(a) CR (a, ISA_IO_DEVICE, IsaIo, ISA_IO_DEVICE_SIGNATURE)
145
146 //
147 // Mapping structure for performing ISA DMA to a buffer above 16 MB
148 //
149 typedef struct {
150 EFI_ISA_IO_PROTOCOL_OPERATION Operation;
151 UINTN NumberOfBytes;
152 UINTN NumberOfPages;
153 EFI_PHYSICAL_ADDRESS HostAddress;
154 EFI_PHYSICAL_ADDRESS MappedHostAddress;
155 } ISA_MAP_INFO;
156
157 //
158 // EFI Driver Binding Protocol Interface Functions
159 //
160
161 /**
162 Tests to see if a controller can be managed by the ISA Bus Driver. If a child device is provided,
163 it further tests to see if this driver supports creating a handle for the specified child device.
164
165 Note that the ISA Bus driver always creates all of its child handles on the first call to Start().
166 How the Start() function of a driver is implemented can affect how the Supported() function is implemented.
167
168 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
169 @param[in] Controller The handle of the controller to test.
170 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
171
172 @retval EFI_SUCCESS The device is supported by this driver.
173 @retval EFI_ALREADY_STARTED The device is already being managed by this driver.
174 @retval EFI_ACCESS_DENIED The device is already being managed by a different driver
175 or an application that requires exclusive access.
176 @retval EFI_UNSUPPORTED The device is is not supported by this driver.
177
178 **/
179 EFI_STATUS
180 EFIAPI
181 IsaBusControllerDriverSupported (
182 IN EFI_DRIVER_BINDING_PROTOCOL * This,
183 IN EFI_HANDLE Controller,
184 IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
185 );
186
187 /**
188 Start this driver on ControllerHandle.
189
190 Note that the ISA Bus driver always creates all of its child handles on the first call to Start().
191 The Start() function is designed to be invoked from the EFI boot service ConnectController().
192 As a result, much of the error checking on the parameters to Start() has been moved into this
193 common boot service. It is legal to call Start() from other locations, but the following calling
194 restrictions must be followed or the system behavior will not be deterministic.
195 1. ControllerHandle must be a valid EFI_HANDLE.
196 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
197 EFI_DEVICE_PATH_PROTOCOL.
198 3. Prior to calling Start(), the Supported() function for the driver specified by This must
199 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
200
201 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
202 @param[in] ControllerHandle The handle of the controller to start. This handle
203 must support a protocol interface that supplies
204 an I/O abstraction to the driver.
205 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
206 This parameter is ignored by device drivers, and is optional for bus drivers.
207
208 @retval EFI_SUCCESS The device was started.
209 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.
210 Currently not implemented.
211 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
212 @retval Others The driver failded to start the device.
213 **/
214 EFI_STATUS
215 EFIAPI
216 IsaBusControllerDriverStart (
217 IN EFI_DRIVER_BINDING_PROTOCOL * This,
218 IN EFI_HANDLE Controller,
219 IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL
220 );
221
222 /**
223 Stop this driver on ControllerHandle.
224
225 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
226 As a result, much of the error checking on the parameters to Stop() has been moved
227 into this common boot service. It is legal to call Stop() from other locations,
228 but the following calling restrictions must be followed or the system behavior will not be deterministic.
229 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
230 same driver's Start() function.
231 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
232 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
233 Start() function, and the Start() function must have called OpenProtocol() on
234 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
235
236 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
237 @param[in] ControllerHandle A handle to the device being stopped. The handle must
238 support a bus specific I/O protocol for the driver
239 to use to stop the device.
240 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
241 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
242 if NumberOfChildren is 0.
243
244 @retval EFI_SUCCESS The device was stopped.
245 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
246 **/
247 EFI_STATUS
248 EFIAPI
249 IsaBusControllerDriverStop (
250 IN EFI_DRIVER_BINDING_PROTOCOL * This,
251 IN EFI_HANDLE Controller,
252 IN UINTN NumberOfChildren,
253 IN EFI_HANDLE * ChildHandleBuffer OPTIONAL
254 );
255
256 //
257 // Function Prototypes
258 //
259
260 /**
261 Create EFI Handle for a ISA device found via ISA ACPI Protocol
262
263 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance.
264 @param[in] Controller The handle of ISA bus controller(PCI to ISA bridge)
265 @param[in] PciIo The Pointer to the PCI protocol
266 @param[in] ParentDevicePath Device path of the ISA bus controller
267 @param[in] IsaDeviceResourceList The resource list of the ISA device
268 @param[in] ChildDevicePath The pointer to the child device.
269
270 @retval EFI_SUCCESS The handle for the child device was created.
271 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
272 @retval EFI_DEVICE_ERROR The handle for the child device can not be created.
273 **/
274 EFI_STATUS
275 IsaCreateDevice (
276 IN EFI_DRIVER_BINDING_PROTOCOL *This,
277 IN EFI_HANDLE Controller,
278 IN EFI_PCI_IO_PROTOCOL *PciIo,
279 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,
280 IN EFI_ISA_ACPI_RESOURCE_LIST *IsaDeviceResourceList,
281 OUT EFI_DEVICE_PATH_PROTOCOL **ChildDevicePath
282 );
283
284 /**
285 Initializes an ISA I/O Instance
286
287 @param[in] IsaIoDevice The iso device to be initialized.
288 @param[in] IsaDeviceResourceList The resource list.
289
290 @retval None
291 **/
292 VOID
293 InitializeIsaIoInstance (
294 IN ISA_IO_DEVICE *IsaIoDevice,
295 IN EFI_ISA_ACPI_RESOURCE_LIST *IsaDevice
296 );
297
298 #endif
299