Skip to content

Commit

Permalink
Address issue chipsec#249
Browse files Browse the repository at this point in the history
changed drivers/linux/include/chipsec.h to start from 'C'
added logic to compute ioctl base based upon changes to chipsec.h above
  • Loading branch information
BrentHoltsclaw committed Jan 7, 2019
1 parent cf1f58d commit 522fbb7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
20 changes: 18 additions & 2 deletions chipsec/helper/linux/helper.py
Expand Up @@ -82,7 +82,6 @@
Tiano = efi_compressor.TianoDecompress
EFI = efi_compressor.EfiDecompress


class MemoryMapping(mmap.mmap):
"""Memory mapping based on Python's mmap.
Expand Down Expand Up @@ -218,7 +217,7 @@ def init(self, start_driver):
except BaseException as be:
raise OsHelperError("Unable to open chipsec device. Did you run as root/sudo and load the driver?\n %s"%str(be),errno.ENXIO)

self._ioctl_base = fcntl.ioctl(self.dev_fh, IOCTL_BASE) << 4
self._ioctl_base = self.compute_ioctlbase()

def devmem_available(self):
"""Check if /dev/mem is usable.
Expand Down Expand Up @@ -297,6 +296,23 @@ def close(self):
os.close(self.dev_mem)
self.dev_mem = None

# code taken from /include/uapi/asm-generic/ioctl.h
# by default itype is 'C' see drivers/linux/include/chipsec.h
# currently all chipsec ioctl functions are _IOWR
# currently all size are pointer
def compute_ioctlbase(self,itype = 'C'):
#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
#define _IOC(dir,type,nr,size) \
# (((dir) << _IOC_DIRSHIFT) | \
# ((type) << _IOC_TYPESHIFT) | \
# ((nr) << _IOC_NRSHIFT) | \
# ((size) << _IOC_SIZESHIFT))
# IOC_READ | _IOC_WRITE is 3
# default _IOC_DIRSHIFT is 30
# default _IOC_TYPESHIFT is 8
# nr will be 0
# _IOC_SIZESHIFT is 16
return (3 << 30) | (ord(itype) << 8) | (struct.calcsize(self._pack) << 16)

def ioctl(self, nr, args, *mutate_flag):
return fcntl.ioctl(self.dev_fh, self._ioctl_base + nr, args)
Expand Down
44 changes: 22 additions & 22 deletions drivers/linux/include/chipsec.h
Expand Up @@ -24,28 +24,28 @@ chipsec@intel.com
#define MSR_IA32_BIOS_UPDT_TRIG 0x79
#define MSR_IA32_BIOS_SIGN_ID 0x8b

#define IOCTL_BASE _IO(0, 0)
#define IOCTL_RDIO _IOWR(0, 0x1, int*)
#define IOCTL_WRIO _IOWR(0, 0x2, int*)
#define IOCTL_RDPCI _IOWR(0, 0x3, int*)
#define IOCTL_WRPCI _IOWR(0, 0x4, int*)
#define IOCTL_RDMSR _IOWR(0, 0x5, int*)
#define IOCTL_WRMSR _IOWR(0, 0x6, int*)
#define IOCTL_CPUID _IOWR(0, 0x7, int*)
#define IOCTL_GET_CPU_DESCRIPTOR_TABLE _IOWR(0, 0x8, int*)
#define IOCTL_HYPERCALL _IOWR(0, 0x9, int*)
#define IOCTL_SWSMI _IOWR(0, 0xA, int*)
#define IOCTL_LOAD_UCODE_PATCH _IOWR(0, 0xB, int*)
#define IOCTL_ALLOC_PHYSMEM _IOWR(0, 0xC, int*)
#define IOCTL_GET_EFIVAR _IOWR(0, 0xD, int*)
#define IOCTL_SET_EFIVAR _IOWR(0, 0xE, int*)
#define IOCTL_RDCR _IOWR(0, 0x10, int*)
#define IOCTL_WRCR _IOWR(0, 0x11, int*)
#define IOCTL_RDMMIO _IOWR(0, 0x12, int*)
#define IOCTL_WRMMIO _IOWR(0, 0x13, int*)
#define IOCTL_VA2PA _IOWR(0, 0x14, int*)
#define IOCTL_MSGBUS_SEND_MESSAGE _IOWR(0, 0x15, int*)
#define IOCTL_FREE_PHYSMEM _IOWR(0, 0x16, int*)
#define IOCTL_BASE _IO('C', 0)
#define IOCTL_RDIO _IOWR('C', 0x1, int*)
#define IOCTL_WRIO _IOWR('C', 0x2, int*)
#define IOCTL_RDPCI _IOWR('C', 0x3, int*)
#define IOCTL_WRPCI _IOWR('C', 0x4, int*)
#define IOCTL_RDMSR _IOWR('C', 0x5, int*)
#define IOCTL_WRMSR _IOWR('C', 0x6, int*)
#define IOCTL_CPUID _IOWR('C', 0x7, int*)
#define IOCTL_GET_CPU_DESCRIPTOR_TABLE _IOWR('C', 0x8, int*)
#define IOCTL_HYPERCALL _IOWR('C', 0x9, int*)
#define IOCTL_SWSMI _IOWR('C', 0xA, int*)
#define IOCTL_LOAD_UCODE_PATCH _IOWR('C', 0xB, int*)
#define IOCTL_ALLOC_PHYSMEM _IOWR('C', 0xC, int*)
#define IOCTL_GET_EFIVAR _IOWR('C', 0xD, int*)
#define IOCTL_SET_EFIVAR _IOWR('C', 0xE, int*)
#define IOCTL_RDCR _IOWR('C', 0x10, int*)
#define IOCTL_WRCR _IOWR('C', 0x11, int*)
#define IOCTL_RDMMIO _IOWR('C', 0x12, int*)
#define IOCTL_WRMMIO _IOWR('C', 0x13, int*)
#define IOCTL_VA2PA _IOWR('C', 0x14, int*)
#define IOCTL_MSGBUS_SEND_MESSAGE _IOWR('C', 0x15, int*)
#define IOCTL_FREE_PHYSMEM _IOWR('C', 0x16, int*)

//
// SoC IOSF Message Bus constants
Expand Down

0 comments on commit 522fbb7

Please sign in to comment.