Message ID | 1516308132-10272-10-git-send-email-mst@redhat.com |
---|---|
State | New |
Headers | show |
Series | [PULL,v4,01/29] MAINTAINERS: Add myself as maintainer to X86 machines | expand |
On 01/18/2018 02:44 PM, Michael S. Tsirkin wrote: > From: Yuval Shaia <yuval.shaia@oracle.com> > > This function should be declared in generic header file so we can > utilize it. > > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com> > Signed-off-by: Marcel Apfelbaum <marcel@redhat.com> > Reviewed-by: Michael S. Tsirkin <mst@redhat.com> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com> > --- > include/qemu/host-utils.h | 10 ++++++++++ > hw/pci/shpc.c | 13 ++----------- > 2 files changed, 12 insertions(+), 11 deletions(-) > > diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h > index 5ac621c..38da849 100644 > --- a/include/qemu/host-utils.h > +++ b/include/qemu/host-utils.h > @@ -400,6 +400,16 @@ static inline uint64_t pow2ceil(uint64_t value) > return 0x8000000000000000ull >> (n - 1); > } > > +static inline uint32_t pow2roundup32(uint32_t x) > +{ > + x |= (x >> 1); > + x |= (x >> 2); > + x |= (x >> 4); > + x |= (x >> 8); > + x |= (x >> 16); > + return x + 1; > +} How does this differ from pow2ceil(), other than the difference in type?
On Thu, Jan 18, 2018 at 03:51:17PM -0600, Eric Blake wrote: > On 01/18/2018 02:44 PM, Michael S. Tsirkin wrote: > > From: Yuval Shaia <yuval.shaia@oracle.com> > > > > This function should be declared in generic header file so we can > > utilize it. > > > > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > > Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com> > > Signed-off-by: Marcel Apfelbaum <marcel@redhat.com> > > Reviewed-by: Michael S. Tsirkin <mst@redhat.com> > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com> > > --- > > include/qemu/host-utils.h | 10 ++++++++++ > > hw/pci/shpc.c | 13 ++----------- > > 2 files changed, 12 insertions(+), 11 deletions(-) > > > > diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h > > index 5ac621c..38da849 100644 > > --- a/include/qemu/host-utils.h > > +++ b/include/qemu/host-utils.h > > @@ -400,6 +400,16 @@ static inline uint64_t pow2ceil(uint64_t value) > > return 0x8000000000000000ull >> (n - 1); > > } > > > > +static inline uint32_t pow2roundup32(uint32_t x) > > +{ > > + x |= (x >> 1); > > + x |= (x >> 2); > > + x |= (x >> 4); > > + x |= (x >> 8); > > + x |= (x >> 16); > > + return x + 1; > > +} > > How does this differ from pow2ceil(), other than the difference in type? Hi Michael, I tested pvrdma device with pow2ceil and it works fine however i have no idea how to test shpc. So from pvrdma perspective this commit can be dropped. I can replace it with one that change shpc_bar_size to use pow2ceil but again - compiled, not tested. Yuval > > -- > Eric Blake, Principal Software Engineer > Red Hat, Inc. +1-919-301-3266 > Virtualization: qemu.org | libvirt.org >
diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h index 5ac621c..38da849 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -400,6 +400,16 @@ static inline uint64_t pow2ceil(uint64_t value) return 0x8000000000000000ull >> (n - 1); } +static inline uint32_t pow2roundup32(uint32_t x) +{ + x |= (x >> 1); + x |= (x >> 2); + x |= (x >> 4); + x |= (x >> 8); + x |= (x >> 16); + return x + 1; +} + /** * urshift - 128-bit Unsigned Right Shift. * @plow: in/out - lower 64-bit integer. diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index 69fc14b..a8462d4 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -1,6 +1,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu-common.h" +#include "qemu/host-utils.h" #include "qemu/range.h" #include "qemu/error-report.h" #include "hw/pci/shpc.h" @@ -122,16 +123,6 @@ #define SHPC_PCI_TO_IDX(pci_slot) ((pci_slot) - 1) #define SHPC_IDX_TO_PHYSICAL(slot) ((slot) + 1) -static int roundup_pow_of_two(int x) -{ - x |= (x >> 1); - x |= (x >> 2); - x |= (x >> 4); - x |= (x >> 8); - x |= (x >> 16); - return x + 1; -} - static uint16_t shpc_get_status(SHPCDevice *shpc, int slot, uint16_t msk) { uint8_t *status = shpc->config + SHPC_SLOT_STATUS(slot); @@ -656,7 +647,7 @@ int shpc_init(PCIDevice *d, PCIBus *sec_bus, MemoryRegion *bar, int shpc_bar_size(PCIDevice *d) { - return roundup_pow_of_two(SHPC_SLOT_REG(SHPC_MAX_SLOTS)); + return pow2roundup32(SHPC_SLOT_REG(SHPC_MAX_SLOTS)); } void shpc_cleanup(PCIDevice *d, MemoryRegion *bar)