]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/IsaIo.c
Rename enum with a duplicate name of EVENT_LOG_TYPE_DATA.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaBusDxe / IsaIo.c
CommitLineData
f8cd287b 1/**@file\r
2 The implementation for EFI_ISA_IO_PROTOCOL. \r
c3902377 3 \r
f8cd287b 4Copyright (c) 2006 - 2007, Intel Corporation.<BR>\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
c3902377 9\r
f8cd287b 10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
c3902377 12\r
f8cd287b 13**/\r
c3902377 14\r
c3902377 15#include "InternalIsaIo.h"\r
16\r
c3902377 17//\r
18// Driver Support Global Variables\r
19//\r
20EFI_ISA_IO_PROTOCOL IsaIoInterface = {\r
21 { \r
22 IsaIoMemRead,\r
23 IsaIoMemWrite\r
24 },\r
25 { \r
26 IsaIoIoRead,\r
27 IsaIoIoWrite\r
28 },\r
29 IsaIoCopyMem,\r
30 IsaIoMap,\r
31 IsaIoUnmap,\r
32 IsaIoAllocateBuffer,\r
33 IsaIoFreeBuffer,\r
34 IsaIoFlush,\r
35 NULL,\r
36 0,\r
37 NULL\r
38};\r
39\r
819d1488 40EFI_ISA_DMA_REGISTERS DmaRegisters[8] = {\r
c3902377 41 {\r
42 0x00,\r
43 0x87,\r
44 0x01\r
45 },\r
46 {\r
47 0x02,\r
48 0x83,\r
49 0x03\r
50 },\r
51 {\r
52 0x04,\r
53 0x81,\r
54 0x05\r
55 },\r
56 {\r
57 0x06,\r
58 0x82,\r
59 0x07\r
60 },\r
61 {\r
62 0x00,\r
63 0x00,\r
64 0x00\r
65 }, // Channel 4 is invalid\r
66 {\r
67 0xC4,\r
68 0x8B,\r
69 0xC6\r
70 },\r
71 {\r
72 0xC8,\r
73 0x89,\r
74 0xCA\r
75 },\r
76 {\r
77 0xCC,\r
78 0x8A,\r
79 0xCE\r
80 },\r
81};\r
82\r
bcd70414 83/**\r
84 report a error Status code of PCI bus driver controller\r
85\r
86 @param Code - The error status code.\r
87 \r
fdb05fa3 88 @return EFI_SUCCESS - Success to report status code.\r
bcd70414 89**/\r
c3902377 90EFI_STATUS\r
91ReportErrorStatusCode (\r
92 EFI_STATUS_CODE_VALUE Code\r
93 )\r
c3902377 94\r
c3902377 95{\r
96 return REPORT_STATUS_CODE (\r
97 EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
98 Code\r
99 );\r
100}\r
101\r
102//\r
103// Driver Support Functions\r
104//\r
bcd70414 105/**\r
106\r
107 Initializes an ISA I/O Instance\r
c3902377 108\r
bcd70414 109 @param IsaIoDevice - The iso device to be initialized.\r
110 @param IsaDeviceResourceList - The resource list.\r
111 \r
112 @retval EFI_SUCCESS - Initial success.\r
113 \r
114**/\r
c3902377 115EFI_STATUS\r
116InitializeIsaIoInstance (\r
117 IN ISA_IO_DEVICE *IsaIoDevice,\r
118 IN EFI_ISA_ACPI_RESOURCE_LIST *IsaDeviceResourceList\r
119 )\r
c3902377 120{\r
121 //\r
122 // Initializes an ISA I/O Instance\r
123 //\r
124 CopyMem (\r
125 &IsaIoDevice->IsaIo,\r
126 &IsaIoInterface,\r
127 sizeof (EFI_ISA_IO_PROTOCOL)\r
128 );\r
129\r
130 IsaIoDevice->IsaIo.ResourceList = IsaDeviceResourceList;\r
131 \r
132 return EFI_SUCCESS;\r
133}\r
134\r
bcd70414 135/**\r
136 Performs an ISA I/O Read Cycle\r
137\r
138 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
139 @param Width - Signifies the width of the I/O operation.\r
140 @param Offset - The offset in ISA I/O space to start the I/O operation. \r
141 @param Count - The number of I/O operations to perform. \r
142 @param Buffer - The destination buffer to store the results\r
143\r
144 @retval EFI_SUCCESS - The data was read from the device sucessfully.\r
145 @retval EFI_UNSUPPORTED - The Offset is not valid for this device.\r
146 @retval EFI_INVALID_PARAMETER - Width or Count, or both, were invalid.\r
147 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r
148\r
149**/\r
c3902377 150EFI_STATUS\r
151EFIAPI\r
152IsaIoIoRead (\r
153 IN EFI_ISA_IO_PROTOCOL *This,\r
154 IN EFI_ISA_IO_PROTOCOL_WIDTH Width,\r
155 IN UINT32 Offset,\r
156 IN UINTN Count,\r
157 IN OUT VOID *Buffer\r
158 )\r
c3902377 159\r
c3902377 160{\r
161 EFI_STATUS Status;\r
162 ISA_IO_DEVICE *IsaIoDevice;\r
163\r
164 IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r
165\r
166 //\r
167 // Verify Isa IO Access\r
168 //\r
169 Status = IsaIoVerifyAccess (\r
170 IsaIoDevice,\r
171 IsaAccessTypeIo,\r
172 Width,\r
173 Count,\r
174 &Offset\r
175 );\r
176 if (EFI_ERROR (Status)) {\r
177 return Status;\r
178 }\r
179 //\r
180 // Call PciIo->Io.Read\r
181 //\r
182 Status = IsaIoDevice->PciIo->Io.Read (\r
183 IsaIoDevice->PciIo,\r
184 (EFI_PCI_IO_PROTOCOL_WIDTH) Width,\r
185 EFI_PCI_IO_PASS_THROUGH_BAR,\r
186 Offset,\r
187 Count,\r
188 Buffer\r
189 );\r
190\r
191 if (EFI_ERROR (Status)) {\r
192 ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r
193 }\r
194\r
195 return Status;\r
196}\r
197\r
bcd70414 198/**\r
199 Performs an ISA I/O Write Cycle\r
200\r
201 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
202 @param Width - Signifies the width of the I/O operation.\r
203 @param Offset - The offset in ISA I/O space to start the I/O operation. \r
204 @param Count - The number of I/O operations to perform. \r
205 @param Buffer - The source buffer to write data from\r
206\r
fdb05fa3 207 @retval EFI_SUCCESS - The data was writen to the device sucessfully.\r
208 @retval EFI_UNSUPPORTED - The Offset is not valid for this device.\r
209 @retval EFI_INVALID_PARAMETER - Width or Count, or both, were invalid.\r
210 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r
bcd70414 211\r
212**/\r
c3902377 213EFI_STATUS\r
214EFIAPI\r
215IsaIoIoWrite (\r
216 IN EFI_ISA_IO_PROTOCOL *This,\r
217 IN EFI_ISA_IO_PROTOCOL_WIDTH Width,\r
218 IN UINT32 Offset,\r
219 IN UINTN Count,\r
220 IN OUT VOID *Buffer\r
221 )\r
c3902377 222{\r
223 EFI_STATUS Status;\r
224 ISA_IO_DEVICE *IsaIoDevice;\r
225\r
226 IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r
227\r
228 //\r
229 // Verify Isa IO Access\r
230 //\r
231 Status = IsaIoVerifyAccess (\r
232 IsaIoDevice,\r
233 IsaAccessTypeIo,\r
234 Width,\r
235 Count,\r
236 &Offset\r
237 );\r
238 if (EFI_ERROR (Status)) {\r
239 return Status;\r
240 }\r
241 //\r
242 // Call PciIo->Io.Write\r
243 //\r
244 Status = IsaIoDevice->PciIo->Io.Write (\r
245 IsaIoDevice->PciIo,\r
246 (EFI_PCI_IO_PROTOCOL_WIDTH) Width,\r
247 EFI_PCI_IO_PASS_THROUGH_BAR,\r
248 Offset,\r
249 Count,\r
250 Buffer\r
251 );\r
252\r
253 if (EFI_ERROR (Status)) {\r
254 ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r
255 }\r
256\r
257 return Status;\r
258}\r
259\r
bcd70414 260/**\r
261 Writes an 8 bit I/O Port\r
262\r
263 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
264 @param Offset - The offset in ISA IO space to start the IO operation. \r
265 @param Value - The data to write port.\r
266\r
267 @retval EFI_SUCCESS - Success.\r
268 @retval EFI_INVALID_PARAMETER - Parameter is invalid.\r
269 @retval EFI_UNSUPPORTED - The address range specified by Offset is not valid.\r
270 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r
271 \r
272**/\r
c3902377 273EFI_STATUS\r
274WritePort (\r
275 IN EFI_ISA_IO_PROTOCOL *This,\r
276 IN UINT32 Offset,\r
277 IN UINT8 Value\r
278 )\r
c3902377 279\r
c3902377 280{\r
281 EFI_STATUS Status;\r
282 ISA_IO_DEVICE *IsaIoDevice;\r
283\r
284 IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r
285\r
286 //\r
287 // Call PciIo->Io.Write\r
288 //\r
289 Status = IsaIoDevice->PciIo->Io.Write (\r
290 IsaIoDevice->PciIo,\r
291 EfiPciIoWidthUint8,\r
292 EFI_PCI_IO_PASS_THROUGH_BAR,\r
293 Offset,\r
294 1,\r
295 &Value\r
296 );\r
297 if (EFI_ERROR (Status)) {\r
298 ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r
299 return Status;\r
300 }\r
301\r
302 gBS->Stall (50);\r
303\r
304 return EFI_SUCCESS;\r
305}\r
306\r
bcd70414 307/**\r
308 Writes I/O operation base address and count number to a 8 bit I/O Port.\r
309\r
310 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
311 @param AddrOffset - The address' offset.\r
312 @param PageOffset - The page's offest.\r
313 @param CountOffset - The count's offset.\r
314 @param BaseAddress - The base address.\r
315 @param Count - The number of I/O operations to perform. \r
316 \r
317 @retval EFI_SUCCESS - Success.\r
318 @retval EFI_INVALID_PARAMETER - Parameter is invalid.\r
319 @retval EFI_UNSUPPORTED - The address range specified by these Offsets and Count is not valid.\r
320 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r
321\r
322**/\r
c3902377 323EFI_STATUS\r
324WriteDmaPort (\r
325 IN EFI_ISA_IO_PROTOCOL *This,\r
326 IN UINT32 AddrOffset,\r
327 IN UINT32 PageOffset,\r
328 IN UINT32 CountOffset,\r
329 IN UINT32 BaseAddress,\r
330 IN UINT16 Count\r
331 )\r
c3902377 332\r
c3902377 333{\r
334 EFI_STATUS Status;\r
335\r
336 Status = WritePort (This, AddrOffset, (UINT8) (BaseAddress & 0xff));\r
337 if (EFI_ERROR (Status)) {\r
338 return Status;\r
339 }\r
340\r
341 Status = WritePort (This, AddrOffset, (UINT8) ((BaseAddress >> 8) & 0xff));\r
342 if (EFI_ERROR (Status)) {\r
343 return Status;\r
344 }\r
345\r
346 Status = WritePort (This, PageOffset, (UINT8) ((BaseAddress >> 16) & 0xff));\r
347 if (EFI_ERROR (Status)) {\r
348 return Status;\r
349 }\r
350\r
351 Status = WritePort (This, CountOffset, (UINT8) (Count & 0xff));\r
352 if (EFI_ERROR (Status)) {\r
353 return Status;\r
354 }\r
355\r
356 Status = WritePort (This, CountOffset, (UINT8) ((Count >> 8) & 0xff));\r
357 if (EFI_ERROR (Status)) {\r
358 return Status;\r
359 }\r
360\r
361 return EFI_SUCCESS;\r
362}\r
363\r
bcd70414 364/**\r
365 Unmaps a memory region for DMA\r
366\r
367 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
368 @param Mapping - The mapping value returned from EFI_ISA_IO.Map().\r
369\r
370 @retval EFI_SUCCESS - The range was unmapped.\r
371 @retval EFI_DEVICE_ERROR - The data was not committed to the target system memory.\r
372\r
373**/\r
c3902377 374EFI_STATUS\r
375EFIAPI\r
376IsaIoUnmap (\r
377 IN EFI_ISA_IO_PROTOCOL *This,\r
378 IN VOID *Mapping\r
379 )\r
c3902377 380{\r
381 ISA_MAP_INFO *IsaMapInfo;\r
382\r
383 //\r
384 // Unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.\r
385 //\r
386 if (!FeaturePcdGet (PcdIsaBusSupportDma)) {\r
387 return EFI_UNSUPPORTED;\r
388 }\r
389\r
390 //\r
391 // See if the Map() operation associated with this Unmap() required a mapping\r
392 // buffer.If a mapping buffer was not required, then this function simply\r
393 // returns EFI_SUCCESS.\r
394 //\r
395 if (Mapping != NULL) {\r
396 //\r
397 // Get the MAP_INFO structure from Mapping\r
398 //\r
399 IsaMapInfo = (ISA_MAP_INFO *) Mapping;\r
400\r
401 //\r
402 // If this is a write operation from the Agent's point of view,\r
403 // then copy the contents of the mapped buffer into the real buffer\r
404 // so the processor can read the contents of the real buffer.\r
405 //\r
406 if (IsaMapInfo->Operation == EfiIsaIoOperationBusMasterWrite) {\r
407 CopyMem (\r
408 (VOID *) (UINTN) IsaMapInfo->HostAddress,\r
409 (VOID *) (UINTN) IsaMapInfo->MappedHostAddress,\r
410 IsaMapInfo->NumberOfBytes\r
411 );\r
412 }\r
413 //\r
414 // Free the mapped buffer and the MAP_INFO structure.\r
415 //\r
416 gBS->FreePages (IsaMapInfo->MappedHostAddress, IsaMapInfo->NumberOfPages);\r
417 gBS->FreePool (IsaMapInfo);\r
418 }\r
419\r
420 return EFI_SUCCESS;\r
421}\r
422\r
bcd70414 423/**\r
424 Flushes a DMA buffer\r
425\r
426 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
427\r
428 @retval EFI_SUCCESS - The buffers were flushed.\r
429 @retval EFI_DEVICE_ERROR - The buffers were not flushed due to a hardware error.\r
430\r
431**/\r
c3902377 432EFI_STATUS\r
433EFIAPI\r
434IsaIoFlush (\r
435 IN EFI_ISA_IO_PROTOCOL *This\r
436 )\r
c3902377 437\r
c3902377 438{\r
439 EFI_STATUS Status;\r
440 ISA_IO_DEVICE *IsaIoDevice;\r
441\r
442 IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r
443\r
444 //\r
445 // Call PciIo->Flush\r
446 //\r
447 Status = IsaIoDevice->PciIo->Flush (IsaIoDevice->PciIo);\r
448\r
449 if (EFI_ERROR (Status)) {\r
450 ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r
451 }\r
452\r
453 return Status;\r
454}\r
455\r
bcd70414 456/**\r
457 Verifies access to an ISA device\r
458\r
459 @param IsaIoDevice - The ISA device to be verified.\r
460 @param Type - The Access type. The input must be either IsaAccessTypeMem or IsaAccessTypeIo.\r
461 @param Width - Signifies the width of the memory operation.\r
462 @param Count - The number of memory operations to perform. \r
463 @param Offset - The offset in ISA memory space to start the memory operation. \r
464 \r
465 @retval EFI_SUCCESS - Verify success.\r
466 @retval EFI_INVALID_PARAMETER - One of the parameters has an invalid value.\r
467 @retval EFI_UNSUPPORTED - The device ont support the access type.\r
468\r
469**/\r
c3902377 470EFI_STATUS\r
471IsaIoVerifyAccess (\r
472 IN ISA_IO_DEVICE *IsaIoDevice,\r
473 IN ISA_ACCESS_TYPE Type,\r
474 IN EFI_ISA_IO_PROTOCOL_WIDTH Width,\r
475 IN UINTN Count,\r
476 IN OUT UINT32 *Offset\r
477 )\r
c3902377 478\r
c3902377 479{\r
480 EFI_ISA_ACPI_RESOURCE *Item;\r
481 EFI_STATUS Status;\r
482\r
483 if (Width < EfiIsaIoWidthUint8 ||\r
484 Width >= EfiIsaIoWidthMaximum ||\r
485 Width == EfiIsaIoWidthReserved ||\r
486 Width == EfiIsaIoWidthFifoReserved ||\r
487 Width == EfiIsaIoWidthFillReserved\r
488 ) {\r
489 return EFI_INVALID_PARAMETER;\r
490 }\r
491\r
492 //\r
493 // If Width is EfiIsaIoWidthFifoUintX then convert to EfiIsaIoWidthUintX\r
494 // If Width is EfiIsaIoWidthFillUintX then convert to EfiIsaIoWidthUintX\r
495 //\r
496 if (Width >= EfiIsaIoWidthFifoUint8 && Width <= EfiIsaIoWidthFifoReserved) {\r
497 Count = 1;\r
498 }\r
499\r
500 Width = (EFI_ISA_IO_PROTOCOL_WIDTH) (Width & 0x03);\r
501\r
502 Status = EFI_UNSUPPORTED;\r
503 Item = IsaIoDevice->IsaIo.ResourceList->ResourceItem;\r
504 while (Item->Type != EfiIsaAcpiResourceEndOfList) {\r
505 if ((Type == IsaAccessTypeMem && Item->Type == EfiIsaAcpiResourceMemory) ||\r
506 (Type == IsaAccessTypeIo && Item->Type == EfiIsaAcpiResourceIo)\r
507 ) {\r
508 if (*Offset >= Item->StartRange && (*Offset + Count * (UINT32)(1 << Width)) - 1 <= Item->EndRange) {\r
509 return EFI_SUCCESS;\r
510 }\r
511\r
512 if (*Offset >= Item->StartRange && *Offset <= Item->EndRange) {\r
513 Status = EFI_INVALID_PARAMETER;\r
514 }\r
515 }\r
516\r
517 Item++;\r
518 }\r
519\r
520 return Status;\r
521}\r
522\r
bcd70414 523/**\r
524\r
525 Performs an ISA Memory Read Cycle\r
526\r
527 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
528 @param Width - Signifies the width of the memory operation.\r
529 @param Offset - The offset in ISA memory space to start the memory operation. \r
530 @param Count - The number of memory operations to perform. \r
531 @param Buffer - The destination buffer to store the results\r
532 \r
533 @retval EFI_SUCCESS - The data was read from the device successfully.\r
534 @retval EFI_UNSUPPORTED - The Offset is not valid for this device.\r
535 @retval EFI_INVALID_PARAMETER - Width or Count, or both, were invalid.\r
536 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r
537\r
538**/\r
c3902377 539EFI_STATUS\r
540EFIAPI\r
541IsaIoMemRead (\r
542 IN EFI_ISA_IO_PROTOCOL *This,\r
543 IN EFI_ISA_IO_PROTOCOL_WIDTH Width,\r
544 IN UINT32 Offset,\r
545 IN UINTN Count,\r
546 IN OUT VOID *Buffer\r
547 )\r
c3902377 548\r
c3902377 549{\r
550 EFI_STATUS Status;\r
551 ISA_IO_DEVICE *IsaIoDevice;\r
552\r
553 //\r
554 // Set Feature Flag PcdIsaBusSupportBusMaster to FALSE to disable support for \r
555 // ISA Bus Master.\r
556 //\r
557 // So we just return EFI_UNSUPPORTED for these functions.\r
558 //\r
559 if (!FeaturePcdGet (PcdIsaBusSupportIsaMemory)) {\r
560 return EFI_UNSUPPORTED;\r
561 }\r
562\r
563 IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r
564\r
565 //\r
566 // Verify the Isa Io Access\r
567 //\r
568 Status = IsaIoVerifyAccess (\r
569 IsaIoDevice,\r
570 IsaAccessTypeMem,\r
571 Width,\r
572 Count,\r
573 &Offset\r
574 );\r
575 if (EFI_ERROR (Status)) {\r
576 return Status;\r
577 }\r
578 //\r
579 // Call PciIo->Mem.Read\r
580 //\r
581 Status = IsaIoDevice->PciIo->Mem.Read (\r
582 IsaIoDevice->PciIo,\r
583 (EFI_PCI_IO_PROTOCOL_WIDTH) Width,\r
584 EFI_PCI_IO_PASS_THROUGH_BAR,\r
585 Offset,\r
586 Count,\r
587 Buffer\r
588 );\r
589\r
590 if (EFI_ERROR (Status)) {\r
591 ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r
592 }\r
593\r
594 return Status;\r
595}\r
596\r
bcd70414 597/**\r
598 Performs an ISA Memory Write Cycle\r
599\r
600 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance. \r
601 @param Width - Signifies the width of the memory operation.\r
602 @param Offset - The offset in ISA memory space to start the memory operation. \r
603 @param Count - The number of memory operations to perform. \r
604 @param Buffer - The source buffer to write data from\r
605\r
606 @retval EFI_SUCCESS - The data was written to the device sucessfully.\r
607 @retval EFI_UNSUPPORTED - The Offset is not valid for this device.\r
608 @retval EFI_INVALID_PARAMETER - Width or Count, or both, were invalid.\r
609 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r
610\r
611**/\r
c3902377 612EFI_STATUS\r
613EFIAPI\r
614IsaIoMemWrite (\r
615 IN EFI_ISA_IO_PROTOCOL *This,\r
616 IN EFI_ISA_IO_PROTOCOL_WIDTH Width,\r
617 IN UINT32 Offset,\r
618 IN UINTN Count,\r
619 IN OUT VOID *Buffer\r
620 )\r
c3902377 621{\r
622 EFI_STATUS Status;\r
623 ISA_IO_DEVICE *IsaIoDevice;\r
624\r
625 //\r
626 // Set Feature Flag PcdIsaBusSupportBusMaster to FALSE to disable support for \r
627 // ISA Bus Master.\r
628 //\r
629 // So we just return EFI_UNSUPPORTED for these functions.\r
630 //\r
631 if (!FeaturePcdGet (PcdIsaBusSupportIsaMemory)) {\r
632 return EFI_UNSUPPORTED;\r
633 }\r
634\r
635 IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r
636\r
637 //\r
638 // Verify Isa IO Access\r
639 //\r
640 Status = IsaIoVerifyAccess (\r
641 IsaIoDevice,\r
642 IsaAccessTypeMem,\r
643 Width,\r
644 Count,\r
645 &Offset\r
646 );\r
647 if (EFI_ERROR (Status)) {\r
648 return Status;\r
649 }\r
650 //\r
651 // Call PciIo->Mem.Write\r
652 //\r
653 Status = IsaIoDevice->PciIo->Mem.Write (\r
654 IsaIoDevice->PciIo,\r
655 (EFI_PCI_IO_PROTOCOL_WIDTH) Width,\r
656 EFI_PCI_IO_PASS_THROUGH_BAR,\r
657 Offset,\r
658 Count,\r
659 Buffer\r
660 );\r
661\r
662 if (EFI_ERROR (Status)) {\r
663 ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r
664 }\r
665\r
666 return Status;\r
667}\r
668\r
bcd70414 669/**\r
670 Performs an ISA I/O Copy Memory \r
671\r
672 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
673 @param Width - Signifies the width of the memory copy operation.\r
674 @param DestOffset - The offset of the destination \r
675 @param SrcOffset - The offset of the source\r
676 @param Count - The number of memory copy operations to perform\r
677\r
678 @retval EFI_SUCCESS - The data was copied sucessfully.\r
679 @retval EFI_UNSUPPORTED - The DestOffset or SrcOffset is not valid for this device.\r
680 @retval EFI_INVALID_PARAMETER - Width or Count, or both, were invalid.\r
681 @retval EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of resources.\r
682\r
683**/\r
c3902377 684EFI_STATUS\r
685EFIAPI\r
686IsaIoCopyMem (\r
687 IN EFI_ISA_IO_PROTOCOL *This,\r
688 IN EFI_ISA_IO_PROTOCOL_WIDTH Width,\r
689 IN UINT32 DestOffset,\r
690 IN UINT32 SrcOffset,\r
691 IN UINTN Count\r
692 )\r
c3902377 693\r
c3902377 694{\r
695 EFI_STATUS Status;\r
696 ISA_IO_DEVICE *IsaIoDevice;\r
697\r
698 //\r
699 // Set Feature Flag PcdIsaBusSupportBusMaster to FALSE to disable support for \r
700 // ISA Bus Master.\r
701 //\r
702 // So we just return EFI_UNSUPPORTED for these functions.\r
703 //\r
704 if (!FeaturePcdGet (PcdIsaBusSupportIsaMemory)) {\r
705 return EFI_UNSUPPORTED;\r
706 }\r
707\r
708 IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (This);\r
709\r
710 //\r
711 // Verify Isa IO Access for destination and source\r
712 //\r
713 Status = IsaIoVerifyAccess (\r
714 IsaIoDevice,\r
715 IsaAccessTypeMem,\r
716 Width,\r
717 Count,\r
718 &DestOffset\r
719 );\r
720 if (EFI_ERROR (Status)) {\r
721 return Status;\r
722 }\r
723\r
724 Status = IsaIoVerifyAccess (\r
725 IsaIoDevice,\r
726 IsaAccessTypeMem,\r
727 Width,\r
728 Count,\r
729 &SrcOffset\r
730 );\r
731 if (EFI_ERROR (Status)) {\r
732 return Status;\r
733 }\r
734 //\r
735 // Call PciIo->CopyMem\r
736 //\r
737 Status = IsaIoDevice->PciIo->CopyMem (\r
738 IsaIoDevice->PciIo,\r
739 (EFI_PCI_IO_PROTOCOL_WIDTH) Width,\r
740 EFI_PCI_IO_PASS_THROUGH_BAR,\r
741 DestOffset,\r
742 EFI_PCI_IO_PASS_THROUGH_BAR,\r
743 SrcOffset,\r
744 Count\r
745 );\r
746\r
747 if (EFI_ERROR (Status)) {\r
748 ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r
749 }\r
750\r
751 return Status;\r
752}\r
753\r
bcd70414 754/**\r
755 Maps a memory region for DMA, note this implementation\r
756 only supports slave read/write operation to save code size.\r
757\r
758 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
759 @param Operation - Indicates the type of DMA (slave or bus master), and if \r
760 the DMA operation is going to read or write to system memory. \r
761 @param ChannelNumber - The slave channel number to use for this DMA operation. \r
762 If Operation and ChannelAttributes shows that this device \r
763 performs bus mastering DMA, then this field is ignored. \r
764 The legal range for this field is 0..7. \r
765 @param ChannelAttributes - The attributes of the DMA channel to use for this DMA operation\r
766 @param HostAddress - The system memory address to map to the device. \r
767 @param NumberOfBytes - On input the number of bytes to map. On output the number \r
768 of bytes that were mapped.\r
769 @param DeviceAddress - The resulting map address for the bus master device to use \r
770 to access the hosts HostAddress. \r
771 @param Mapping - A resulting value to pass to EFI_ISA_IO.Unmap().\r
772\r
773 @retval EFI_SUCCESS - The range was mapped for the returned NumberOfBytes.\r
774 @retval EFI_INVALID_PARAMETER - The Operation or HostAddress is undefined.\r
775 @retval EFI_UNSUPPORTED - The HostAddress can not be mapped as a common buffer.\r
776 @retval EFI_DEVICE_ERROR - The system hardware could not map the requested address.\r
777 @retval EFI_OUT_OF_RESOURCES - The memory pages could not be allocated.\r
778\r
779**/\r
c3902377 780EFI_STATUS\r
781IsaIoMap_OnlySupportSlaveReadWrite (\r
782 IN EFI_ISA_IO_PROTOCOL *This,\r
783 IN EFI_ISA_IO_PROTOCOL_OPERATION Operation,\r
784 IN UINT8 ChannelNumber OPTIONAL,\r
785 IN UINT32 ChannelAttributes,\r
786 IN VOID *HostAddress,\r
787 IN OUT UINTN *NumberOfBytes,\r
788 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
789 OUT VOID **Mapping\r
790 )\r
c3902377 791\r
c3902377 792{\r
793 EFI_STATUS Status;\r
794 EFI_PHYSICAL_ADDRESS PhysicalAddress;\r
795 ISA_MAP_INFO *IsaMapInfo;\r
796 UINT8 DmaMode;\r
797 UINTN MaxNumberOfBytes;\r
798 UINT32 BaseAddress;\r
799 UINT16 Count;\r
800\r
801 UINT8 DmaMask;\r
802 UINT8 DmaClear;\r
803 UINT8 DmaChannelMode;\r
804 \r
805 if ((NULL == This) ||\r
806 (NULL == HostAddress) ||\r
807 (NULL == NumberOfBytes) ||\r
808 (NULL == DeviceAddress) ||\r
809 (NULL == Mapping)\r
810 ) {\r
811 return EFI_INVALID_PARAMETER;\r
812 }\r
813\r
814\r
815 //\r
816 // Initialize the return values to their defaults\r
817 //\r
818 *Mapping = NULL;\r
819\r
820 //\r
821 // Make sure the Operation parameter is valid.\r
822 // Light IsaIo only supports two operations.\r
823 //\r
824 if (!(Operation == EfiIsaIoOperationSlaveRead || \r
825 Operation == EfiIsaIoOperationSlaveWrite)) {\r
826 return EFI_INVALID_PARAMETER;\r
827 }\r
828\r
829 if (ChannelNumber >= 4) {\r
830 //\r
831 // The Light IsaIo doesn't support channelNumber larger than 4.\r
832 //\r
833 return EFI_INVALID_PARAMETER;\r
834 }\r
835\r
836 //\r
837 // Map the HostAddress to a DeviceAddress.\r
838 //\r
839 PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress;\r
840 if ((PhysicalAddress +*NumberOfBytes) > ISA_MAX_MEMORY_ADDRESS) {\r
841 //\r
842 // Common Buffer operations can not be remapped. If the common buffer\r
843 // is above 16MB, then it is not possible to generate a mapping, so return\r
844 // an error.\r
845 //\r
846 if (Operation == EfiIsaIoOperationBusMasterCommonBuffer) {\r
847 return EFI_UNSUPPORTED;\r
848 }\r
849 //\r
850 // Allocate an ISA_MAP_INFO structure to remember the mapping when Unmap()\r
851 // is called later.\r
852 //\r
853 IsaMapInfo = AllocatePool (sizeof (ISA_MAP_INFO));\r
854 if (IsaMapInfo == NULL) {\r
855 *NumberOfBytes = 0;\r
856 return EFI_OUT_OF_RESOURCES;\r
857 }\r
858 //\r
859 // Return a pointer to the MAP_INFO structure in Mapping\r
860 //\r
861 *Mapping = IsaMapInfo;\r
862\r
863 //\r
864 // Initialize the MAP_INFO structure\r
865 //\r
866 IsaMapInfo->Operation = Operation;\r
867 IsaMapInfo->NumberOfBytes = *NumberOfBytes;\r
868 IsaMapInfo->NumberOfPages = EFI_SIZE_TO_PAGES (*NumberOfBytes);\r
869 IsaMapInfo->HostAddress = PhysicalAddress;\r
870 IsaMapInfo->MappedHostAddress = ISA_MAX_MEMORY_ADDRESS - 1;\r
871\r
872 //\r
873 // Allocate a buffer below 16MB to map the transfer to.\r
874 //\r
875 Status = gBS->AllocatePages (\r
876 AllocateMaxAddress,\r
877 EfiBootServicesData,\r
878 IsaMapInfo->NumberOfPages,\r
879 &IsaMapInfo->MappedHostAddress\r
880 );\r
881 if (EFI_ERROR (Status)) {\r
882 gBS->FreePool (IsaMapInfo);\r
883 *NumberOfBytes = 0;\r
884 *Mapping = NULL;\r
885 return Status;\r
886 }\r
887 //\r
888 // If this is a read operation from the DMA agents's point of view,\r
889 // then copy the contents of the real buffer into the mapped buffer\r
890 // so the DMA agent can read the contents of the real buffer.\r
891 //\r
892 if (Operation == EfiIsaIoOperationSlaveRead) {\r
893 CopyMem (\r
894 (VOID *) (UINTN) IsaMapInfo->MappedHostAddress,\r
895 (VOID *) (UINTN) IsaMapInfo->HostAddress,\r
896 IsaMapInfo->NumberOfBytes\r
897 );\r
898 }\r
899 //\r
900 // The DeviceAddress is the address of the maped buffer below 16 MB\r
901 //\r
902 *DeviceAddress = IsaMapInfo->MappedHostAddress;\r
903 } else {\r
904 //\r
905 // The transfer is below 16 MB, so the DeviceAddress is simply the\r
906 // HostAddress\r
907 //\r
908 *DeviceAddress = PhysicalAddress;\r
909 }\r
910 \r
911 //\r
912 // Figure out what to program into the DMA Channel Mode Register\r
913 //\r
914 DmaMode = (UINT8) (B_8237_DMA_CHMODE_INCREMENT | (ChannelNumber & 0x03));\r
915 if (Operation == EfiIsaIoOperationSlaveRead) {\r
916 DmaMode |= V_8237_DMA_CHMODE_MEM2IO;\r
917 } else {\r
918 DmaMode |= V_8237_DMA_CHMODE_IO2MEM;\r
919 }\r
920 //\r
921 // We only support EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SINGLE_MODE in simplified IsaIo\r
922 //\r
923 DmaMode |= V_8237_DMA_CHMODE_SINGLE;\r
924\r
925 //\r
926 // A Slave DMA transfer can not cross a 64K boundary.\r
927 // Compute *NumberOfBytes based on this restriction.\r
928 //\r
929 MaxNumberOfBytes = 0x10000 - ((UINT32) (*DeviceAddress) & 0xffff);\r
930 if (*NumberOfBytes > MaxNumberOfBytes) {\r
931 *NumberOfBytes = MaxNumberOfBytes;\r
932 }\r
933 //\r
934 // Compute the values to program into the BaseAddress and Count registers\r
935 // of the Slave DMA controller\r
936 //\r
937 BaseAddress = (UINT32) (*DeviceAddress);\r
938 Count = (UINT16) (*NumberOfBytes - 1);\r
939 //\r
940 // Program the DMA Write Single Mask Register for ChannelNumber\r
941 // Clear the DMA Byte Pointer Register\r
942 //\r
943 DmaMask = R_8237_DMA_WRSMSK_CH0_3;\r
944 DmaClear = R_8237_DMA_CBPR_CH0_3;\r
945 DmaChannelMode = R_8237_DMA_CHMODE_CH0_3;\r
946\r
947 Status = WritePort (\r
948 This,\r
949 DmaMask,\r
950 (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))\r
951 );\r
952 if (EFI_ERROR (Status)) {\r
953 return Status;\r
954 }\r
955\r
956 Status = WritePort (\r
957 This,\r
958 DmaClear,\r
959 (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))\r
960 );\r
961 if (EFI_ERROR (Status)) {\r
962 return Status;\r
963 }\r
964\r
965 Status = WritePort (This, DmaChannelMode, DmaMode);\r
966 if (EFI_ERROR (Status)) {\r
967 return Status;\r
968 }\r
969\r
970 Status = WriteDmaPort (\r
971 This,\r
972 DmaRegisters[ChannelNumber].Address,\r
973 DmaRegisters[ChannelNumber].Page,\r
974 DmaRegisters[ChannelNumber].Count,\r
975 BaseAddress,\r
976 Count\r
977 );\r
978 if (EFI_ERROR (Status)) {\r
979 return Status;\r
980 }\r
981\r
982 Status = WritePort (\r
983 This,\r
984 DmaMask,\r
985 (UINT8) (ChannelNumber & 0x03)\r
986 );\r
987 if (EFI_ERROR (Status)) {\r
988 return Status;\r
989 }\r
990\r
991 return EFI_SUCCESS;\r
992}\r
993\r
bcd70414 994/**\r
995 Maps a memory region for DMA. This implementation implement the \r
996 the full mapping support.\r
997\r
998 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
999 @param Operation - Indicates the type of DMA (slave or bus master), and if \r
1000 the DMA operation is going to read or write to system memory. \r
1001 @param ChannelNumber - The slave channel number to use for this DMA operation. \r
1002 If Operation and ChannelAttributes shows that this device \r
1003 performs bus mastering DMA, then this field is ignored. \r
1004 The legal range for this field is 0..7. \r
1005 @param ChannelAttributes - The attributes of the DMA channel to use for this DMA operation\r
1006 @param HostAddress - The system memory address to map to the device. \r
1007 @param NumberOfBytes - On input the number of bytes to map. On output the number \r
1008 of bytes that were mapped.\r
1009 @param DeviceAddress - The resulting map address for the bus master device to use \r
1010 - to access the hosts HostAddress. \r
1011 @param Mapping - A resulting value to pass to EFI_ISA_IO.Unmap().\r
1012\r
1013 @retval EFI_SUCCESS - The range was mapped for the returned NumberOfBytes.\r
1014 @retval EFI_INVALID_PARAMETER - The Operation or HostAddress is undefined.\r
1015 @retval EFI_UNSUPPORTED - The HostAddress can not be mapped as a common buffer.\r
1016 @retval EFI_DEVICE_ERROR - The system hardware could not map the requested address.\r
1017 @retval EFI_OUT_OF_RESOURCES - The memory pages could not be allocated.\r
1018\r
1019**/\r
c3902377 1020EFI_STATUS\r
1021IsaIoMap_FullSupport (\r
1022 IN EFI_ISA_IO_PROTOCOL *This,\r
1023 IN EFI_ISA_IO_PROTOCOL_OPERATION Operation,\r
1024 IN UINT8 ChannelNumber OPTIONAL,\r
1025 IN UINT32 ChannelAttributes,\r
1026 IN VOID *HostAddress,\r
1027 IN OUT UINTN *NumberOfBytes,\r
1028 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
1029 OUT VOID **Mapping\r
1030 )\r
c3902377 1031\r
c3902377 1032{\r
1033 EFI_STATUS Status;\r
1034 BOOLEAN Master;\r
1035 BOOLEAN Read;\r
1036 EFI_PHYSICAL_ADDRESS PhysicalAddress;\r
1037 ISA_MAP_INFO *IsaMapInfo;\r
1038 UINT8 DmaMode;\r
1039 UINTN MaxNumberOfBytes;\r
1040 UINT32 BaseAddress;\r
1041 UINT16 Count;\r
1042\r
1043 UINT8 DmaMask;\r
1044 UINT8 DmaClear;\r
1045 UINT8 DmaChannelMode;\r
1046\r
1047 if ((NULL == This) ||\r
1048 (NULL == HostAddress) ||\r
1049 (NULL == NumberOfBytes) ||\r
1050 (NULL == DeviceAddress) ||\r
1051 (NULL == Mapping)\r
1052 ) {\r
1053 return EFI_INVALID_PARAMETER;\r
1054 }\r
1055\r
1056\r
1057 //\r
1058 // Initialize the return values to their defaults\r
1059 //\r
1060 *Mapping = NULL;\r
1061\r
1062 //\r
1063 // Make sure the Operation parameter is valid\r
1064 //\r
1065 if (Operation < 0 || Operation >= EfiIsaIoOperationMaximum) {\r
1066 return EFI_INVALID_PARAMETER;\r
1067 }\r
1068 //\r
1069 // See if this is a Slave DMA Operation\r
1070 //\r
1071 Master = TRUE;\r
1072 Read = FALSE;\r
1073 if (Operation == EfiIsaIoOperationSlaveRead) {\r
1074 Operation = EfiIsaIoOperationBusMasterRead;\r
1075 Master = FALSE;\r
1076 Read = TRUE;\r
1077 }\r
1078\r
1079 if (Operation == EfiIsaIoOperationSlaveWrite) {\r
1080 Operation = EfiIsaIoOperationBusMasterWrite;\r
1081 Master = FALSE;\r
1082 Read = FALSE;\r
1083 }\r
1084\r
1085 if (!Master) {\r
1086 //\r
1087 // Make sure that ChannelNumber is a valid channel number\r
1088 // Channel 4 is used to cascade, so it is illegal.\r
1089 //\r
1090 if (ChannelNumber == 4 || ChannelNumber > 7) {\r
1091 return EFI_INVALID_PARAMETER;\r
1092 }\r
1093 //\r
1094 // This implementation only support COMPATIBLE DMA Transfers\r
1095 //\r
1096 if (!(ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_COMPATIBLE)) {\r
1097 return EFI_INVALID_PARAMETER;\r
1098 }\r
1099\r
1100 if (ChannelAttributes &\r
1101 (\r
1102 EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_A |\r
1103 EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_B |\r
1104 EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_C\r
1105 )\r
1106 ) {\r
1107 return EFI_INVALID_PARAMETER;\r
1108 }\r
1109\r
1110 if (ChannelNumber < 4) {\r
1111 //\r
1112 // If this is Channel 0..3, then the width must be 8 bit\r
1113 //\r
1114 if (!(ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_8) ||\r
1115 (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_16)\r
1116 ) {\r
1117 return EFI_INVALID_PARAMETER;\r
1118 }\r
1119 } else {\r
1120 //\r
1121 // If this is Channel 4..7, then the width must be 16 bit\r
1122 //\r
1123 if ((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_8) ||\r
1124 (!(ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_16))\r
1125 ) {\r
1126 return EFI_INVALID_PARAMETER;\r
1127 }\r
1128 }\r
1129 //\r
1130 // Either Demand Mode or Single Mode must be selected, but not both\r
1131 //\r
1132 if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SINGLE_MODE) {\r
1133 if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_DEMAND_MODE) {\r
1134 return EFI_INVALID_PARAMETER;\r
1135 }\r
1136 } else {\r
1137 if (!(ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_DEMAND_MODE)) {\r
1138 return EFI_INVALID_PARAMETER;\r
1139 }\r
1140 }\r
1141 }\r
1142 //\r
1143 // Map the HostAddress to a DeviceAddress.\r
1144 //\r
1145 PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress;\r
1146 if ((PhysicalAddress +*NumberOfBytes) > ISA_MAX_MEMORY_ADDRESS) {\r
1147 //\r
1148 // Common Buffer operations can not be remapped. If the common buffer\r
1149 // is above 16MB, then it is not possible to generate a mapping, so return\r
1150 // an error.\r
1151 //\r
1152 if (Operation == EfiIsaIoOperationBusMasterCommonBuffer) {\r
1153 return EFI_UNSUPPORTED;\r
1154 }\r
1155 //\r
1156 // Allocate an ISA_MAP_INFO structure to remember the mapping when Unmap()\r
1157 // is called later.\r
1158 //\r
1159 IsaMapInfo = AllocatePool (sizeof (ISA_MAP_INFO));\r
1160 if (IsaMapInfo == NULL) {\r
1161 *NumberOfBytes = 0;\r
1162 return EFI_OUT_OF_RESOURCES;\r
1163 }\r
1164 //\r
1165 // Return a pointer to the MAP_INFO structure in Mapping\r
1166 //\r
1167 *Mapping = IsaMapInfo;\r
1168\r
1169 //\r
1170 // Initialize the MAP_INFO structure\r
1171 //\r
1172 IsaMapInfo->Operation = Operation;\r
1173 IsaMapInfo->NumberOfBytes = *NumberOfBytes;\r
1174 IsaMapInfo->NumberOfPages = EFI_SIZE_TO_PAGES (*NumberOfBytes);\r
1175 IsaMapInfo->HostAddress = PhysicalAddress;\r
1176 IsaMapInfo->MappedHostAddress = ISA_MAX_MEMORY_ADDRESS - 1;\r
1177\r
1178 //\r
1179 // Allocate a buffer below 16MB to map the transfer to.\r
1180 //\r
1181 Status = gBS->AllocatePages (\r
1182 AllocateMaxAddress,\r
1183 EfiBootServicesData,\r
1184 IsaMapInfo->NumberOfPages,\r
1185 &IsaMapInfo->MappedHostAddress\r
1186 );\r
1187 if (EFI_ERROR (Status)) {\r
1188 gBS->FreePool (IsaMapInfo);\r
1189 *NumberOfBytes = 0;\r
1190 *Mapping = NULL;\r
1191 return Status;\r
1192 }\r
1193 //\r
1194 // If this is a read operation from the DMA agents's point of view,\r
1195 // then copy the contents of the real buffer into the mapped buffer\r
1196 // so the DMA agent can read the contents of the real buffer.\r
1197 //\r
1198 if (Operation == EfiIsaIoOperationBusMasterRead) {\r
1199 CopyMem (\r
1200 (VOID *) (UINTN) IsaMapInfo->MappedHostAddress,\r
1201 (VOID *) (UINTN) IsaMapInfo->HostAddress,\r
1202 IsaMapInfo->NumberOfBytes\r
1203 );\r
1204 }\r
1205 //\r
1206 // The DeviceAddress is the address of the maped buffer below 16 MB\r
1207 //\r
1208 *DeviceAddress = IsaMapInfo->MappedHostAddress;\r
1209 } else {\r
1210 //\r
1211 // The transfer is below 16 MB, so the DeviceAddress is simply the\r
1212 // HostAddress\r
1213 //\r
1214 *DeviceAddress = PhysicalAddress;\r
1215 }\r
1216 //\r
1217 // If this is a Bus Master operation then return\r
1218 //\r
1219 if (Master) {\r
1220 return EFI_SUCCESS;\r
1221 }\r
1222 //\r
1223 // Figure out what to program into the DMA Channel Mode Register\r
1224 //\r
1225 DmaMode = (UINT8) (B_8237_DMA_CHMODE_INCREMENT | (ChannelNumber & 0x03));\r
1226 if (Read) {\r
1227 DmaMode |= V_8237_DMA_CHMODE_MEM2IO;\r
1228 } else {\r
1229 DmaMode |= V_8237_DMA_CHMODE_IO2MEM;\r
1230 }\r
1231\r
1232 if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_AUTO_INITIALIZE) {\r
1233 DmaMode |= B_8237_DMA_CHMODE_AE;\r
1234 }\r
1235\r
1236 if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_DEMAND_MODE) {\r
1237 DmaMode |= V_8237_DMA_CHMODE_DEMAND;\r
1238 }\r
1239\r
1240 if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SINGLE_MODE) {\r
1241 DmaMode |= V_8237_DMA_CHMODE_SINGLE;\r
1242 }\r
1243 //\r
1244 // A Slave DMA transfer can not cross a 64K boundary.\r
1245 // Compute *NumberOfBytes based on this restriction.\r
1246 //\r
1247 MaxNumberOfBytes = 0x10000 - ((UINT32) (*DeviceAddress) & 0xffff);\r
1248 if (*NumberOfBytes > MaxNumberOfBytes) {\r
1249 *NumberOfBytes = MaxNumberOfBytes;\r
1250 }\r
1251 //\r
1252 // Compute the values to program into the BaseAddress and Count registers\r
1253 // of the Slave DMA controller\r
1254 //\r
1255 if (ChannelNumber < 4) {\r
1256 BaseAddress = (UINT32) (*DeviceAddress);\r
1257 Count = (UINT16) (*NumberOfBytes - 1);\r
1258 } else {\r
1259 BaseAddress = (UINT32) (((UINT32) (*DeviceAddress) & 0xff0000) | (((UINT32) (*DeviceAddress) & 0xffff) >> 1));\r
1260 Count = (UINT16) ((*NumberOfBytes - 1) >> 1);\r
1261 }\r
1262 //\r
1263 // Program the DMA Write Single Mask Register for ChannelNumber\r
1264 // Clear the DMA Byte Pointer Register\r
1265 //\r
1266 if (ChannelNumber < 4) {\r
1267 DmaMask = R_8237_DMA_WRSMSK_CH0_3;\r
1268 DmaClear = R_8237_DMA_CBPR_CH0_3;\r
1269 DmaChannelMode = R_8237_DMA_CHMODE_CH0_3;\r
1270 } else {\r
1271 DmaMask = R_8237_DMA_WRSMSK_CH4_7;\r
1272 DmaClear = R_8237_DMA_CBPR_CH4_7;\r
1273 DmaChannelMode = R_8237_DMA_CHMODE_CH4_7;\r
1274 }\r
1275\r
1276 Status = WritePort (\r
1277 This,\r
1278 DmaMask,\r
1279 (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))\r
1280 );\r
1281 if (EFI_ERROR (Status)) {\r
1282 return Status;\r
1283 }\r
1284\r
1285 Status = WritePort (\r
1286 This,\r
1287 DmaClear,\r
1288 (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))\r
1289 );\r
1290 if (EFI_ERROR (Status)) {\r
1291 return Status;\r
1292 }\r
1293\r
1294 Status = WritePort (This, DmaChannelMode, DmaMode);\r
1295 if (EFI_ERROR (Status)) {\r
1296 return Status;\r
1297 }\r
1298\r
1299 Status = WriteDmaPort (\r
1300 This,\r
1301 DmaRegisters[ChannelNumber].Address,\r
1302 DmaRegisters[ChannelNumber].Page,\r
1303 DmaRegisters[ChannelNumber].Count,\r
1304 BaseAddress,\r
1305 Count\r
1306 );\r
1307 if (EFI_ERROR (Status)) {\r
1308 return Status;\r
1309 }\r
1310\r
1311 Status = WritePort (\r
1312 This,\r
1313 DmaMask,\r
1314 (UINT8) (ChannelNumber & 0x03)\r
1315 );\r
1316 if (EFI_ERROR (Status)) {\r
1317 return Status;\r
1318 }\r
1319\r
1320 return EFI_SUCCESS;\r
1321}\r
1322\r
bcd70414 1323/**\r
1324 Maps a memory region for DMA\r
1325\r
1326 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
1327 @param Operation - Indicates the type of DMA (slave or bus master), and if \r
1328 the DMA operation is going to read or write to system memory. \r
1329 @param ChannelNumber - The slave channel number to use for this DMA operation. \r
1330 If Operation and ChannelAttributes shows that this device \r
1331 performs bus mastering DMA, then this field is ignored. \r
1332 The legal range for this field is 0..7. \r
1333 @param ChannelAttributes - The attributes of the DMA channel to use for this DMA operation\r
1334 @param HostAddress - The system memory address to map to the device. \r
1335 @param NumberOfBytes - On input the number of bytes to map. On output the number \r
1336 of bytes that were mapped.\r
1337 @param DeviceAddress - The resulting map address for the bus master device to use \r
1338 - to access the hosts HostAddress. \r
1339 @param Mapping - A resulting value to pass to EFI_ISA_IO.Unmap().\r
1340\r
1341\r
1342 @retval EFI_SUCCESS - The range was mapped for the returned NumberOfBytes.\r
1343 @retval EFI_INVALID_PARAMETER - The Operation or HostAddress is undefined.\r
1344 @retval EFI_UNSUPPORTED - The HostAddress can not be mapped as a common buffer.\r
1345 @retval EFI_DEVICE_ERROR - The system hardware could not map the requested address.\r
1346 @retval EFI_OUT_OF_RESOURCES - The memory pages could not be allocated.\r
1347\r
1348**/\r
c3902377 1349EFI_STATUS\r
1350EFIAPI\r
1351IsaIoMap (\r
1352 IN EFI_ISA_IO_PROTOCOL *This,\r
1353 IN EFI_ISA_IO_PROTOCOL_OPERATION Operation,\r
1354 IN UINT8 ChannelNumber OPTIONAL,\r
1355 IN UINT32 ChannelAttributes,\r
1356 IN VOID *HostAddress,\r
1357 IN OUT UINTN *NumberOfBytes,\r
1358 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
1359 OUT VOID **Mapping\r
1360 )\r
c3902377 1361\r
c3902377 1362{\r
1363 //\r
1364 // Or unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.\r
1365 //\r
1366 if (!FeaturePcdGet (PcdIsaBusSupportDma)) {\r
1367 return EFI_UNSUPPORTED;\r
1368 }\r
1369 //\r
1370 // Set Feature Flag PcdIsaBusSupportBusMaster to FALSE to disable support for \r
1371 // ISA Bus Master.\r
1372 //\r
1373 // So we just return EFI_UNSUPPORTED for these functions.\r
1374 //\r
1375 if (FeaturePcdGet (PcdIsaBusOnlySupportSlaveDma)) {\r
1376 return IsaIoMap_OnlySupportSlaveReadWrite (\r
1377 This,\r
1378 Operation,\r
1379 ChannelNumber,\r
1380 ChannelAttributes,\r
1381 HostAddress,\r
1382 NumberOfBytes,\r
1383 DeviceAddress,\r
1384 Mapping\r
1385 );\r
1386\r
1387 } else {\r
1388 return IsaIoMap_FullSupport (\r
1389 This,\r
1390 Operation,\r
1391 ChannelNumber,\r
1392 ChannelAttributes,\r
1393 HostAddress,\r
1394 NumberOfBytes,\r
1395 DeviceAddress,\r
1396 Mapping\r
1397 );\r
1398 }\r
1399}\r
bcd70414 1400\r
1401/**\r
1402 Allocates a common buffer for DMA\r
1403\r
1404 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
1405 @param Type - The type allocation to perform.\r
1406 @param MemoryType - The type of memory to allocate.\r
1407 @param Pages - The number of pages to allocate.\r
1408 @param HostAddress - A pointer to store the base address of the allocated range.\r
1409 @param Attributes - The requested bit mask of attributes for the allocated range.\r
1410\r
1411 @retval EFI_SUCCESS - The requested memory pages were allocated.\r
1412 @retval EFI_INVALID_PARAMETER - Type is invalid or MemoryType is invalid or HostAddress is NULL\r
1413 @retval EFI_UNSUPPORTED - Attributes is unsupported or the memory range specified \r
1414 by HostAddress, Pages, and Type is not available for common buffer use.\r
1415 @retval EFI_OUT_OF_RESOURCES - The memory pages could not be allocated.\r
1416\r
1417**/\r
c3902377 1418EFI_STATUS\r
1419EFIAPI\r
1420IsaIoAllocateBuffer (\r
1421 IN EFI_ISA_IO_PROTOCOL *This,\r
1422 IN EFI_ALLOCATE_TYPE Type,\r
1423 IN EFI_MEMORY_TYPE MemoryType,\r
1424 IN UINTN Pages,\r
1425 OUT VOID **HostAddress,\r
1426 IN UINT64 Attributes\r
1427 )\r
c3902377 1428{\r
1429 EFI_STATUS Status;\r
1430 EFI_PHYSICAL_ADDRESS PhysicalAddress;\r
1431\r
1432 //\r
1433 // Set Feature Flag PcdIsaBusOnlySupportSlaveDma to FALSE to disable support for \r
1434 // ISA Bus Master.\r
1435 // Or unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.\r
1436 //\r
1437 if (!FeaturePcdGet (PcdIsaBusSupportDma) || FeaturePcdGet (PcdIsaBusOnlySupportSlaveDma)) {\r
1438 return EFI_UNSUPPORTED;\r
1439 }\r
1440\r
1441 if (HostAddress == NULL) {\r
1442 return EFI_INVALID_PARAMETER;\r
1443 }\r
1444\r
1445 if (Type < AllocateAnyPages || Type >= MaxAllocateType) {\r
1446 return EFI_INVALID_PARAMETER;\r
1447 }\r
1448 //\r
1449 // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData\r
1450 //\r
1451 if (MemoryType != EfiBootServicesData && MemoryType != EfiRuntimeServicesData) {\r
1452 return EFI_INVALID_PARAMETER;\r
1453 }\r
1454\r
1455 if (Attributes &~(EFI_ISA_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE | EFI_ISA_IO_ATTRIBUTE_MEMORY_CACHED)) {\r
1456 return EFI_UNSUPPORTED;\r
1457 }\r
1458\r
1459 PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) (ISA_MAX_MEMORY_ADDRESS - 1);\r
1460 if (Type == AllocateAddress) {\r
1461 if ((UINTN) (*HostAddress) >= ISA_MAX_MEMORY_ADDRESS) {\r
1462 return EFI_UNSUPPORTED;\r
1463 } else {\r
1464 PhysicalAddress = (UINTN) (*HostAddress);\r
1465 }\r
1466 }\r
1467\r
1468 if (Type == AllocateAnyPages) {\r
1469 Type = AllocateMaxAddress;\r
1470 }\r
1471\r
1472 Status = gBS->AllocatePages (Type, MemoryType, Pages, &PhysicalAddress);\r
1473 if (EFI_ERROR (Status)) {\r
1474 ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r
1475 return Status;\r
1476 }\r
1477\r
1478 *HostAddress = (VOID *) (UINTN) PhysicalAddress;\r
1479 return Status;\r
1480}\r
1481\r
bcd70414 1482/**\r
c3902377 1483\r
1484 Frees a common buffer \r
1485\r
bcd70414 1486 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
1487 @param Pages - The number of pages to free.\r
1488 @param HostAddress - The base address of the allocated range.\r
c3902377 1489\r
c3902377 1490\r
bcd70414 1491 @retval EFI_SUCCESS - The requested memory pages were freed.\r
1492 @retval EFI_INVALID_PARAMETER - The memory was not allocated with EFI_ISA_IO.AllocateBufer().\r
c3902377 1493\r
bcd70414 1494**/\r
c3902377 1495\r
bcd70414 1496EFI_STATUS\r
1497EFIAPI\r
1498IsaIoFreeBuffer (\r
1499 IN EFI_ISA_IO_PROTOCOL *This,\r
1500 IN UINTN Pages,\r
1501 IN VOID *HostAddress\r
1502 )\r
c3902377 1503{\r
1504 EFI_STATUS Status;\r
1505 EFI_PHYSICAL_ADDRESS PhysicalAddress;\r
1506\r
1507 //\r
1508 // Set Feature Flag PcdIsaBusOnlySupportSlaveDma to FALSE to disable support for \r
1509 // ISA Bus Master.\r
1510 // Or unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.\r
1511 //\r
1512 if (!FeaturePcdGet (PcdIsaBusSupportDma) || FeaturePcdGet (PcdIsaBusOnlySupportSlaveDma)) {\r
1513 return EFI_UNSUPPORTED;\r
1514 }\r
1515\r
1516 PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress;\r
1517 Status = gBS->FreePages (\r
1518 PhysicalAddress,\r
1519 Pages\r
1520 );\r
1521 if (EFI_ERROR (Status)) {\r
1522 ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r
1523 }\r
1524\r
1525 return Status;\r
1526}\r
1527\r