From a9cdb3cf183a19035f0f8013fd654063dc88ccbd Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Thu, 9 Feb 2012 23:18:53 +0100 Subject: [PATCH] * grub-core/bus/usb/ehci.c (grub_ehci_ehcc_read32): Restructure to conserve alignment invariants. (grub_ehci_ehcc_read16): Likewise. (grub_ehci_oper_read32): Likewise. (grub_ehci_oper_write32): Likewise. (grub_ehci_pci_iter) [!GRUB_HAVE_UNALIGNED_ACCESS]: Check alignment. Conserve alignment invariants. --- ChangeLog | 10 ++++++++++ grub-core/bus/usb/ehci.c | 28 ++++++++++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 12e48e9f6..2ed21f80b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2012-02-09 Vladimir Serbinenko + + * grub-core/bus/usb/ehci.c (grub_ehci_ehcc_read32): Restructure to + conserve alignment invariants. + (grub_ehci_ehcc_read16): Likewise. + (grub_ehci_oper_read32): Likewise. + (grub_ehci_oper_write32): Likewise. + (grub_ehci_pci_iter) [!GRUB_HAVE_UNALIGNED_ACCESS]: Check alignment. + Conserve alignment invariants. + 2012-02-09 Vladimir Serbinenko * grub-core/kern/emu/full.c (grub_emu_post_init): Remove raid reinit. diff --git a/grub-core/bus/usb/ehci.c b/grub-core/bus/usb/ehci.c index 2f1116bde..5e3a72356 100644 --- a/grub-core/bus/usb/ehci.c +++ b/grub-core/bus/usb/ehci.c @@ -337,24 +337,22 @@ static inline grub_uint32_t grub_ehci_ehcc_read32 (struct grub_ehci *e, grub_uint32_t addr) { return - grub_le_to_cpu32 (* - ((volatile grub_uint32_t *) ((char *) e->iobase_ehcc + - addr))); + grub_le_to_cpu32 (*((volatile grub_uint32_t *) e->iobase_ehcc + + (addr / sizeof (grub_uint32_t)))); } static inline grub_uint16_t grub_ehci_ehcc_read16 (struct grub_ehci *e, grub_uint32_t addr) { return - grub_le_to_cpu16 (* - ((volatile grub_uint16_t *) ((char *) e->iobase_ehcc + - addr))); + grub_le_to_cpu16 (*((volatile grub_uint16_t *) e->iobase_ehcc + + (addr / sizeof (grub_uint16_t)))); } static inline grub_uint8_t grub_ehci_ehcc_read8 (struct grub_ehci *e, grub_uint32_t addr) { - return *((volatile grub_uint8_t *) ((char *) e->iobase_ehcc + addr)); + return *((volatile grub_uint8_t *) e->iobase_ehcc + addr); } /* Operational registers access functions */ @@ -363,15 +361,15 @@ grub_ehci_oper_read32 (struct grub_ehci *e, grub_uint32_t addr) { return grub_le_to_cpu32 (* - ((volatile grub_uint32_t *) ((char *) e->iobase + - addr))); + ((volatile grub_uint32_t *) e->iobase + + (addr / sizeof (grub_uint32_t)))); } static inline void grub_ehci_oper_write32 (struct grub_ehci *e, grub_uint32_t addr, grub_uint32_t value) { - *((volatile grub_uint32_t *) ((char *) e->iobase + addr)) = + *((volatile grub_uint32_t *) e->iobase + (addr / sizeof (grub_uint32_t))) = grub_cpu_to_le32 (value); } @@ -559,8 +557,18 @@ grub_ehci_pci_iter (grub_pci_device_t dev, /* Determine base address of EHCI operational registers */ caplen = grub_ehci_ehcc_read8 (e, GRUB_EHCI_EHCC_CAPLEN); +#ifndef GRUB_HAVE_UNALIGNED_ACCESS + if (caplen & (sizeof (grub_uint32_t) - 1)) + { + grub_dprintf ("ehci", "Unaligned caplen\n"); + return 0; + } + e->iobase = ((volatile grub_uint32_t *) e->iobase_ehcc + + (caplen / sizeof (grub_uint32_t))); +#else e->iobase = (volatile grub_uint32_t *) ((grub_uint8_t *) e->iobase_ehcc + caplen); +#endif grub_dprintf ("ehci", "EHCI grub_ehci_pci_iter: iobase of oper. regs: %08x\n",