ia64/xen-unstable

changeset 10818:199d53efd029

[IA64] IO ports for driver domains.

Map/unmap IO ports.

Signed-off-by: Tristan Gingold <tristan.gingold@bull.net>
author awilliam@xenbuild.aw
date Thu Jul 27 10:00:00 2006 -0600 (2006-07-27)
parents 14f8c17c9808
children 2d73714911c2
files xen/arch/ia64/xen/dom0_ops.c xen/arch/ia64/xen/dom_fw.c xen/arch/ia64/xen/mm.c xen/include/asm-ia64/domain.h xen/include/asm-ia64/iocap.h
line diff
     1.1 --- a/xen/arch/ia64/xen/dom0_ops.c	Thu Jul 27 09:47:59 2006 -0600
     1.2 +++ b/xen/arch/ia64/xen/dom0_ops.c	Thu Jul 27 10:00:00 2006 -0600
     1.3 @@ -285,6 +285,7 @@ long arch_do_dom0_op(dom0_op_t *op, XEN_
     1.4          struct domain *d;
     1.5          unsigned int fp = op->u.ioport_permission.first_port;
     1.6          unsigned int np = op->u.ioport_permission.nr_ports;
     1.7 +        unsigned int lp = fp + np - 1;
     1.8  
     1.9          ret = -ESRCH;
    1.10          d = find_domain_by_id(op->u.ioport_permission.domain);
    1.11 @@ -295,9 +296,9 @@ long arch_do_dom0_op(dom0_op_t *op, XEN_
    1.12              ret = 0;
    1.13          else {
    1.14              if (op->u.ioport_permission.allow_access)
    1.15 -                ret = ioports_permit_access(d, fp, fp + np - 1);
    1.16 +                ret = ioports_permit_access(d, fp, lp);
    1.17              else
    1.18 -                ret = ioports_deny_access(d, fp, fp + np - 1);
    1.19 +                ret = ioports_deny_access(d, fp, lp);
    1.20          }
    1.21  
    1.22          put_domain(d);
     2.1 --- a/xen/arch/ia64/xen/dom_fw.c	Thu Jul 27 09:47:59 2006 -0600
     2.2 +++ b/xen/arch/ia64/xen/dom_fw.c	Thu Jul 27 10:00:00 2006 -0600
     2.3 @@ -855,15 +855,17 @@ dom_fw_init (struct domain *d, struct ia
     2.4  	} else {
     2.5  #ifndef CONFIG_XEN_IA64_DOM0_VP
     2.6  	  	/* Dom0 maps legacy mmio in first MB.  */
     2.7 -		MAKE_MD(EFI_LOADER_DATA,EFI_MEMORY_WB,0*MB,1*MB, 1);
     2.8 -		MAKE_MD(EFI_CONVENTIONAL_MEMORY,EFI_MEMORY_WB,HYPERCALL_END,maxmem, 1);
     2.9 +		MAKE_MD(EFI_LOADER_DATA, EFI_MEMORY_WB, 0*MB, 1*MB, 1);
    2.10 +		MAKE_MD(EFI_CONVENTIONAL_MEMORY, EFI_MEMORY_WB,
    2.11 +			HYPERCALL_END, maxmem, 1);
    2.12  #endif
    2.13 -		/* hypercall patches live here, masquerade as reserved PAL memory */
    2.14 -		MAKE_MD(EFI_PAL_CODE,EFI_MEMORY_WB|EFI_MEMORY_RUNTIME,HYPERCALL_START,HYPERCALL_END, 1);
    2.15 -		/* Create a dummy entry for IO ports, so that IO accesses are
    2.16 -		   trapped by Xen.  */
    2.17 -		MAKE_MD(EFI_MEMORY_MAPPED_IO_PORT_SPACE,EFI_MEMORY_UC,
    2.18 -			0x00000ffffc000000, 0x00000fffffffffff, 1);
    2.19 +		/* hypercall patches live here, masquerade as reserved
    2.20 +		   PAL memory */
    2.21 +		MAKE_MD(EFI_PAL_CODE, EFI_MEMORY_WB | EFI_MEMORY_RUNTIME,
    2.22 +			HYPERCALL_START, HYPERCALL_END, 1);
    2.23 +		/* Create an entry for IO ports.  */
    2.24 +		MAKE_MD(EFI_MEMORY_MAPPED_IO_PORT_SPACE, EFI_MEMORY_UC,
    2.25 +			IO_PORTS_PADDR, IO_PORTS_PADDR + IO_PORTS_SIZE, 1);
    2.26  		MAKE_MD(EFI_RESERVED_TYPE,0,0,0,0);
    2.27  	}
    2.28  
     3.1 --- a/xen/arch/ia64/xen/mm.c	Thu Jul 27 09:47:59 2006 -0600
     3.2 +++ b/xen/arch/ia64/xen/mm.c	Thu Jul 27 10:00:00 2006 -0600
     3.3 @@ -180,6 +180,8 @@ static void domain_page_flush(struct dom
     3.4                                unsigned long old_mfn, unsigned long new_mfn);
     3.5  #endif
     3.6  
     3.7 +extern unsigned long ia64_iobase;
     3.8 +
     3.9  static struct domain *dom_xen, *dom_io;
    3.10  
    3.11  // followings are stolen from arch_init_memory() @ xen/arch/x86/mm.c
    3.12 @@ -894,6 +896,60 @@ assign_domain_page(struct domain *d,
    3.13      __assign_domain_page(d, mpaddr, physaddr, ASSIGN_writable);
    3.14  }
    3.15  
    3.16 +int
    3.17 +ioports_permit_access(struct domain *d, unsigned long fp, unsigned long lp)
    3.18 +{
    3.19 +    int ret;
    3.20 +    unsigned long off;
    3.21 +    unsigned long fp_offset;
    3.22 +    unsigned long lp_offset;
    3.23 +
    3.24 +    ret = rangeset_add_range(d->arch.ioport_caps, fp, lp);
    3.25 +    if (ret != 0)
    3.26 +        return ret;
    3.27 +
    3.28 +    fp_offset = IO_SPACE_SPARSE_ENCODING(fp) & ~PAGE_MASK;
    3.29 +    lp_offset = PAGE_ALIGN(IO_SPACE_SPARSE_ENCODING(lp));
    3.30 +
    3.31 +    for (off = fp_offset; off <= lp_offset; off += PAGE_SIZE)
    3.32 +        __assign_domain_page(d, IO_PORTS_PADDR + off,
    3.33 +                             ia64_iobase + off, ASSIGN_nocache);
    3.34 +
    3.35 +    return 0;
    3.36 +}
    3.37 +
    3.38 +int
    3.39 +ioports_deny_access(struct domain *d, unsigned long fp, unsigned long lp)
    3.40 +{
    3.41 +    int ret;
    3.42 +    struct mm_struct *mm = &d->arch.mm;
    3.43 +    unsigned long off;
    3.44 +    unsigned long fp_offset;
    3.45 +    unsigned long lp_offset;
    3.46 +
    3.47 +    ret = rangeset_remove_range(d->arch.ioport_caps, fp, lp);
    3.48 +    if (ret != 0)
    3.49 +        return ret;
    3.50 +
    3.51 +    fp_offset = IO_SPACE_SPARSE_ENCODING(fp) & ~PAGE_MASK;
    3.52 +    lp_offset = PAGE_ALIGN(IO_SPACE_SPARSE_ENCODING(lp));
    3.53 +
    3.54 +    for (off = fp_offset; off <= lp_offset; off += PAGE_SIZE) {
    3.55 +        unsigned long mpaddr = IO_PORTS_PADDR + off;
    3.56 +        volatile pte_t *pte;
    3.57 +        pte_t old_pte;
    3.58 +
    3.59 +        pte = lookup_noalloc_domain_pte_none(d, mpaddr);
    3.60 +        BUG_ON(pte == NULL);
    3.61 +        BUG_ON(pte_none(*pte));
    3.62 +
    3.63 +        // clear pte
    3.64 +        old_pte = ptep_get_and_clear(mm, mpaddr, pte);
    3.65 +    }
    3.66 +    domain_flush_vtlb_all();
    3.67 +    return 0;
    3.68 +}
    3.69 +
    3.70  #ifdef CONFIG_XEN_IA64_DOM0_VP
    3.71  static void
    3.72  assign_domain_same_page(struct domain *d,
     4.1 --- a/xen/include/asm-ia64/domain.h	Thu Jul 27 09:47:59 2006 -0600
     4.2 +++ b/xen/include/asm-ia64/domain.h	Thu Jul 27 10:00:00 2006 -0600
     4.3 @@ -196,6 +196,10 @@ struct arch_vcpu {
     4.4  #include <asm/uaccess.h> /* for KERNEL_DS */
     4.5  #include <asm/pgtable.h>
     4.6  
     4.7 +/* Guest physical address of IO ports space.  */
     4.8 +#define IO_PORTS_PADDR          0x00000ffffc000000UL
     4.9 +#define IO_PORTS_SIZE           0x0000000004000000UL
    4.10 +
    4.11  #endif /* __ASM_DOMAIN_H__ */
    4.12  
    4.13  /*
     5.1 --- a/xen/include/asm-ia64/iocap.h	Thu Jul 27 09:47:59 2006 -0600
     5.2 +++ b/xen/include/asm-ia64/iocap.h	Thu Jul 27 10:00:00 2006 -0600
     5.3 @@ -7,10 +7,11 @@
     5.4  #ifndef __IA64_IOCAP_H__
     5.5  #define __IA64_IOCAP_H__
     5.6  
     5.7 -#define ioports_permit_access(d, s, e)                  \
     5.8 -    rangeset_add_range((d)->arch.ioport_caps, s, e)
     5.9 -#define ioports_deny_access(d, s, e)                    \
    5.10 -    rangeset_remove_range((d)->arch.ioport_caps, s, e)
    5.11 +extern int ioports_permit_access(struct domain *d,
    5.12 +                                 unsigned long s, unsigned long e);
    5.13 +extern int ioports_deny_access(struct domain *d,
    5.14 +                               unsigned long s, unsigned long e);
    5.15 +
    5.16  #define ioports_access_permitted(d, s, e)               \
    5.17      rangeset_contains_range((d)->arch.ioport_caps, s, e)
    5.18