From 3d83b3b2ce20595b80c5575ce403e2d55da7b7a1 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 26 Jul 2010 21:07:04 +0000 Subject: [PATCH] - Add PciIo headers. --- gnu-efi-3.0e-add-pciio.patch | 66 +++++--- gnu-efi-3.0e-add-uefi-2.x-boot-services.patch | 25 ++- gnu-efi-3.0e-route80h.patch | 159 ++++++++++++++++++ gnu-efi.spec | 4 +- 4 files changed, 223 insertions(+), 31 deletions(-) create mode 100644 gnu-efi-3.0e-route80h.patch diff --git a/gnu-efi-3.0e-add-pciio.patch b/gnu-efi-3.0e-add-pciio.patch index 80c8bdf..ea04316 100644 --- a/gnu-efi-3.0e-add-pciio.patch +++ b/gnu-efi-3.0e-add-pciio.patch @@ -1,12 +1,14 @@ -From 5c79e84d2f7740b2da84364f80a577b904f12b34 Mon Sep 17 00:00:00 2001 +From 4547a096f10ea8b2164f895a10f2dbe9e1269c22 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Mon, 26 Jul 2010 14:25:47 -0400 -Subject: [PATCH 1/2] Add headers for PciIo . +Subject: [PATCH] Add headers for PciIo . --- inc/efi.h | 1 + + inc/efilib.h | 1 + inc/efipciio.h | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - 2 files changed, 220 insertions(+), 0 deletions(-) + lib/data.c | 1 + + 4 files changed, 222 insertions(+), 0 deletions(-) create mode 100644 inc/efipciio.h diff --git a/inc/efi.h b/inc/efi.h @@ -21,16 +23,28 @@ index 4cdb12b..e9de37b 100644 #include "efiprot.h" #include "eficon.h" #include "efiser.h" +diff --git a/inc/efilib.h b/inc/efilib.h +index 82c332a..740c2ff 100644 +--- a/inc/efilib.h ++++ b/inc/efilib.h +@@ -58,6 +58,7 @@ extern EFI_GUID PxeCallbackProtocol; + extern EFI_GUID NetworkInterfaceIdentifierProtocol; + extern EFI_GUID UiProtocol; + extern EFI_GUID InternalShellProtocol; ++extern EFI_GUID PciIoProtocol; + + extern EFI_GUID EfiGlobalVariable; + extern EFI_GUID GenericFileInfo; diff --git a/inc/efipciio.h b/inc/efipciio.h new file mode 100644 -index 0000000..d5e818a +index 0000000..0724f95 --- /dev/null +++ b/inc/efipciio.h @@ -0,0 +1,219 @@ +#ifndef _EFI_PCI_IO_H +#define _EFI_PCI_IO_H + -+#define PCI_IO_PROTOCOL \ ++#define EFI_PCI_IO_PROTOCOL \ + { 0x4cf5b200, 0x68b8, 0x4ca5, {0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a} } + +INTERFACE_DECL(_EFI_PCI_IO); @@ -56,7 +70,7 @@ index 0000000..d5e818a +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_POLL_IO_MEM) ( -+ IN EFI_PCI_IO_PROTOCOL *This, ++ IN struct _EFI_PCI_IO *This, + IN EFI_PCI_IO_PROTOCOL_WIDTH Width, + IN UINT8 BarIndex, + IN UINT64 Offset, @@ -69,7 +83,7 @@ index 0000000..d5e818a +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_IO_MEM) ( -+ IN EFI_PCI_IO_PROTOCOL *This, ++ IN struct _EFI_PCI_IO *This, + IN EFI_PCI_IO_PROTOCOL_WIDTH Width, + IN UINT8 BarIndex, + IN UINT64 Offset, @@ -85,7 +99,7 @@ index 0000000..d5e818a +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_CONFIG) ( -+ IN EFI_PCI_IO_PROTOCOL *This, ++ IN struct _EFI_PCI_IO *This, + IN EFI_PCI_IO_PROTOCOL_WIDTH Width, + IN UINT32 Offset, + IN UINTN Count, @@ -100,7 +114,7 @@ index 0000000..d5e818a +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_COPY_MEM) ( -+ IN EFI_PCI_IO_PROTOCOL *This, ++ IN struct _EFI_PCI_IO *This, + IN EFI_PCI_IO_PROTOCOL_WIDTH Width, + IN UINT8 DestBarIndex, + IN UINT64 DestOffset, @@ -119,7 +133,7 @@ index 0000000..d5e818a +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_MAP) ( -+ IN EFI_PCI_IO_PROTOCOL *This, ++ IN struct _EFI_PCI_IO *This, + IN EFI_PCI_IO_PROTOCOL_OPERATION Operation, + IN VOID *HostAddress, + IN OUT UINTN *NumberOfBytes, @@ -130,14 +144,14 @@ index 0000000..d5e818a +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_UNMAP) ( -+ IN EFI_PCI_IO_PROTOCOL *This, ++ IN struct _EFI_PCI_IO *This, + IN VOID *Mapping +); + +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_ALLOCATE_BUFFER) ( -+ IN EFI_PCI_IO_PROTOCOL *This, ++ IN struct _EFI_PCI_IO *This, + IN EFI_ALLOCATE_TYPE Type, + IN EFI_MEMORY_TYPE MemoryType, + IN UINTN Pages, @@ -148,7 +162,7 @@ index 0000000..d5e818a +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_FREE_BUFFER) ( -+ IN EFI_PCI_IO_PROTOCOL *This, ++ IN struct _EFI_PCI_IO *This, + IN UINTN Pages, + IN VOID *HostAddress + ); @@ -156,13 +170,13 @@ index 0000000..d5e818a +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_FLUSH) ( -+ IN EFI_PCI_IO_PROTOCOL *This ++ IN struct _EFI_PCI_IO *This + ); + +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_GET_LOCATION) ( -+ IN EFI_PCI_IO_PROTOCOL *This, ++ IN struct _EFI_PCI_IO *This, + OUT UINTN *SegmentNumber, + OUT UINTN *BusNumber, + OUT UINTN *DeviceNumber, @@ -200,7 +214,7 @@ index 0000000..d5e818a +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_ATTRIBUTES) ( -+ IN EFI_PCI_IO_PROTOCOL *This, ++ IN struct _EFI_PCI_IO *This, + IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation, + IN UINT64 Attributes, + OUT UINT64 *Result OPTIONAL @@ -209,7 +223,7 @@ index 0000000..d5e818a +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_GET_BAR_ATTRIBUTES) ( -+ IN EFI_PCI_IO_PROTOCOL *This, ++ IN struct _EFI_PCI_IO *This, + IN UINT8 BarIndex, + OUT UINT64 *Supports OPTIONAL, + OUT VOID **Resources OPTIONAL @@ -218,14 +232,14 @@ index 0000000..d5e818a +typedef +EFI_STATUS +(EFIAPI *EFI_PCI_IO_PROTOCOL_SET_BAR_ATTRIBUTES) ( -+ IN EFI_PCI_IO_PROTOCOL *This, ++ IN struct _EFI_PCI_IO *This, + IN UINT64 Attributes, + IN UINT8 BarIndex, + IN OUT UINT64 *Offset, + IN OUT UINT64 *Length + ); + -+typedef struct _EFI_PCI_IO_PROTOCOL { ++typedef struct _EFI_PCI_IO { + EFI_PCI_IO_PROTOCOL_POLL_IO_MEM PollMem; + EFI_PCI_IO_PROTOCOL_POLL_IO_MEM PollIo; + EFI_PCI_IO_PROTOCOL_ACCESS Mem; @@ -243,9 +257,21 @@ index 0000000..d5e818a + EFI_PCI_IO_PROTOCOL_SET_BAR_ATTRIBUTES SetBarAttributes; + UINT64 RomSize; + VOID *RomImage; -+} EFI_PCI_IO_PROTOCOL; ++} EFI_PCI_IO; + +#endif /* _EFI_PCI_IO_H */ +diff --git a/lib/data.c b/lib/data.c +index 402c54d..bcb2d67 100644 +--- a/lib/data.c ++++ b/lib/data.c +@@ -103,6 +103,7 @@ EFI_GUID PxeBaseCodeProtocol = EFI_PXE_BASE_CODE_PROTOCOL; + EFI_GUID PxeCallbackProtocol = EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL; + EFI_GUID NetworkInterfaceIdentifierProtocol = EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL; + EFI_GUID UiProtocol = EFI_UI_PROTOCOL; ++EFI_GUID PciIoProtocol = EFI_PCI_IO_PROTOCOL; + // + // File system information IDs + // -- 1.7.1.1 diff --git a/gnu-efi-3.0e-add-uefi-2.x-boot-services.patch b/gnu-efi-3.0e-add-uefi-2.x-boot-services.patch index 1e18ddc..65c79bf 100644 --- a/gnu-efi-3.0e-add-uefi-2.x-boot-services.patch +++ b/gnu-efi-3.0e-add-uefi-2.x-boot-services.patch @@ -1,17 +1,17 @@ -From 896d31cb20f831c28edba7d96413900a3ac8fde3 Mon Sep 17 00:00:00 2001 +From 05b13861f78a9f20e5902fc37cac4564d430fd35 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Fri, 23 Jul 2010 16:07:13 -0400 Subject: [PATCH] Add the UEFI 2.x bits for EFI_BOOT_SERVICES --- - inc/efiapi.h | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- - 1 files changed, 168 insertions(+), 6 deletions(-) + inc/efiapi.h | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- + 1 files changed, 175 insertions(+), 6 deletions(-) diff --git a/inc/efiapi.h b/inc/efiapi.h -index 888e052..812d8b4 100644 +index 888e052..5e47324 100644 --- a/inc/efiapi.h +++ b/inc/efiapi.h -@@ -412,6 +412,140 @@ EFI_STATUS +@@ -412,6 +412,147 @@ EFI_STATUS IN CHAR16 *WatchdogData OPTIONAL ); @@ -32,6 +32,13 @@ index 888e052..812d8b4 100644 + IN EFI_HANDLE ChildHandle OPTIONAL + ); + ++#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001 ++#define EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002 ++#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL 0x00000004 ++#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008 ++#define EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010 ++#define EFI_OPEN_PROTOCOL_EXCLUSIVE 0x00000020 ++ +typedef +EFI_STATUS +(EFIAPI *EFI_OPEN_PROTOCOL) ( @@ -145,14 +152,14 @@ index 888e052..812d8b4 100644 + IN UINT32 Type, + IN EFI_TPL NotifyTpl, + IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL, -+ IN CONST VOID *NotifyContext OPTIONAL, -+ IN CONST EFI_GUID EventGroup OPTIONAL, ++ IN const VOID *NotifyContext OPTIONAL, ++ IN const EFI_GUID EventGroup OPTIONAL, + OUT EFI_EVENT *Event + ); typedef enum { EfiResetCold, -@@ -491,12 +625,6 @@ EFI_STATUS +@@ -491,12 +632,6 @@ EFI_STATUS OUT VOID **Registration ); @@ -165,7 +172,7 @@ index 888e052..812d8b4 100644 typedef EFI_STATUS (EFIAPI *EFI_LOCATE_HANDLE) ( -@@ -655,6 +783,40 @@ typedef struct _EFI_BOOT_SERVICES { +@@ -655,6 +790,40 @@ typedef struct _EFI_BOOT_SERVICES { EFI_STALL Stall; EFI_SET_WATCHDOG_TIMER SetWatchdogTimer; diff --git a/gnu-efi-3.0e-route80h.patch b/gnu-efi-3.0e-route80h.patch new file mode 100644 index 0000000..d3b4c49 --- /dev/null +++ b/gnu-efi-3.0e-route80h.patch @@ -0,0 +1,159 @@ +From 796ce7f03ed606a801b6a23384e8cf4a13c46fc6 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Mon, 26 Jul 2010 17:04:12 -0400 +Subject: [PATCH] Add the "route80h.efi" test program. + +This is a test program for PciIo. It routes port80h on ICH10 to PCI. +--- + apps/Makefile | 2 +- + apps/route80h.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 126 insertions(+), 1 deletions(-) + create mode 100644 apps/route80h.c + +diff --git a/apps/Makefile b/apps/Makefile +index 44122ad..2baf64d 100644 +--- a/apps/Makefile ++++ b/apps/Makefile +@@ -38,7 +38,7 @@ LDFLAGS += -T $(LDSCRIPT) -shared -Bsymbolic -L../lib -L../gnuefi $(CRTOBJS) + LOADLIBES = -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name) + FORMAT = efi-app-$(ARCH) + +-TARGETS = t.efi t2.efi t3.efi t4.efi t5.efi t6.efi printenv.efi t7.efi ++TARGETS = t.efi t2.efi t3.efi t4.efi t5.efi t6.efi printenv.efi t7.efi route80h.efi + + all: $(TARGETS) + +diff --git a/apps/route80h.c b/apps/route80h.c +new file mode 100644 +index 0000000..05cc883 +--- /dev/null ++++ b/apps/route80h.c +@@ -0,0 +1,125 @@ ++#include ++#include ++ ++/* this example program changes the Reserved Page Route (RPR) bit on ICH10's General ++ * Control And Status Register (GCS) from LPC to PCI. In practical terms, it routes ++ * outb to port 80h to the PCI bus. */ ++ ++#define GCS_OFFSET_ADDR 0x3410 ++#define GCS_RPR_SHIFT 2 ++#define GCS_RPR_PCI 1 ++#define GCS_RPR_LPC 0 ++ ++#define VENDOR_ID_INTEL 0x8086 ++#define DEVICE_ID_LPCIF 0x3a16 ++ ++static EFI_HANDLE ImageHandle; ++ ++typedef struct { ++ uint16_t vendor_id; /* 00-01 */ ++ uint16_t device_id; /* 02-03 */ ++ char pad[0xEB]; /* 04-EF */ ++ uint32_t rcba; /* F0-F3 */ ++ uint32_t reserved[3]; /* F4-FF */ ++} lpcif_t; ++ ++static inline void set_bit(volatile uint32_t *flag, int bit, int value) ++{ ++ uint32_t val = *flag; ++ Print(L"current value is 0x%2x\n", val); ++ ++ if (value) { ++ val |= (1 << bit); ++ } else { ++ val &= ~(1 << bit); ++ } ++ Print(L"setting value to 0x%2x\n", val); ++ *flag = val; ++ val = *flag; ++ Print(L"new value is 0x%2x\n", val); ++} ++ ++static inline int configspace_matches_ids(void *config, uint32_t vendor_id, ++ uint32_t device_id) ++{ ++ uint32_t *cfg = config; ++ if (cfg[0] == vendor_id && cfg[1] == device_id) ++ return 1; ++ return 0; ++} ++ ++static int is_device(EFI_PCI_IO *pciio, uint16_t vendor_id, uint16_t device_id) ++{ ++ lpcif_t lpcif; ++ EFI_STATUS rc; ++ ++ rc = uefi_call_wrapper(pciio->Pci.Read, 5, pciio, EfiPciIoWidthUint16, 0, 2, &lpcif); ++ if (EFI_ERROR(rc)) ++ return 0; ++ ++ if (vendor_id == lpcif.vendor_id && device_id == lpcif.device_id) ++ return 1; ++ return 0; ++} ++ ++static EFI_STATUS find_pci_device(uint16_t vendor_id, uint16_t device_id, ++ EFI_PCI_IO **pciio) ++{ ++ EFI_STATUS rc; ++ EFI_HANDLE *Handles; ++ UINTN NoHandles; ++ int i; ++ ++ rc = LibLocateHandle(ByProtocol, &PciIoProtocol, NULL, &NoHandles, ++ &Handles); ++ if (EFI_ERROR(rc)) ++ return rc; ++ ++ for (i = 0; i < NoHandles; i++) { ++ rc = uefi_call_wrapper(BS->OpenProtocol, 6, Handles[i], ++ &PciIoProtocol, pciio, ImageHandle, ++ NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); ++ if (EFI_ERROR(rc)) ++ continue; ++ if (!is_device(*pciio, vendor_id, device_id)) ++ continue; ++ ++ return EFI_SUCCESS; ++ } ++ return EFI_NOT_FOUND; ++} ++ ++EFI_STATUS ++efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab) ++{ ++ InitializeLib(image_handle, systab); ++ EFI_PCI_IO *pciio; ++ lpcif_t lpcif; ++ EFI_STATUS rc; ++ ++ ImageHandle = image_handle; ++ rc = find_pci_device(VENDOR_ID_INTEL, DEVICE_ID_LPCIF, &pciio); ++ ++ if (rc == EFI_NOT_FOUND) { ++ Print(L"Device not found.\n"); ++ return rc; ++ } else if (EFI_ERROR(rc)) { ++ return rc; ++ } ++ ++ rc = uefi_call_wrapper(pciio->Pci.Read, 5, pciio, EfiPciIoWidthUint32, ++ EFI_FIELD_OFFSET(lpcif_t, rcba), 1, &lpcif.rcba); ++ if (EFI_ERROR(rc)) ++ return rc; ++ if (!(lpcif.rcba & 1)) { ++ Print(L"rcrb is not mapped, cannot route port 80h\n"); ++ return EFI_UNSUPPORTED; ++ } ++ lpcif.rcba &= ~1UL; ++ ++ Print(L"rcba: 0x%8x\n", lpcif.rcba, lpcif.rcba); ++ set_bit((uint32_t *)(lpcif.rcba + GCS_OFFSET_ADDR), ++ GCS_RPR_SHIFT, GCS_RPR_PCI); ++ ++ return EFI_SUCCESS; ++} +-- +1.7.1.1 + diff --git a/gnu-efi.spec b/gnu-efi.spec index 152ba45..9c96cab 100644 --- a/gnu-efi.spec +++ b/gnu-efi.spec @@ -11,8 +11,9 @@ Patch1: gnu-efi-3.0e-Fix-usage-of-INSTALLROOT-PREFIX-and-LIBDIR.patch Patch2: gnu-efi-3.0e-ignore-gnu-stack.patch Patch3: gnu-efi-3.0e-add-uefi-2.x-boot-services.patch Patch4: gnu-efi-3.0e-add-pciio.patch +Patch5: gnu-efi-3.0e-route80h.patch # "git am" doesn't like ms-dos formatted text-files. -#Patch5: gnu-efi-3.0e-add-pciio-2.patch +#Patch6: gnu-efi-3.0e-add-pciio-2.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) ExclusiveArch: i686 x86_64 ia64 BuildRequires: git @@ -31,7 +32,6 @@ git config user.name "Fedora Ninjas" git add . git commit -a -q -m "%{version} baseline." git am %{patches} -exit 1 %build # Package cannot build with %{?_smp_mflags}.