From 727a11c9127261bac0be317d2ad8f4865bcdac3d Mon Sep 17 00:00:00 2001 From: jumkey Date: Fri, 19 May 2023 11:34:04 +0800 Subject: [PATCH] gleaning --- compat/toolkit/drivers/pci/pci.h | 30 ++++++++++++++++++++++++++++++ internal/uart/uart_swapper.c | 2 +- internal/virtual_pci.c | 7 +++++-- shim/bios_shim.c | 2 ++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 compat/toolkit/drivers/pci/pci.h diff --git a/compat/toolkit/drivers/pci/pci.h b/compat/toolkit/drivers/pci/pci.h new file mode 100644 index 0000000..cd87ed4 --- /dev/null +++ b/compat/toolkit/drivers/pci/pci.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef REDPILL_PCI_H +#define REDPILL_PCI_H + +#warning "Using compatibility file for drivers/pci/pci.h - if possible do NOT compile using toolkit" + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0) && LINUX_VERSION_CODE < KERNEL_VERSION(4,20,0) //v4.18 - v4.20 +/* pci_dev priv_flags */ +#define PCI_DEV_ADDED 1 + +static inline bool pci_dev_is_added(const struct pci_dev *dev) +{ + return test_bit(PCI_DEV_ADDED, &dev->priv_flags); +} + +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,0) && LINUX_VERSION_CODE < KERNEL_VERSION(6,0,0) //v4.20 - v6.0 +#define PCI_DEV_ADDED 0 + +static inline bool pci_dev_is_added(const struct pci_dev *dev) +{ + return test_bit(PCI_DEV_ADDED, &dev->priv_flags); +} +#else +static inline bool pci_dev_is_added(const struct pci_dev *dev) +{ + return 1 == dev->is_added; +} +#endif //LINUX_VERSION_CODE check + +#endif /* REDPILL_PCI_H */ diff --git a/internal/uart/uart_swapper.c b/internal/uart/uart_swapper.c index 28e4991..8e5a745 100644 --- a/internal/uart/uart_swapper.c +++ b/internal/uart/uart_swapper.c @@ -373,7 +373,7 @@ static inline void restart_port(struct uart_8250_port *up) // because we did swap IRQ values. However, we MUST restart such port not to reinit the hardware (which doesn't // care) but to fix the interrupt mapping in the kernel! //skip extensive tests - it was working before -#if LINUX_VERSION_CODE <= KERNEL_VERSION(5,0,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) port->flags |= UPF_NO_TXEN_TEST; #else port->quirks |= UPQ_NO_TXEN_TEST; diff --git a/internal/virtual_pci.c b/internal/virtual_pci.c index 6b7905c..72dd99f 100644 --- a/internal/virtual_pci.c +++ b/internal/virtual_pci.c @@ -176,6 +176,9 @@ #include //Constants for vendors, classes, and other #include //list_for_each #include //device_del +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0) +#include <../drivers/pci/pci.h> //pci_dev_is_added +#endif #define PCIBUS_VIRTUAL_DOMAIN 0x0001 //normal PC buses are (always?) on domain 0, this is just a next one #define PCI_DEVICE_NOT_FOUND_VID_DID 0xFFFFFFFF //A special case to detect non-existing devices (per PCI spec) @@ -545,10 +548,10 @@ int vpci_remove_all_devices_and_buses(void) for_each_bus_idx() { list_for_each_entry_safe(pci_dev, pci_dev_n, &buses[i]->devices, bus_list) { pr_loc_dbg("Detaching vDEV dev=%02x fn=%02x from bus=%02x [add=%d]", PCI_SLOT(pci_dev->devfn), -#if LINUX_VERSION_CODE <= KERNEL_VERSION(5,0,0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,18,0) PCI_FUNC(pci_dev->devfn), buses[i]->number, pci_dev->is_added); #else - PCI_FUNC(pci_dev->devfn), buses[i]->number, 0); // Not found a replacement for pci_dev->is_added + PCI_FUNC(pci_dev->devfn), buses[i]->number, pci_dev_is_added(pci_dev)); #endif pci_stop_and_remove_bus_device(pci_dev); } diff --git a/shim/bios_shim.c b/shim/bios_shim.c index 55f7c34..48d7656 100644 --- a/shim/bios_shim.c +++ b/shim/bios_shim.c @@ -348,10 +348,12 @@ static int _apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab, unsigned val -= (u64)loc; *(u32 *)loc = val; break; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,20,0) case R_X86_64_PC64: val -= (u64)loc; *(u64 *)loc = val; break; +#endif default: pr_err("%s: Unknown rela relocation: %llu\n", me->name, ELF64_R_TYPE(rel[i].r_info));