ia64/xen-unstable

changeset 10020:bd714da877c7

[IA64] add parameter check to ioremap hypercall

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author awilliam@xenbuild.aw
date Wed May 17 15:53:14 2006 -0600 (2006-05-17)
parents 41e7549d7df9
children d2f6e3d70f22
files xen/arch/ia64/xen/domain.c
line diff
     1.1 --- a/xen/arch/ia64/xen/domain.c	Wed May 17 15:53:05 2006 -0600
     1.2 +++ b/xen/arch/ia64/xen/domain.c	Wed May 17 15:53:14 2006 -0600
     1.3 @@ -837,6 +837,56 @@ assign_domain_same_page(struct domain *d
     1.4      }
     1.5  }
     1.6  
     1.7 +static int
     1.8 +efi_mmio(unsigned long physaddr, unsigned long size)
     1.9 +{
    1.10 +    void *efi_map_start, *efi_map_end;
    1.11 +    u64 efi_desc_size;
    1.12 +    void* p;
    1.13 +
    1.14 +    efi_map_start = __va(ia64_boot_param->efi_memmap);
    1.15 +    efi_map_end   = efi_map_start + ia64_boot_param->efi_memmap_size;
    1.16 +    efi_desc_size = ia64_boot_param->efi_memdesc_size;
    1.17 +
    1.18 +    for (p = efi_map_start; p < efi_map_end; p += efi_desc_size) {
    1.19 +        efi_memory_desc_t* md = (efi_memory_desc_t *)p;
    1.20 +        unsigned long start = md->phys_addr;
    1.21 +        unsigned long end = md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT);
    1.22 +        
    1.23 +        if (start <= physaddr && physaddr < end) {
    1.24 +            if ((physaddr + size) > end) {
    1.25 +                DPRINTK("%s:%d physaddr 0x%lx size = 0x%lx\n",
    1.26 +                        __func__, __LINE__, physaddr, size);
    1.27 +                return 0;
    1.28 +            }
    1.29 +
    1.30 +            // for io space
    1.31 +            if (md->type == EFI_MEMORY_MAPPED_IO ||
    1.32 +                md->type == EFI_MEMORY_MAPPED_IO_PORT_SPACE) {
    1.33 +                return 1;
    1.34 +            }
    1.35 +
    1.36 +            // for runtime
    1.37 +            // see efi_enter_virtual_mode(void)
    1.38 +            // in linux/arch/ia64/kernel/efi.c
    1.39 +            if ((md->attribute & EFI_MEMORY_RUNTIME) &&
    1.40 +                !(md->attribute & EFI_MEMORY_WB)) {
    1.41 +                return 1;
    1.42 +            }
    1.43 +
    1.44 +            DPRINTK("%s:%d physaddr 0x%lx size = 0x%lx\n",
    1.45 +                    __func__, __LINE__, physaddr, size);
    1.46 +            return 0;
    1.47 +        }
    1.48 +
    1.49 +        if (physaddr < start) {
    1.50 +            break;
    1.51 +        }
    1.52 +    }
    1.53 +
    1.54 +    return 1;
    1.55 +}
    1.56 +
    1.57  unsigned long
    1.58  assign_domain_mmio_page(struct domain *d,
    1.59                          unsigned long mpaddr, unsigned long size)
    1.60 @@ -845,6 +895,11 @@ assign_domain_mmio_page(struct domain *d
    1.61          DPRINTK("%s: domain %p mpaddr 0x%lx size = 0x%lx\n",
    1.62                  __func__, d, mpaddr, size);
    1.63      }
    1.64 +    if (!efi_mmio(mpaddr, size)) {
    1.65 +        DPRINTK("%s:%d domain %p mpaddr 0x%lx size = 0x%lx\n",
    1.66 +                __func__, __LINE__, d, mpaddr, size);
    1.67 +        return -EINVAL;
    1.68 +    }
    1.69      assign_domain_same_page(d, mpaddr, size);
    1.70      return mpaddr;
    1.71  }