libpci: Add new direct HW access method intel-conf1-ext
Subsystems (2)
PATCH 1/1 libpci: Add new direct HW access method intel-conf1-ext
Introduce the intel-conf1-ext method, an extension of intel-conf1 that allows access to all PCIe registers, including the extended PCIe space starting at offset 0x100. This method utilizes four reserved bits above the bus bits to represent the extended PCIe registers.
Currently, on x86 architectures, this method is supported exclusively by AMD Family 10h-18h CPUs. Newer AMD CPUs require a setup that has not yet been documented by AMD and remains unknown. Intel CPUs do not support this method yet.
--- lib/i386-cpuid.h | 108 +++++++++++++++++++++ lib/i386-ports.c | 245 +++++++++++++++++++++++++++++++++++++++++++++-- lib/init.c | 6 ++ lib/internal.h | 2 +- lib/pci.h | 1 + pcilib.man | 4 + 6 files changed, 357 insertions(+), 9 deletions(-) create mode 100644 lib/i386-cpuid.h
lib/i386-cpuid.h new file +108 -0
@@ -0,0 +1,108 @@ +#if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || (__GNUC__ > 4)) + +/* + * GCC's cpuid.h header file is buggy and cannot be included more times. + * MinGW's intrin.h header file in some versions includes cpuid.h and + * therefore intrin.h and cpuid.h cannot be mixed in one source unit. + * libpci's i386-io-windows.h in some cases include intrin.h and therefore + * in some configurations it is not possible to include cpuid.h here again. + * GCC's cpuid.h since beginning define __cpuid macro, so it could be used + * as a include guard. But unfortunately MinGW-w64 since version 10.0.0 + * automatically undefine macro __cpuid in intrin.h. + */ +#if defined(__MINGW64_VERSION_MAJOR) && __MINGW64_VERSION_MAJOR >= 10 +#include <intrin.h> +#elif !defined(__cpuid) +#include <cpuid.h> +#endif +#ifndef __get_cpuid +#define __get_cpuid __get_cpuid +#endif + +#elif defined (__GNUC__) + +static inline int +__get_cpuid(unsigned int level, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) +{ +#ifndef __x86_64__ + /* cpuid does not have to be supported on 32-bit x86, check for it. */ + unsigned int eflags_orig, eflags_mod; + asm ( + "pushfl\n\t" + "pushfl\n\t" + "popl\t%0\n\t" + "movl\t%0, %1\n\t" + "xorl\t%2, %0\n\t" + "pushl\t%0\n\t" + "popfl\n\t" + "pushfl\n\t" + "popl\t%0\n\t" + "popfl\n\t" + : "=&r" (eflags_mod), "=&r" (eflags_orig) + : "i" (0x00200000) + ); + if (!((eflags_mod ^ eflags_orig) & 0x00200000)) + return 0; +#endif + + asm ("cpuid\n\t" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (level)); + return 1; +} +#define __get_cpuid __get_cpuid + +#elif defined(_MSC_VER) + +/* MSVC provides intrinsic __cpuid since version 14.00 included in VS2005. */ +#if _MSC_VER >= 1400 +#pragma intrinsic(__cpuid) +#else +static void +__cpuid(int CPUInfo[4], int InfoType) +{ + __asm { + mov esi, CPUInfo + mov eax, InfoType + xor ecx, ecx + _emit 0x0F __asm _emit 0xA2 /* cpuid */ + mov dword ptr [esi + 0], eax + mov dword ptr [esi + 4], ebx + mov dword ptr [esi + 8], ecx + mov dword ptr [esi + 12], edx + } +} +#endif +static inline int +__get_cpuid(unsigned int level, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) +{ + int regs[4]; + +#ifndef _M_AMD64 + /* cpuid does not have to be supported on 32-bit x86, check for it. */ + unsigned int eflags_orig, eflags_mod; + __asm { + pushfd + pushfd + pop eflags_orig + push eflags_orig + pop eflags_mod + xor eflags_mod, 0x00200000 + push eflags_mod + popfd + pushfd + pop eflags_mod + popfd + } + if (!((eflags_mod ^ eflags_orig) & 0x00200000)) + return 0; +#endif + + __cpuid(regs, level); + *eax = regs[0]; + *ebx = regs[1]; + *ecx = regs[2]; + *edx = regs[3]; + return 1; +} +#define __get_cpuid __get_cpuid + +#endif
lib/i386-ports.c +237 -8
314 lines not on this page · raw message
lib/init.c +6 -0
@@ -168,6 +168,11 @@ static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = {#else NULL,#endif +#ifdef PCI_HAVE_PM_INTEL_CONF + &pm_intel_conf1_ext, +#else + NULL, +#endif };// If PCI_ACCESS_AUTO is selected, we probe the access methods in this order
@@ -189,6 +194,7 @@ static int probe_sequence[] = {PCI_ACCESS_RT_THREAD_SMART_DM ,// Low-level methods poking the hardware directly PCI_ACCESS_ECAM , +PCI_ACCESS_I386_TYPE1_EXT ,PCI_ACCESS_I386_TYPE1 ,PCI_ACCESS_I386_TYPE2 , PCI_ACCESS_MMIO_TYPE1_EXT,
lib/internal.h +1 -1
@@ -141,7 +141,7 @@ void pci_free_params(struct pci_access *acc);void pci_scan_caps (struct pci_dev *,unsigned int want_fields);void pci_free_caps (struct pci_dev *); -extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_linux_proc, +extern struct pci_methods pm_intel_conf1_ext, pm_intel_conf1, pm_intel_conf2, pm_linux_proc, pm_fbsd_device, pm_aix_device, pm_nbsd_libpci, pm_obsd_device, pm_dump, pm_linux_sysfs, pm_darwin, pm_sylixos_device, pm_hurd, pm_mmio_conf1, pm_mmio_conf1_ext, pm_ecam,
lib/pci.h +1 -0
@@ -57,6 +57,7 @@ enum pci_access_type {PCI_ACCESS_ECAM ,/* PCIe ECAM via /dev/mem */ PCI_ACCESS_AOS_EXPANSION ,/* AmigaOS Expansion library */ PCI_ACCESS_RT_THREAD_SMART_DM ,/* RT-Thread Smart pci */ +PCI_ACCESS_I386_TYPE1_EXT ,/* i386 ports, type 1 extended */ PCI_ACCESS_MAX };
pcilib.man +4 -0
@@ -35,6 +35,10 @@ to all users, the rest only to root. Direct hardware access via Intel configuration mechanism 1. Available on i386 and compatibles on Linux, Solaris/x86, GNU Hurd, Windows, BeOS and Haiku. Requires root privileges. .TP +.B intel-conf1-ext +Direct hardware access via Extended PCIe Intel configuration mechanism 1. Available on +AMD Family 10h-18h CPUs. Requires root privileges. +.TP .B intel-conf2 Direct hardware access via Intel configuration mechanism 2. Available on i386 and compatibles on Linux, Solaris/x86, GNU Hurd, Windows, BeOS and Haiku. Requires root privileges. Warning: This method
Signature · 1 line
2.20.1
Hello!
Quoted 9 lines
Introduce the intel-conf1-ext method, an extension of intel-conf1 that allows access to all PCIe registers, including the extended PCIe space starting at offset
0x100. This method utilizes four reserved bits above the bus bits to represent the extended PCIe registers.Currently, on x86 architectures, this method is supported exclusively by AMD Family 10h-18h CPUs. Newer AMD CPUs require a setup that has not yet been documented by AMD and remains unknown. Intel CPUs do not support this method yet.
Thanks, I will apply it. However, the patch no longer applies to the current version. Could you please update it?
Martin
PATCH 1/1 libpci: Add new direct HW access method intel-conf1-ext
Introduce the intel-conf1-ext method, an extension of intel-conf1 that allows access to all PCIe registers, including the extended PCIe space starting at offset 0x100. This method utilizes four reserved bits above the bus bits to represent the extended PCIe registers.
Currently, on x86 architectures, this method is supported exclusively by AMD Family 10h-18h CPUs. Newer AMD CPUs require a setup that has not yet been documented by AMD and remains unknown. Intel CPUs do not support this method yet.
--- lib/i386-cpuid.h | 108 +++++++++++++++++++++ lib/i386-ports.c | 245 +++++++++++++++++++++++++++++++++++++++++++++-- lib/init.c | 6 ++ lib/internal.h | 2 +- lib/pci.h | 1 + pcilib.man | 4 + 6 files changed, 357 insertions(+), 9 deletions(-) create mode 100644 lib/i386-cpuid.h
lib/i386-cpuid.h new file +108 -0
@@ -0,0 +1,108 @@ +#if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || (__GNUC__ > 4)) + +/* + * GCC's cpuid.h header file is buggy and cannot be included more times. + * MinGW's intrin.h header file in some versions includes cpuid.h and + * therefore intrin.h and cpuid.h cannot be mixed in one source unit. + * libpci's i386-io-windows.h in some cases include intrin.h and therefore + * in some configurations it is not possible to include cpuid.h here again. + * GCC's cpuid.h since beginning define __cpuid macro, so it could be used + * as a include guard. But unfortunately MinGW-w64 since version 10.0.0 + * automatically undefine macro __cpuid in intrin.h. + */ +#if defined(__MINGW64_VERSION_MAJOR) && __MINGW64_VERSION_MAJOR >= 10 +#include <intrin.h> +#elif !defined(__cpuid) +#include <cpuid.h> +#endif +#ifndef __get_cpuid +#define __get_cpuid __get_cpuid +#endif + +#elif defined (__GNUC__) + +static inline int +__get_cpuid(unsigned int level, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) +{ +#ifndef __x86_64__ + /* cpuid does not have to be supported on 32-bit x86, check for it. */ + unsigned int eflags_orig, eflags_mod; + asm ( + "pushfl\n\t" + "pushfl\n\t" + "popl\t%0\n\t" + "movl\t%0, %1\n\t" + "xorl\t%2, %0\n\t" + "pushl\t%0\n\t" + "popfl\n\t" + "pushfl\n\t" + "popl\t%0\n\t" + "popfl\n\t" + : "=&r" (eflags_mod), "=&r" (eflags_orig) + : "i" (0x00200000) + ); + if (!((eflags_mod ^ eflags_orig) & 0x00200000)) + return 0; +#endif + + asm ("cpuid\n\t" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (level)); + return 1; +} +#define __get_cpuid __get_cpuid + +#elif defined(_MSC_VER) + +/* MSVC provides intrinsic __cpuid since version 14.00 included in VS2005. */ +#if _MSC_VER >= 1400 +#pragma intrinsic(__cpuid) +#else +static void +__cpuid(int CPUInfo[4], int InfoType) +{ + __asm { + mov esi, CPUInfo + mov eax, InfoType + xor ecx, ecx + _emit 0x0F __asm _emit 0xA2 /* cpuid */ + mov dword ptr [esi + 0], eax + mov dword ptr [esi + 4], ebx + mov dword ptr [esi + 8], ecx + mov dword ptr [esi + 12], edx + } +} +#endif +static inline int +__get_cpuid(unsigned int level, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) +{ + int regs[4]; + +#ifndef _M_AMD64 + /* cpuid does not have to be supported on 32-bit x86, check for it. */ + unsigned int eflags_orig, eflags_mod; + __asm { + pushfd + pushfd + pop eflags_orig + push eflags_orig + pop eflags_mod + xor eflags_mod, 0x00200000 + push eflags_mod + popfd + pushfd + pop eflags_mod + popfd + } + if (!((eflags_mod ^ eflags_orig) & 0x00200000)) + return 0; +#endif + + __cpuid(regs, level); + *eax = regs[0]; + *ebx = regs[1]; + *ecx = regs[2]; + *edx = regs[3]; + return 1; +} +#define __get_cpuid __get_cpuid + +#endif
lib/i386-ports.c +237 -8
314 lines not on this page · raw message
lib/init.c +6 -0
@@ -173,6 +173,11 @@ static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = {#else NULL,#endif +#ifdef PCI_HAVE_PM_INTEL_CONF + &pm_intel_conf1_ext, +#else + NULL, +#endif };// If PCI_ACCESS_AUTO is selected, we probe the access methods in this order
@@ -195,6 +200,7 @@ static int probe_sequence[] = {PCI_ACCESS_MINIOS ,// Low-level methods poking the hardware directly PCI_ACCESS_ECAM , +PCI_ACCESS_I386_TYPE1_EXT ,PCI_ACCESS_I386_TYPE1 ,PCI_ACCESS_I386_TYPE2 , PCI_ACCESS_MMIO_TYPE1_EXT,
lib/internal.h +1 -1
@@ -141,7 +141,7 @@ void pci_free_params(struct pci_access *acc);void pci_scan_caps (struct pci_dev *,unsigned int want_fields);void pci_free_caps (struct pci_dev *); -extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_linux_proc, +extern struct pci_methods pm_intel_conf1_ext, pm_intel_conf1, pm_intel_conf2, pm_linux_proc, pm_fbsd_device, pm_aix_device, pm_nbsd_libpci, pm_obsd_device, pm_dump, pm_linux_sysfs, pm_darwin, pm_sylixos_device, pm_hurd, pm_mmio_conf1, pm_mmio_conf1_ext, pm_ecam,
lib/pci.h +1 -0
@@ -58,6 +58,7 @@ enum pci_access_type {PCI_ACCESS_AOS_EXPANSION ,/* AmigaOS Expansion library */ PCI_ACCESS_RT_THREAD_SMART_DM ,/* RT-Thread Smart pci */ PCI_ACCESS_MINIOS ,/* Xen MiniOS */ +PCI_ACCESS_I386_TYPE1_EXT ,/* i386 ports, type 1 extended */ PCI_ACCESS_MAX };
pcilib.man +4 -0
@@ -35,6 +35,10 @@ to all users, the rest only to root. Direct hardware access via Intel configuration mechanism 1. Available on i386 and compatibles on Linux, Solaris/x86, GNU Hurd, Windows, BeOS and Haiku. Requires root privileges. .TP +.B intel-conf1-ext +Direct hardware access via Extended PCIe Intel configuration mechanism 1. Available on +AMD Family 10h-18h CPUs. Requires root privileges. +.TP .B intel-conf2 Direct hardware access via Intel configuration mechanism 2. Available on i386 and compatibles on Linux, Solaris/x86, GNU Hurd, Windows, BeOS and Haiku. Requires root privileges. Warning: This method
Signature · 1 line
2.20.1
Martin Mareš
AppliedHi!
Quoted 9 lines
Introduce the intel-conf1-ext method, an extension of intel-conf1 that allows access to all PCIe registers, including the extended PCIe space starting at offset
0x100. This method utilizes four reserved bits above the bus bits to represent the extended PCIe registers.Currently, on x86 architectures, this method is supported exclusively by AMD Family 10h-18h CPUs. Newer AMD CPUs require a setup that has not yet been documented by AMD and remains unknown. Intel CPUs do not support this method yet.
Thanks, applied.
Martin