1 /** @file
2   The header file for ISA driver
3 
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 
7 **/
8 
9 #ifndef _ISA_DRIVER_H_
10 #define _ISA_DRIVER_H_
11 
12 
13 #include <Uefi.h>
14 
15 #include <Protocol/PciIo.h>
16 #include <Protocol/SuperIo.h>
17 #include <Protocol/ComponentName.h>
18 #include <Protocol/IsaIo.h>
19 #include <Protocol/DevicePath.h>
20 #include <Protocol/DriverBinding.h>
21 #include <Guid/StatusCodeDataTypeId.h>
22 
23 #include <Library/DebugLib.h>
24 #include <Library/UefiDriverEntryPoint.h>
25 #include <Library/UefiLib.h>
26 #include <Library/DevicePathLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/MemoryAllocationLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/ReportStatusCodeLib.h>
31 #include <Library/PcdLib.h>
32 #include <IndustryStandard/Acpi.h>
33 
34 #include "ComponentName.h"
35 
36 //
37 // 8237 DMA registers
38 //
39 #define R_8237_DMA_BASE_CA_CH0                    0x00
40 #define R_8237_DMA_BASE_CA_CH1                    0x02
41 #define R_8237_DMA_BASE_CA_CH2                    0x04
42 #define R_8237_DMA_BASE_CA_CH3                    0xd6
43 #define R_8237_DMA_BASE_CA_CH5                    0xc4
44 #define R_8237_DMA_BASE_CA_CH6                    0xc8
45 #define R_8237_DMA_BASE_CA_CH7                    0xcc
46 
47 #define R_8237_DMA_BASE_CC_CH0                    0x01
48 #define R_8237_DMA_BASE_CC_CH1                    0x03
49 #define R_8237_DMA_BASE_CC_CH2                    0x05
50 #define R_8237_DMA_BASE_CC_CH3                    0xd7
51 #define R_8237_DMA_BASE_CC_CH5                    0xc6
52 #define R_8237_DMA_BASE_CC_CH6                    0xca
53 #define R_8237_DMA_BASE_CC_CH7                    0xce
54 
55 #define R_8237_DMA_MEM_LP_CH0                     0x87
56 #define R_8237_DMA_MEM_LP_CH1                     0x83
57 #define R_8237_DMA_MEM_LP_CH2                     0x81
58 #define R_8237_DMA_MEM_LP_CH3                     0x82
59 #define R_8237_DMA_MEM_LP_CH5                     0x8B
60 #define R_8237_DMA_MEM_LP_CH6                     0x89
61 #define R_8237_DMA_MEM_LP_CH7                     0x8A
62 
63 
64 #define R_8237_DMA_COMMAND_CH0_3                  0x08
65 #define R_8237_DMA_COMMAND_CH4_7                  0xd0
66 #define   B_8237_DMA_COMMAND_GAP                  0x10
67 #define   B_8237_DMA_COMMAND_CGE                  0x04
68 
69 
70 #define R_8237_DMA_STA_CH0_3                      0xd8
71 #define R_8237_DMA_STA_CH4_7                      0xd0
72 
73 #define R_8237_DMA_WRSMSK_CH0_3                   0x0a
74 #define R_8237_DMA_WRSMSK_CH4_7                   0xd4
75 #define   B_8237_DMA_WRSMSK_CMS                   0x04
76 
77 
78 #define R_8237_DMA_CHMODE_CH0_3                   0x0b
79 #define R_8237_DMA_CHMODE_CH4_7                   0xd6
80 #define   V_8237_DMA_CHMODE_DEMAND                0x00
81 #define   V_8237_DMA_CHMODE_SINGLE                0x40
82 #define   V_8237_DMA_CHMODE_CASCADE               0xc0
83 #define   B_8237_DMA_CHMODE_DECREMENT             0x20
84 #define   B_8237_DMA_CHMODE_INCREMENT             0x00
85 #define   B_8237_DMA_CHMODE_AE                    0x10
86 #define   V_8237_DMA_CHMODE_VERIFY                0
87 #define   V_8237_DMA_CHMODE_IO2MEM                0x04
88 #define   V_8237_DMA_CHMODE_MEM2IO                0x08
89 
90 #define R_8237_DMA_CBPR_CH0_3                     0x0c
91 #define R_8237_DMA_CBPR_CH4_7                     0xd8
92 
93 #define R_8237_DMA_MCR_CH0_3                      0x0d
94 #define R_8237_DMA_MCR_CH4_7                      0xda
95 
96 #define R_8237_DMA_CLMSK_CH0_3                    0x0e
97 #define R_8237_DMA_CLMSK_CH4_7                    0xdc
98 
99 #define R_8237_DMA_WRMSK_CH0_3                    0x0f
100 #define R_8237_DMA_WRMSK_CH4_7                    0xde
101 
102 typedef enum {
103   IsaAccessTypeUnknown,
104   IsaAccessTypeIo,
105   IsaAccessTypeMem,
106   IsaAccessTypeMaxType
107 } ISA_ACCESS_TYPE;
108 
109 typedef struct {
110   UINT8 Address;
111   UINT8 Page;
112   UINT8 Count;
113 } EFI_ISA_DMA_REGISTERS;
114 
115 //
116 // ISA I/O Device Structure
117 //
118 #define ISA_IO_DEVICE_SIGNATURE SIGNATURE_32 ('i', 's', 'a', 'i')
119 
120 typedef struct {
121   UINT32                                    Signature;
122   EFI_HANDLE                                Handle;
123   EFI_ISA_IO_PROTOCOL                       IsaIo;
124   EFI_PCI_IO_PROTOCOL                       *PciIo;
125 } ISA_IO_DEVICE;
126 
127 #define ISA_IO_DEVICE_FROM_ISA_IO_THIS(a) CR (a, ISA_IO_DEVICE, IsaIo, ISA_IO_DEVICE_SIGNATURE)
128 
129 //
130 // Mapping structure for performing ISA DMA to a buffer above 16 MB
131 //
132 typedef struct {
133   EFI_ISA_IO_PROTOCOL_OPERATION Operation;
134   UINTN                         NumberOfBytes;
135   UINTN                         NumberOfPages;
136   EFI_PHYSICAL_ADDRESS          HostAddress;
137   EFI_PHYSICAL_ADDRESS          MappedHostAddress;
138 } ISA_MAP_INFO;
139 
140 //
141 // EFI Driver Binding Protocol Interface Functions
142 //
143 
144 /**
145   Tests to see if a controller can be managed by the ISA Driver.
146 
147   How the Start() function of a driver is implemented can affect how the Supported() function is implemented.
148 
149   @param[in] This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
150   @param[in] Controller           The handle of the controller to test.
151   @param[in] RemainingDevicePath  A pointer to the remaining portion of a device path.
152 
153   @retval EFI_SUCCESS             The device is supported by this driver.
154   @retval EFI_ALREADY_STARTED     The device is already being managed by this driver.
155   @retval EFI_ACCESS_DENIED       The device is already being managed by a different driver
156                                   or an application that requires exclusive access.
157   @retval EFI_UNSUPPORTED         The device is is not supported by this driver.
158 
159 **/
160 EFI_STATUS
161 EFIAPI
162 IsaIoDriverSupported (
163   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
164   IN EFI_HANDLE                   Controller,
165   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
166   );
167 
168 /**
169   Start this driver on ControllerHandle.
170 
171   The Start() function is designed to be invoked from the EFI boot service ConnectController().
172   As a result, much of the error checking on the parameters to Start() has been moved into this
173   common boot service. It is legal to call Start() from other locations, but the following calling
174   restrictions must be followed or the system behavior will not be deterministic.
175   1. ControllerHandle must be a valid EFI_HANDLE.
176   2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
177      EFI_DEVICE_PATH_PROTOCOL.
178   3. Prior to calling Start(), the Supported() function for the driver specified by This must
179      have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
180 
181   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
182   @param[in]  ControllerHandle     The handle of the controller to start. This handle
183                                    must support a protocol interface that supplies
184                                    an I/O abstraction to the driver.
185   @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.
186                                    This parameter is ignored by device drivers, and is optional for bus drivers.
187 
188   @retval EFI_SUCCESS              The device was started.
189   @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.
190                                    Currently not implemented.
191   @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.
192   @retval Others                   The driver failded to start the device.
193 **/
194 EFI_STATUS
195 EFIAPI
196 IsaIoDriverStart (
197   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
198   IN EFI_HANDLE                   Controller,
199   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
200   );
201 
202 /**
203   Stop this driver on ControllerHandle.
204 
205   The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
206   As a result, much of the error checking on the parameters to Stop() has been moved
207   into this common boot service. It is legal to call Stop() from other locations,
208   but the following calling restrictions must be followed or the system behavior will not be deterministic.
209   1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
210      same driver's Start() function.
211   2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
212      EFI_HANDLE. In addition, all of these handles must have been created in this driver's
213      Start() function, and the Start() function must have called OpenProtocol() on
214      ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
215 
216   @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
217   @param[in]  ControllerHandle  A handle to the device being stopped. The handle must
218                                 support a bus specific I/O protocol for the driver
219                                 to use to stop the device.
220   @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.
221   @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL
222                                 if NumberOfChildren is 0.
223 
224   @retval EFI_SUCCESS           The device was stopped.
225   @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.
226 **/
227 EFI_STATUS
228 EFIAPI
229 IsaIoDriverStop (
230   IN  EFI_DRIVER_BINDING_PROTOCOL  * This,
231   IN  EFI_HANDLE                   Controller,
232   IN  UINTN                        NumberOfChildren,
233   IN  EFI_HANDLE                   * ChildHandleBuffer OPTIONAL
234   );
235 
236 //
237 // Function Prototypes
238 //
239 
240 /**
241   Initializes an ISA I/O Instance
242 
243   @param[in] IsaIoDevice            The isa device to be initialized.
244   @param[in] DevicePath             The device path of the isa device.
245   @param[in] Resources              The ACPI resource list.
246 
247 **/
248 VOID
249 InitializeIsaIoInstance (
250   IN ISA_IO_DEVICE               *IsaIoDevice,
251   IN EFI_DEVICE_PATH_PROTOCOL    *DevicePath,
252   IN ACPI_RESOURCE_HEADER_PTR    Resources
253   );
254 
255 #endif
256 
257