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