]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/IsaIo.c
Correct TokenSpace Guid value
[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
aa950314 1068\r
1069 if (ChannelNumber >= 8) {\r
1070 return EFI_INVALID_PARAMETER;\r
1071 }\r
1072\r
c3902377 1073 //\r
1074 // See if this is a Slave DMA Operation\r
1075 //\r
1076 Master = TRUE;\r
1077 Read = FALSE;\r
1078 if (Operation == EfiIsaIoOperationSlaveRead) {\r
1079 Operation = EfiIsaIoOperationBusMasterRead;\r
1080 Master = FALSE;\r
1081 Read = TRUE;\r
1082 }\r
1083\r
1084 if (Operation == EfiIsaIoOperationSlaveWrite) {\r
1085 Operation = EfiIsaIoOperationBusMasterWrite;\r
1086 Master = FALSE;\r
1087 Read = FALSE;\r
1088 }\r
1089\r
1090 if (!Master) {\r
1091 //\r
1092 // Make sure that ChannelNumber is a valid channel number\r
1093 // Channel 4 is used to cascade, so it is illegal.\r
1094 //\r
1095 if (ChannelNumber == 4 || ChannelNumber > 7) {\r
1096 return EFI_INVALID_PARAMETER;\r
1097 }\r
1098 //\r
1099 // This implementation only support COMPATIBLE DMA Transfers\r
1100 //\r
1101 if (!(ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_COMPATIBLE)) {\r
1102 return EFI_INVALID_PARAMETER;\r
1103 }\r
1104\r
1105 if (ChannelAttributes &\r
1106 (\r
1107 EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_A |\r
1108 EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_B |\r
1109 EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SPEED_C\r
1110 )\r
1111 ) {\r
1112 return EFI_INVALID_PARAMETER;\r
1113 }\r
1114\r
1115 if (ChannelNumber < 4) {\r
1116 //\r
1117 // If this is Channel 0..3, then the width must be 8 bit\r
1118 //\r
1119 if (!(ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_8) ||\r
1120 (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_16)\r
1121 ) {\r
1122 return EFI_INVALID_PARAMETER;\r
1123 }\r
1124 } else {\r
1125 //\r
1126 // If this is Channel 4..7, then the width must be 16 bit\r
1127 //\r
1128 if ((ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_8) ||\r
1129 (!(ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_WIDTH_16))\r
1130 ) {\r
1131 return EFI_INVALID_PARAMETER;\r
1132 }\r
1133 }\r
1134 //\r
1135 // Either Demand Mode or Single Mode must be selected, but not both\r
1136 //\r
1137 if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SINGLE_MODE) {\r
1138 if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_DEMAND_MODE) {\r
1139 return EFI_INVALID_PARAMETER;\r
1140 }\r
1141 } else {\r
1142 if (!(ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_DEMAND_MODE)) {\r
1143 return EFI_INVALID_PARAMETER;\r
1144 }\r
1145 }\r
1146 }\r
1147 //\r
1148 // Map the HostAddress to a DeviceAddress.\r
1149 //\r
1150 PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress;\r
1151 if ((PhysicalAddress +*NumberOfBytes) > ISA_MAX_MEMORY_ADDRESS) {\r
1152 //\r
1153 // Common Buffer operations can not be remapped. If the common buffer\r
1154 // is above 16MB, then it is not possible to generate a mapping, so return\r
1155 // an error.\r
1156 //\r
1157 if (Operation == EfiIsaIoOperationBusMasterCommonBuffer) {\r
1158 return EFI_UNSUPPORTED;\r
1159 }\r
1160 //\r
1161 // Allocate an ISA_MAP_INFO structure to remember the mapping when Unmap()\r
1162 // is called later.\r
1163 //\r
1164 IsaMapInfo = AllocatePool (sizeof (ISA_MAP_INFO));\r
1165 if (IsaMapInfo == NULL) {\r
1166 *NumberOfBytes = 0;\r
1167 return EFI_OUT_OF_RESOURCES;\r
1168 }\r
1169 //\r
1170 // Return a pointer to the MAP_INFO structure in Mapping\r
1171 //\r
1172 *Mapping = IsaMapInfo;\r
1173\r
1174 //\r
1175 // Initialize the MAP_INFO structure\r
1176 //\r
1177 IsaMapInfo->Operation = Operation;\r
1178 IsaMapInfo->NumberOfBytes = *NumberOfBytes;\r
1179 IsaMapInfo->NumberOfPages = EFI_SIZE_TO_PAGES (*NumberOfBytes);\r
1180 IsaMapInfo->HostAddress = PhysicalAddress;\r
1181 IsaMapInfo->MappedHostAddress = ISA_MAX_MEMORY_ADDRESS - 1;\r
1182\r
1183 //\r
1184 // Allocate a buffer below 16MB to map the transfer to.\r
1185 //\r
1186 Status = gBS->AllocatePages (\r
1187 AllocateMaxAddress,\r
1188 EfiBootServicesData,\r
1189 IsaMapInfo->NumberOfPages,\r
1190 &IsaMapInfo->MappedHostAddress\r
1191 );\r
1192 if (EFI_ERROR (Status)) {\r
1193 gBS->FreePool (IsaMapInfo);\r
1194 *NumberOfBytes = 0;\r
1195 *Mapping = NULL;\r
1196 return Status;\r
1197 }\r
1198 //\r
1199 // If this is a read operation from the DMA agents's point of view,\r
1200 // then copy the contents of the real buffer into the mapped buffer\r
1201 // so the DMA agent can read the contents of the real buffer.\r
1202 //\r
1203 if (Operation == EfiIsaIoOperationBusMasterRead) {\r
1204 CopyMem (\r
1205 (VOID *) (UINTN) IsaMapInfo->MappedHostAddress,\r
1206 (VOID *) (UINTN) IsaMapInfo->HostAddress,\r
1207 IsaMapInfo->NumberOfBytes\r
1208 );\r
1209 }\r
1210 //\r
1211 // The DeviceAddress is the address of the maped buffer below 16 MB\r
1212 //\r
1213 *DeviceAddress = IsaMapInfo->MappedHostAddress;\r
1214 } else {\r
1215 //\r
1216 // The transfer is below 16 MB, so the DeviceAddress is simply the\r
1217 // HostAddress\r
1218 //\r
1219 *DeviceAddress = PhysicalAddress;\r
1220 }\r
1221 //\r
1222 // If this is a Bus Master operation then return\r
1223 //\r
1224 if (Master) {\r
1225 return EFI_SUCCESS;\r
1226 }\r
1227 //\r
1228 // Figure out what to program into the DMA Channel Mode Register\r
1229 //\r
1230 DmaMode = (UINT8) (B_8237_DMA_CHMODE_INCREMENT | (ChannelNumber & 0x03));\r
1231 if (Read) {\r
1232 DmaMode |= V_8237_DMA_CHMODE_MEM2IO;\r
1233 } else {\r
1234 DmaMode |= V_8237_DMA_CHMODE_IO2MEM;\r
1235 }\r
1236\r
1237 if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_AUTO_INITIALIZE) {\r
1238 DmaMode |= B_8237_DMA_CHMODE_AE;\r
1239 }\r
1240\r
1241 if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_DEMAND_MODE) {\r
1242 DmaMode |= V_8237_DMA_CHMODE_DEMAND;\r
1243 }\r
1244\r
1245 if (ChannelAttributes & EFI_ISA_IO_SLAVE_DMA_ATTRIBUTE_SINGLE_MODE) {\r
1246 DmaMode |= V_8237_DMA_CHMODE_SINGLE;\r
1247 }\r
1248 //\r
1249 // A Slave DMA transfer can not cross a 64K boundary.\r
1250 // Compute *NumberOfBytes based on this restriction.\r
1251 //\r
1252 MaxNumberOfBytes = 0x10000 - ((UINT32) (*DeviceAddress) & 0xffff);\r
1253 if (*NumberOfBytes > MaxNumberOfBytes) {\r
1254 *NumberOfBytes = MaxNumberOfBytes;\r
1255 }\r
1256 //\r
1257 // Compute the values to program into the BaseAddress and Count registers\r
1258 // of the Slave DMA controller\r
1259 //\r
1260 if (ChannelNumber < 4) {\r
1261 BaseAddress = (UINT32) (*DeviceAddress);\r
1262 Count = (UINT16) (*NumberOfBytes - 1);\r
1263 } else {\r
1264 BaseAddress = (UINT32) (((UINT32) (*DeviceAddress) & 0xff0000) | (((UINT32) (*DeviceAddress) & 0xffff) >> 1));\r
1265 Count = (UINT16) ((*NumberOfBytes - 1) >> 1);\r
1266 }\r
1267 //\r
1268 // Program the DMA Write Single Mask Register for ChannelNumber\r
1269 // Clear the DMA Byte Pointer Register\r
1270 //\r
1271 if (ChannelNumber < 4) {\r
1272 DmaMask = R_8237_DMA_WRSMSK_CH0_3;\r
1273 DmaClear = R_8237_DMA_CBPR_CH0_3;\r
1274 DmaChannelMode = R_8237_DMA_CHMODE_CH0_3;\r
1275 } else {\r
1276 DmaMask = R_8237_DMA_WRSMSK_CH4_7;\r
1277 DmaClear = R_8237_DMA_CBPR_CH4_7;\r
1278 DmaChannelMode = R_8237_DMA_CHMODE_CH4_7;\r
1279 }\r
1280\r
1281 Status = WritePort (\r
1282 This,\r
1283 DmaMask,\r
1284 (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))\r
1285 );\r
1286 if (EFI_ERROR (Status)) {\r
1287 return Status;\r
1288 }\r
1289\r
1290 Status = WritePort (\r
1291 This,\r
1292 DmaClear,\r
1293 (UINT8) (B_8237_DMA_WRSMSK_CMS | (ChannelNumber & 0x03))\r
1294 );\r
1295 if (EFI_ERROR (Status)) {\r
1296 return Status;\r
1297 }\r
1298\r
1299 Status = WritePort (This, DmaChannelMode, DmaMode);\r
1300 if (EFI_ERROR (Status)) {\r
1301 return Status;\r
1302 }\r
1303\r
1304 Status = WriteDmaPort (\r
1305 This,\r
1306 DmaRegisters[ChannelNumber].Address,\r
1307 DmaRegisters[ChannelNumber].Page,\r
1308 DmaRegisters[ChannelNumber].Count,\r
1309 BaseAddress,\r
1310 Count\r
1311 );\r
1312 if (EFI_ERROR (Status)) {\r
1313 return Status;\r
1314 }\r
1315\r
1316 Status = WritePort (\r
1317 This,\r
1318 DmaMask,\r
1319 (UINT8) (ChannelNumber & 0x03)\r
1320 );\r
1321 if (EFI_ERROR (Status)) {\r
1322 return Status;\r
1323 }\r
1324\r
1325 return EFI_SUCCESS;\r
1326}\r
1327\r
bcd70414 1328/**\r
1329 Maps a memory region for DMA\r
1330\r
1331 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
1332 @param Operation - Indicates the type of DMA (slave or bus master), and if \r
1333 the DMA operation is going to read or write to system memory. \r
1334 @param ChannelNumber - The slave channel number to use for this DMA operation. \r
1335 If Operation and ChannelAttributes shows that this device \r
1336 performs bus mastering DMA, then this field is ignored. \r
1337 The legal range for this field is 0..7. \r
1338 @param ChannelAttributes - The attributes of the DMA channel to use for this DMA operation\r
1339 @param HostAddress - The system memory address to map to the device. \r
1340 @param NumberOfBytes - On input the number of bytes to map. On output the number \r
1341 of bytes that were mapped.\r
1342 @param DeviceAddress - The resulting map address for the bus master device to use \r
1343 - to access the hosts HostAddress. \r
1344 @param Mapping - A resulting value to pass to EFI_ISA_IO.Unmap().\r
1345\r
1346\r
1347 @retval EFI_SUCCESS - The range was mapped for the returned NumberOfBytes.\r
1348 @retval EFI_INVALID_PARAMETER - The Operation or HostAddress is undefined.\r
1349 @retval EFI_UNSUPPORTED - The HostAddress can not be mapped as a common buffer.\r
1350 @retval EFI_DEVICE_ERROR - The system hardware could not map the requested address.\r
1351 @retval EFI_OUT_OF_RESOURCES - The memory pages could not be allocated.\r
1352\r
1353**/\r
c3902377 1354EFI_STATUS\r
1355EFIAPI\r
1356IsaIoMap (\r
1357 IN EFI_ISA_IO_PROTOCOL *This,\r
1358 IN EFI_ISA_IO_PROTOCOL_OPERATION Operation,\r
1359 IN UINT8 ChannelNumber OPTIONAL,\r
1360 IN UINT32 ChannelAttributes,\r
1361 IN VOID *HostAddress,\r
1362 IN OUT UINTN *NumberOfBytes,\r
1363 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,\r
1364 OUT VOID **Mapping\r
1365 )\r
c3902377 1366\r
c3902377 1367{\r
1368 //\r
1369 // Or unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.\r
1370 //\r
1371 if (!FeaturePcdGet (PcdIsaBusSupportDma)) {\r
1372 return EFI_UNSUPPORTED;\r
1373 }\r
1374 //\r
1375 // Set Feature Flag PcdIsaBusSupportBusMaster to FALSE to disable support for \r
1376 // ISA Bus Master.\r
1377 //\r
1378 // So we just return EFI_UNSUPPORTED for these functions.\r
1379 //\r
1380 if (FeaturePcdGet (PcdIsaBusOnlySupportSlaveDma)) {\r
1381 return IsaIoMap_OnlySupportSlaveReadWrite (\r
1382 This,\r
1383 Operation,\r
1384 ChannelNumber,\r
1385 ChannelAttributes,\r
1386 HostAddress,\r
1387 NumberOfBytes,\r
1388 DeviceAddress,\r
1389 Mapping\r
1390 );\r
1391\r
1392 } else {\r
1393 return IsaIoMap_FullSupport (\r
1394 This,\r
1395 Operation,\r
1396 ChannelNumber,\r
1397 ChannelAttributes,\r
1398 HostAddress,\r
1399 NumberOfBytes,\r
1400 DeviceAddress,\r
1401 Mapping\r
1402 );\r
1403 }\r
1404}\r
bcd70414 1405\r
1406/**\r
1407 Allocates a common buffer for DMA\r
1408\r
1409 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
1410 @param Type - The type allocation to perform.\r
1411 @param MemoryType - The type of memory to allocate.\r
1412 @param Pages - The number of pages to allocate.\r
1413 @param HostAddress - A pointer to store the base address of the allocated range.\r
1414 @param Attributes - The requested bit mask of attributes for the allocated range.\r
1415\r
1416 @retval EFI_SUCCESS - The requested memory pages were allocated.\r
1417 @retval EFI_INVALID_PARAMETER - Type is invalid or MemoryType is invalid or HostAddress is NULL\r
1418 @retval EFI_UNSUPPORTED - Attributes is unsupported or the memory range specified \r
1419 by HostAddress, Pages, and Type is not available for common buffer use.\r
1420 @retval EFI_OUT_OF_RESOURCES - The memory pages could not be allocated.\r
1421\r
1422**/\r
c3902377 1423EFI_STATUS\r
1424EFIAPI\r
1425IsaIoAllocateBuffer (\r
1426 IN EFI_ISA_IO_PROTOCOL *This,\r
1427 IN EFI_ALLOCATE_TYPE Type,\r
1428 IN EFI_MEMORY_TYPE MemoryType,\r
1429 IN UINTN Pages,\r
1430 OUT VOID **HostAddress,\r
1431 IN UINT64 Attributes\r
1432 )\r
c3902377 1433{\r
1434 EFI_STATUS Status;\r
1435 EFI_PHYSICAL_ADDRESS PhysicalAddress;\r
1436\r
1437 //\r
1438 // Set Feature Flag PcdIsaBusOnlySupportSlaveDma to FALSE to disable support for \r
1439 // ISA Bus Master.\r
1440 // Or unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.\r
1441 //\r
1442 if (!FeaturePcdGet (PcdIsaBusSupportDma) || FeaturePcdGet (PcdIsaBusOnlySupportSlaveDma)) {\r
1443 return EFI_UNSUPPORTED;\r
1444 }\r
1445\r
1446 if (HostAddress == NULL) {\r
1447 return EFI_INVALID_PARAMETER;\r
1448 }\r
1449\r
1450 if (Type < AllocateAnyPages || Type >= MaxAllocateType) {\r
1451 return EFI_INVALID_PARAMETER;\r
1452 }\r
1453 //\r
1454 // The only valid memory types are EfiBootServicesData and EfiRuntimeServicesData\r
1455 //\r
1456 if (MemoryType != EfiBootServicesData && MemoryType != EfiRuntimeServicesData) {\r
1457 return EFI_INVALID_PARAMETER;\r
1458 }\r
1459\r
1460 if (Attributes &~(EFI_ISA_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE | EFI_ISA_IO_ATTRIBUTE_MEMORY_CACHED)) {\r
1461 return EFI_UNSUPPORTED;\r
1462 }\r
1463\r
1464 PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) (ISA_MAX_MEMORY_ADDRESS - 1);\r
1465 if (Type == AllocateAddress) {\r
1466 if ((UINTN) (*HostAddress) >= ISA_MAX_MEMORY_ADDRESS) {\r
1467 return EFI_UNSUPPORTED;\r
1468 } else {\r
1469 PhysicalAddress = (UINTN) (*HostAddress);\r
1470 }\r
1471 }\r
1472\r
1473 if (Type == AllocateAnyPages) {\r
1474 Type = AllocateMaxAddress;\r
1475 }\r
1476\r
1477 Status = gBS->AllocatePages (Type, MemoryType, Pages, &PhysicalAddress);\r
1478 if (EFI_ERROR (Status)) {\r
1479 ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r
1480 return Status;\r
1481 }\r
1482\r
1483 *HostAddress = (VOID *) (UINTN) PhysicalAddress;\r
1484 return Status;\r
1485}\r
1486\r
bcd70414 1487/**\r
c3902377 1488\r
1489 Frees a common buffer \r
1490\r
bcd70414 1491 @param This - A pointer to the EFI_ISA_IO_PROTOCOL instance.\r
1492 @param Pages - The number of pages to free.\r
1493 @param HostAddress - The base address of the allocated range.\r
c3902377 1494\r
c3902377 1495\r
bcd70414 1496 @retval EFI_SUCCESS - The requested memory pages were freed.\r
1497 @retval EFI_INVALID_PARAMETER - The memory was not allocated with EFI_ISA_IO.AllocateBufer().\r
c3902377 1498\r
bcd70414 1499**/\r
c3902377 1500\r
bcd70414 1501EFI_STATUS\r
1502EFIAPI\r
1503IsaIoFreeBuffer (\r
1504 IN EFI_ISA_IO_PROTOCOL *This,\r
1505 IN UINTN Pages,\r
1506 IN VOID *HostAddress\r
1507 )\r
c3902377 1508{\r
1509 EFI_STATUS Status;\r
1510 EFI_PHYSICAL_ADDRESS PhysicalAddress;\r
1511\r
1512 //\r
1513 // Set Feature Flag PcdIsaBusOnlySupportSlaveDma to FALSE to disable support for \r
1514 // ISA Bus Master.\r
1515 // Or unset Feature Flag PcdIsaBusSupportDma to disable support for ISA DMA.\r
1516 //\r
1517 if (!FeaturePcdGet (PcdIsaBusSupportDma) || FeaturePcdGet (PcdIsaBusOnlySupportSlaveDma)) {\r
1518 return EFI_UNSUPPORTED;\r
1519 }\r
1520\r
1521 PhysicalAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress;\r
1522 Status = gBS->FreePages (\r
1523 PhysicalAddress,\r
1524 Pages\r
1525 );\r
1526 if (EFI_ERROR (Status)) {\r
1527 ReportErrorStatusCode (EFI_IO_BUS_LPC | EFI_IOB_EC_CONTROLLER_ERROR);\r
1528 }\r
1529\r
1530 return Status;\r
1531}\r
1532\r