ia64/xen-unstable

changeset 18634:07558e1876e4

[IA64] clean up ioports_{permit, deny}_access()

eliminate code duplication in those functions
by introducing helper functions.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Fri Oct 17 18:16:05 2008 +0900 (2008-10-17)
parents f27787b9f8d7
children e23c1f241c7b
files xen/arch/ia64/xen/mm.c
line diff
     1.1 --- a/xen/arch/ia64/xen/mm.c	Fri Oct 17 17:40:15 2008 +0900
     1.2 +++ b/xen/arch/ia64/xen/mm.c	Fri Oct 17 18:16:05 2008 +0900
     1.3 @@ -983,6 +983,32 @@ assign_domain_page(struct domain *d,
     1.4                                 ASSIGN_writable | ASSIGN_pgc_allocated);
     1.5  }
     1.6  
     1.7 +static void
     1.8 +ioports_get_mmio_addr(const struct io_space *space,
     1.9 +                      unsigned long fp, unsigned long lp,
    1.10 +                      unsigned long *mmio_start, unsigned long *mmio_end)
    1.11 +{
    1.12 +    if (space->sparse) {
    1.13 +        *mmio_start = IO_SPACE_SPARSE_ENCODING(fp) & PAGE_MASK;
    1.14 +        *mmio_end = PAGE_ALIGN(IO_SPACE_SPARSE_ENCODING(lp));
    1.15 +    } else {
    1.16 +        *mmio_start = fp & PAGE_MASK;
    1.17 +        *mmio_end = PAGE_ALIGN(lp);
    1.18 +    }
    1.19 +}
    1.20 +
    1.21 +static unsigned long
    1.22 +ioports_get_mmio_base(const struct io_space *space, struct domain *d)
    1.23 +{
    1.24 +    if (VMX_DOMAIN(d->vcpu[0]))
    1.25 +        return LEGACY_IO_START;
    1.26 +
    1.27 +    if (space == &io_space[0] && d != dom0)
    1.28 +        return IO_PORTS_PADDR;
    1.29 +
    1.30 +    return __pa(space->mmio_base);
    1.31 +}
    1.32 +
    1.33  /* 
    1.34   * Inpurt
    1.35   * fgp: first guest port
    1.36 @@ -1025,13 +1051,7 @@ ioports_permit_access(struct domain *d, 
    1.37      fmp = IO_SPACE_PORT(fmp);
    1.38      lmp = IO_SPACE_PORT(lmp);
    1.39  
    1.40 -    if (space->sparse) {
    1.41 -        mach_start = IO_SPACE_SPARSE_ENCODING(fmp) & PAGE_MASK;
    1.42 -        mach_end = PAGE_ALIGN(IO_SPACE_SPARSE_ENCODING(lmp));
    1.43 -    } else {
    1.44 -        mach_start = fmp & PAGE_MASK;
    1.45 -        mach_end = PAGE_ALIGN(lmp);
    1.46 -    }
    1.47 +    ioports_get_mmio_addr(space, fmp, lmp, &mach_start, &mach_end);
    1.48  
    1.49      /*
    1.50       * The "machine first port" is not necessarily identity mapped
    1.51 @@ -1041,13 +1061,7 @@ ioports_permit_access(struct domain *d, 
    1.52      mach_end = mach_end | __pa(space->mmio_base);
    1.53  
    1.54      mmio_start = IO_SPACE_SPARSE_ENCODING(fgp) & PAGE_MASK;
    1.55 -
    1.56 -    if (VMX_DOMAIN(d->vcpu[0]))
    1.57 -        mmio_start |= LEGACY_IO_START;
    1.58 -    else if (space == &io_space[0])
    1.59 -        mmio_start |= IO_PORTS_PADDR;
    1.60 -    else
    1.61 -        mmio_start |= __pa(space->mmio_base);
    1.62 +    mmio_start |= ioports_get_mmio_base(space, d);
    1.63  
    1.64      while (mach_start < mach_end) {
    1.65          (void)__assign_domain_page(d, mmio_start, mach_start, ASSIGN_nocache); 
    1.66 @@ -1090,20 +1104,9 @@ ioports_deny_access(struct domain *d, un
    1.67      fp_base = IO_SPACE_PORT(fp);
    1.68      lp_base = IO_SPACE_PORT(lp);
    1.69  
    1.70 -    if (space->sparse) {
    1.71 -        mmio_start = IO_SPACE_SPARSE_ENCODING(fp_base) & PAGE_MASK;
    1.72 -        mmio_end = PAGE_ALIGN(IO_SPACE_SPARSE_ENCODING(lp_base));
    1.73 -    } else {
    1.74 -        mmio_start = fp_base & PAGE_MASK;
    1.75 -        mmio_end = PAGE_ALIGN(lp_base);
    1.76 -    }
    1.77 -
    1.78 -    if (VMX_DOMAIN(d->vcpu[0]))
    1.79 -        mmio_base = LEGACY_IO_START;
    1.80 -    else if (space == &io_space[0] && d != dom0)
    1.81 -        mmio_base = IO_PORTS_PADDR;
    1.82 -    else
    1.83 -        mmio_base = __pa(space->mmio_base);
    1.84 +    ioports_get_mmio_addr(space, fp_base, lp_base, &mmio_start, &mmio_end);
    1.85 +
    1.86 +    mmio_base = ioports_get_mmio_base(space, d);
    1.87  
    1.88      for (; mmio_start < mmio_end; mmio_start += PAGE_SIZE) {
    1.89          unsigned int port, range;