Home | History | Annotate | Line # | Download | only in lib
      1 /*	$NetBSD: hw.c,v 1.3 2018/08/16 18:22:05 jmcneill Exp $	*/
      2 
      3 /*++
      4 
      5 Copyright (c) 1998  Intel Corporation
      6 
      7 Module Name:
      8 
      9     hw.c
     10 
     11 Abstract:
     12 
     13     Debug library functions for Hardware IO access
     14 
     15 
     16 
     17 Revision History
     18 
     19 --*/
     20 
     21 #include "lib.h"
     22 
     23 
     24 EFI_STATUS
     25 InitializeGlobalIoDevice (
     26         IN  EFI_DEVICE_PATH             *DevicePath,
     27         IN  EFI_GUID                    *Protocol,
     28         IN  CHAR8                       *ErrorStr EFI_UNUSED,
     29         OUT EFI_DEVICE_IO_INTERFACE     **GlobalIoFncs
     30         )
     31 /*++
     32 
     33 Routine Description:
     34 
     35     Check to see if DevicePath exists for a given Protocol. Return Error if it
     36     exists. Return GlobalIoFuncs set match the DevicePath
     37 
     38   Arguments:
     39 
     40     DevicePath      - to operate on
     41     Protocol        - to check the DevicePath against
     42     ErrorStr        - ASCII string to display on error
     43     GlobalIoFncs    - Returned with DeviceIoProtocol for the DevicePath
     44 
     45 Returns:
     46 
     47     Pass or Fail based on  wether GlobalIoFncs where found
     48 
     49 --*/
     50 {
     51     EFI_STATUS      Status;
     52     EFI_HANDLE      Handle;
     53 
     54     //
     55     // Check to see if this device path already has Protocol on it.
     56     //  if so we are loading recursivly and should exit with an error
     57     //
     58     Status = uefi_call_wrapper(BS->LocateDevicePath, 3, Protocol, &DevicePath, &Handle);
     59     if (!EFI_ERROR(Status)) {
     60         DEBUG ((D_INIT, "Device Already Loaded for %a device\n", ErrorStr));
     61         return EFI_LOAD_ERROR;
     62     }
     63 
     64     Status = uefi_call_wrapper(BS->LocateDevicePath, 3, &DeviceIoProtocol, &DevicePath, &Handle);
     65     if (!EFI_ERROR(Status)) {
     66         Status = uefi_call_wrapper(BS->HandleProtocol, 3, Handle, &DeviceIoProtocol, (VOID*)GlobalIoFncs);
     67     }
     68 
     69     ASSERT (!EFI_ERROR(Status));
     70     return Status;
     71 }
     72 
     73 UINT32
     74 ReadPort (
     75         IN  EFI_DEVICE_IO_INTERFACE     *GlobalIoFncs,
     76         IN  EFI_IO_WIDTH                Width,
     77         IN  UINTN                       Port
     78         )
     79 {
     80     UINT32       Data;
     81     EFI_STATUS  Status EFI_UNUSED;
     82 
     83     Status = uefi_call_wrapper(GlobalIoFncs->Io.Read, 5, GlobalIoFncs, Width, (UINT64)Port, 1, &Data);
     84     ASSERT(!EFI_ERROR(Status));
     85     return Data;
     86 }
     87 
     88 UINT32
     89 WritePort (
     90         IN  EFI_DEVICE_IO_INTERFACE     *GlobalIoFncs,
     91         IN  EFI_IO_WIDTH                Width,
     92         IN  UINTN                       Port,
     93         IN  UINTN                       Data
     94         )
     95 {
     96     EFI_STATUS  Status EFI_UNUSED;
     97 
     98     Status = uefi_call_wrapper(GlobalIoFncs->Io.Write, 5, GlobalIoFncs, Width, (UINT64)Port, 1, &Data);
     99     ASSERT(!EFI_ERROR(Status));
    100     return (UINT32)Data;
    101 }
    102 
    103 UINT32
    104 ReadPciConfig (
    105         IN  EFI_DEVICE_IO_INTERFACE     *GlobalIoFncs,
    106         IN  EFI_IO_WIDTH                Width,
    107         IN  UINTN                       Address
    108         )
    109 {
    110     UINT32       Data;
    111     EFI_STATUS  Status EFI_UNUSED;
    112 
    113     Status = uefi_call_wrapper(GlobalIoFncs->Pci.Read, 5, GlobalIoFncs, Width, (UINT64)Address, 1, &Data);
    114     ASSERT(!EFI_ERROR(Status));
    115     return Data;
    116 }
    117 
    118 UINT32
    119 WritePciConfig (
    120         IN  EFI_DEVICE_IO_INTERFACE     *GlobalIoFncs,
    121         IN  EFI_IO_WIDTH                Width,
    122         IN  UINTN                       Address,
    123         IN  UINTN                       Data
    124         )
    125 {
    126     EFI_STATUS  Status EFI_UNUSED;
    127 
    128     Status = uefi_call_wrapper(GlobalIoFncs->Pci.Write, 5, GlobalIoFncs, Width, (UINT64)Address, 1, &Data);
    129     ASSERT(!EFI_ERROR(Status));
    130     return (UINT32)Data;
    131 }
    132 
    133 
    134 
    135