ia64/xen-unstable

changeset 3594:fec8b1778268

bitkeeper revision 1.1159.212.60 (41febc4bKKSkh9u-Zes9v2CmBuLZxA)

More bootstrap fixes for x86/64. Next thing to do is sort out the IDT and
get traps.c working; then we can get rid of a bunch of dummy labels from
end of boot/x86_64.S. We're also going to need some kind of entry.S before
we can safely enable interrupts. Also bear in mind that not all of physical
RAM may be mapped (only first 1GB) and no m2p table is yet allocated or
mapped. Plenty to be done!
author kaf24@viper.(none)
date Mon Jan 31 23:16:27 2005 +0000 (2005-01-31)
parents 3a17f2625dc3
children 578b6c14e635
files .rootkeys xen/arch/x86/boot/x86_64.S xen/arch/x86/memory.c xen/arch/x86/setup.c xen/arch/x86/x86_32/mm.c xen/arch/x86/x86_64/mm.c xen/include/asm-x86/config.h xen/include/asm-x86/domain_page.h xen/include/asm-x86/fixmap.h xen/include/asm-x86/mm.h xen/include/asm-x86/page.h xen/include/asm-x86/x86_32/domain_page.h xen/include/asm-x86/x86_64/domain_page.h
line diff
     1.1 --- a/.rootkeys	Sat Jan 29 22:42:20 2005 +0000
     1.2 +++ b/.rootkeys	Mon Jan 31 23:16:27 2005 +0000
     1.3 @@ -999,7 +999,7 @@ 3ddb79c2jFkPAZTDmU35L6IUssYMgQ xen/inclu
     1.4  3ddb79c3r9-31dIsewPV3P3i8HALsQ xen/include/asm-x86/delay.h
     1.5  3ddb79c34BFiXjBJ_cCKB0aCsV1IDw xen/include/asm-x86/desc.h
     1.6  40715b2dTokMLYGSuD58BnxOqyWVew xen/include/asm-x86/div64.h
     1.7 -3e20b82fl1jmQiKdLy7fxMcutfpjWA xen/include/asm-x86/domain_page.h
     1.8 +41febc4bBKTKHhnAu_KPYwgNkHjFlg xen/include/asm-x86/domain_page.h
     1.9  41d3eaaeIBzW621S1oa0c2yk7X43qQ xen/include/asm-x86/e820.h
    1.10  3ddb79c3NU8Zy40OTrq3D-i30Y3t4A xen/include/asm-x86/fixmap.h
    1.11  3e2d29944GI24gf7vOP_7x8EyuqxeA xen/include/asm-x86/flushtlb.h
    1.12 @@ -1036,12 +1036,14 @@ 41c0c41243jC1mcArZx_t3YkBL4lTA xen/inclu
    1.13  41c0c412lQ0NVVN9PsOSznQ-qhOiPA xen/include/asm-x86/vmx_vmcs.h
    1.14  418fbcfe_WliJPToeVM-9VStvym-hw xen/include/asm-x86/x86_32/asm_defns.h
    1.15  3ddb79c2ADvRmdexd9y3AYK9_NTx-Q xen/include/asm-x86/x86_32/current.h
    1.16 +3e20b82fl1jmQiKdLy7fxMcutfpjWA xen/include/asm-x86/x86_32/domain_page.h
    1.17  3ddb79c3mbqEM7QQr3zVq7NiBNhouA xen/include/asm-x86/x86_32/regs.h
    1.18  3e7f358aG11EvMI9VJ4_9hD4LUO7rQ xen/include/asm-x86/x86_32/string.h
    1.19  3ddb79c3M2n1ROZH6xk3HbyN4CPDqg xen/include/asm-x86/x86_32/uaccess.h
    1.20  41bf1717bML6GxpclTWJabiaO5W5vg xen/include/asm-x86/x86_64/asm_defns.h
    1.21  404f1b9ceJeGVaPNIENm2FkK0AgEOQ xen/include/asm-x86/x86_64/current.h
    1.22  404f1b9fl6AQ_a-T1TDK3fuwTPXmHw xen/include/asm-x86/x86_64/desc.h
    1.23 +41febc4b1aCGLsm0Y0b_82h7lFtrEA xen/include/asm-x86/x86_64/domain_page.h
    1.24  404f1badfXZJZ2sU8sh9PS2EZvd19Q xen/include/asm-x86/x86_64/ldt.h
    1.25  404f1bb86rAXB3aLS1vYdcqpJiEcyg xen/include/asm-x86/x86_64/regs.h
    1.26  40e1966azOJZfNI6Ilthe6Q-T3Hewg xen/include/asm-x86/x86_64/string.h
     2.1 --- a/xen/arch/x86/boot/x86_64.S	Sat Jan 29 22:42:20 2005 +0000
     2.2 +++ b/xen/arch/x86/boot/x86_64.S	Mon Jan 31 23:16:27 2005 +0000
     2.3 @@ -248,19 +248,11 @@ ENTRY(cpu0_stack)    # Initial stack is 
     2.4  ENTRY(stext)
     2.5  ENTRY(_stext)
     2.6  
     2.7 -.globl map_domain_mem, unmap_domain_mem, ret_from_intr
     2.8 -map_domain_mem:
     2.9 -unmap_domain_mem:
    2.10 +.globl ret_from_intr, copy_to_user, set_intr_gate, die
    2.11  ret_from_intr:
    2.12 -#undef machine_to_phys_mapping
    2.13 -#undef phys_to_machine_mapping
    2.14 -.globl copy_to_user, set_intr_gate, die, machine_to_phys_mapping
    2.15 -.globl phys_to_machine_mapping
    2.16  copy_to_user:
    2.17  set_intr_gate:
    2.18  die:
    2.19 -machine_to_phys_mapping:
    2.20 -phys_to_machine_mapping:
    2.21  .globl copy_from_user, show_registers, do_iopl
    2.22  copy_from_user: 
    2.23  show_registers: 
     3.1 --- a/xen/arch/x86/memory.c	Sat Jan 29 22:42:20 2005 +0000
     3.2 +++ b/xen/arch/x86/memory.c	Mon Jan 31 23:16:27 2005 +0000
     3.3 @@ -148,27 +148,20 @@ unsigned long max_page;
     3.4  
     3.5  void __init init_frametable(void)
     3.6  {
     3.7 -#if defined(__i386__)
     3.8      unsigned long i, p;
     3.9 -#endif
    3.10  
    3.11 +    frame_table      = (struct pfn_info *)FRAMETABLE_VIRT_START;
    3.12      frame_table_size = max_page * sizeof(struct pfn_info);
    3.13      frame_table_size = (frame_table_size + PAGE_SIZE - 1) & PAGE_MASK;
    3.14  
    3.15 -#if defined(__x86_64__)
    3.16 -    frame_table = __va(alloc_boot_pages(frame_table_size, 4UL << 20));
    3.17 -#elif defined(__i386__)
    3.18 -    frame_table = (struct pfn_info *)FRAMETABLE_VIRT_START;
    3.19 -
    3.20      for ( i = 0; i < frame_table_size; i += (4UL << 20) )
    3.21      {
    3.22          p = alloc_boot_pages(min(frame_table_size - i, 4UL << 20), 4UL << 20);
    3.23          if ( p == 0 )
    3.24              panic("Not enough memory for frame table\n");
    3.25 -        idle_pg_table[(FRAMETABLE_VIRT_START + i) >> L2_PAGETABLE_SHIFT] =
    3.26 -            mk_l2_pgentry(p | __PAGE_HYPERVISOR | _PAGE_PSE);
    3.27 +        map_pages(idle_pg_table, FRAMETABLE_VIRT_START + i, p, 
    3.28 +                  4UL << 20, PAGE_HYPERVISOR);
    3.29      }
    3.30 -#endif
    3.31  
    3.32      memset(frame_table, 0, frame_table_size);
    3.33  }
     4.1 --- a/xen/arch/x86/setup.c	Sat Jan 29 22:42:20 2005 +0000
     4.2 +++ b/xen/arch/x86/setup.c	Mon Jan 31 23:16:27 2005 +0000
     4.3 @@ -55,6 +55,8 @@ boolean_param("ignorebiostables", opt_ig
     4.4  static int opt_watchdog = 0;
     4.5  boolean_param("watchdog", opt_watchdog);
     4.6  
     4.7 +int early_boot = 1;
     4.8 +
     4.9  unsigned long xenheap_phys_end;
    4.10  
    4.11  extern void arch_init_memory(void);
    4.12 @@ -594,6 +596,8 @@ void __init __start_xen(multiboot_info_t
    4.13  	   (xenheap_phys_end-__pa(heap_start)) >> 20,
    4.14  	   (xenheap_phys_end-__pa(heap_start)) >> 10);
    4.15  
    4.16 +    early_boot = 0;
    4.17 +
    4.18      /* Initialise the slab allocator. */
    4.19      xmem_cache_init();
    4.20      xmem_cache_sizes_init(max_page);
     5.1 --- a/xen/arch/x86/x86_32/mm.c	Sat Jan 29 22:42:20 2005 +0000
     5.2 +++ b/xen/arch/x86/x86_32/mm.c	Mon Jan 31 23:16:27 2005 +0000
     5.3 @@ -29,30 +29,62 @@
     5.4  
     5.5  unsigned long m2p_start_mfn;
     5.6  
     5.7 -static inline void set_pte_phys(unsigned long vaddr,
     5.8 -                                l1_pgentry_t entry)
     5.9 +/* Map physical byte range (@p, @p+@s) at virt address @v in pagetable @pt. */
    5.10 +int map_pages(
    5.11 +    pagetable_t *pt,
    5.12 +    unsigned long v,
    5.13 +    unsigned long p,
    5.14 +    unsigned long s,
    5.15 +    unsigned long flags)
    5.16  {
    5.17 -    l2_pgentry_t *l2ent;
    5.18 -    l1_pgentry_t *l1ent;
    5.19 +    l2_pgentry_t *pl2e;
    5.20 +    l1_pgentry_t *pl1e;
    5.21 +    void         *newpg;
    5.22 +
    5.23 +    while ( s != 0 )
    5.24 +    {
    5.25 +        pl2e = &pt[l2_table_offset(v)];
    5.26 +
    5.27 +        if ( ((s|v|p) & ((1<<L2_PAGETABLE_SHIFT)-1)) == 0 )
    5.28 +        {
    5.29 +            /* Super-page mapping. */
    5.30 +            if ( (l2_pgentry_val(*pl2e) & _PAGE_PRESENT) )
    5.31 +                __flush_tlb_pge();
    5.32 +            *pl2e = mk_l2_pgentry(p|flags|_PAGE_PSE);
    5.33  
    5.34 -    l2ent = &idle_pg_table[l2_table_offset(vaddr)];
    5.35 -    l1ent = l2_pgentry_to_l1(*l2ent) + l1_table_offset(vaddr);
    5.36 -    *l1ent = entry;
    5.37 +            v += 1 << L2_PAGETABLE_SHIFT;
    5.38 +            p += 1 << L2_PAGETABLE_SHIFT;
    5.39 +            s -= 1 << L2_PAGETABLE_SHIFT;
    5.40 +        }
    5.41 +        else
    5.42 +        {
    5.43 +            /* Normal page mapping. */
    5.44 +            if ( !(l2_pgentry_val(*pl2e) & _PAGE_PRESENT) )
    5.45 +            {
    5.46 +                newpg = (void *)alloc_xenheap_page();
    5.47 +                clear_page(newpg);
    5.48 +                *pl2e = mk_l2_pgentry(__pa(newpg) | __PAGE_HYPERVISOR);
    5.49 +            }
    5.50 +            pl1e = l2_pgentry_to_l1(*pl2e) + l1_table_offset(v);
    5.51 +            if ( (l1_pgentry_val(*pl1e) & _PAGE_PRESENT) )
    5.52 +                __flush_tlb_one(v);
    5.53 +            *pl1e = mk_l1_pgentry(p|flags);
    5.54  
    5.55 -    /* It's enough to flush this one mapping. */
    5.56 -    __flush_tlb_one(vaddr);
    5.57 +            v += 1 << L1_PAGETABLE_SHIFT;
    5.58 +            p += 1 << L1_PAGETABLE_SHIFT;
    5.59 +            s -= 1 << L1_PAGETABLE_SHIFT;            
    5.60 +        }
    5.61 +    }
    5.62 +
    5.63 +    return 0;
    5.64  }
    5.65  
    5.66 -
    5.67 -void __set_fixmap(enum fixed_addresses idx, 
    5.68 -                  l1_pgentry_t entry)
    5.69 +void __set_fixmap(
    5.70 +    enum fixed_addresses idx, unsigned long p, unsigned long flags)
    5.71  {
    5.72 -    unsigned long address = fix_to_virt(idx);
    5.73 -
    5.74 -    if ( likely(idx < __end_of_fixed_addresses) )
    5.75 -        set_pte_phys(address, entry);
    5.76 -    else
    5.77 -        printk("Invalid __set_fixmap\n");
    5.78 +    if ( unlikely(idx >= __end_of_fixed_addresses) )
    5.79 +        BUG();
    5.80 +    map_pages(idle_pg_table, fix_to_virt(idx), p, PAGE_SIZE, flags);
    5.81  }
    5.82  
    5.83  
     6.1 --- a/xen/arch/x86/x86_64/mm.c	Sat Jan 29 22:42:20 2005 +0000
     6.2 +++ b/xen/arch/x86/x86_64/mm.c	Mon Jan 31 23:16:27 2005 +0000
     6.3 @@ -27,39 +27,114 @@
     6.4  #include <asm/fixmap.h>
     6.5  #include <asm/domain_page.h>
     6.6  
     6.7 -static inline void set_pte_phys(unsigned long vaddr,
     6.8 -                                l1_pgentry_t entry)
     6.9 -{
    6.10 -    l4_pgentry_t *l4ent;
    6.11 -    l3_pgentry_t *l3ent;
    6.12 -    l2_pgentry_t *l2ent;
    6.13 -    l1_pgentry_t *l1ent;
    6.14 +unsigned long m2p_start_mfn; /* XXX Kill this (in 32-bit code also). */
    6.15  
    6.16 -    l4ent = &idle_pg_table[l4_table_offset(vaddr)];
    6.17 -    l3ent = l4_pgentry_to_l3(*l4ent) + l3_table_offset(vaddr);
    6.18 -    l2ent = l3_pgentry_to_l2(*l3ent) + l2_table_offset(vaddr);
    6.19 -    l1ent = l2_pgentry_to_l1(*l2ent) + l1_table_offset(vaddr);
    6.20 -    *l1ent = entry;
    6.21 -
    6.22 -    /* It's enough to flush this one mapping. */
    6.23 -    __flush_tlb_one(vaddr);
    6.24 +void *safe_page_alloc(void)
    6.25 +{
    6.26 +    extern int early_boot;
    6.27 +    if ( early_boot )
    6.28 +        return __va(alloc_boot_pages(PAGE_SIZE, PAGE_SIZE));
    6.29 +    return (void *)alloc_xenheap_page();
    6.30  }
    6.31  
    6.32 -
    6.33 -void __set_fixmap(enum fixed_addresses idx, 
    6.34 -                  l1_pgentry_t entry)
    6.35 +/* Map physical byte range (@p, @p+@s) at virt address @v in pagetable @pt. */
    6.36 +int map_pages(
    6.37 +    pagetable_t *pt,
    6.38 +    unsigned long v,
    6.39 +    unsigned long p,
    6.40 +    unsigned long s,
    6.41 +    unsigned long flags)
    6.42  {
    6.43 -    unsigned long address = fix_to_virt(idx);
    6.44 +    l4_pgentry_t *pl4e;
    6.45 +    l3_pgentry_t *pl3e;
    6.46 +    l2_pgentry_t *pl2e;
    6.47 +    l1_pgentry_t *pl1e;
    6.48 +    void         *newpg;
    6.49 +
    6.50 +    while ( s != 0 )
    6.51 +    {
    6.52 +        pl4e = &pt[l4_table_offset(v)];
    6.53 +        if ( !(l4_pgentry_val(*pl4e) & _PAGE_PRESENT) )
    6.54 +        {
    6.55 +            newpg = safe_page_alloc();
    6.56 +            clear_page(newpg);
    6.57 +            *pl4e = mk_l4_pgentry(__pa(newpg) | __PAGE_HYPERVISOR);
    6.58 +        }
    6.59 +
    6.60 +        pl3e = l4_pgentry_to_l3(*pl4e) + l3_table_offset(v);
    6.61 +        if ( !(l3_pgentry_val(*pl3e) & _PAGE_PRESENT) )
    6.62 +        {
    6.63 +            newpg = safe_page_alloc();
    6.64 +            clear_page(newpg);
    6.65 +            *pl3e = mk_l3_pgentry(__pa(newpg) | __PAGE_HYPERVISOR);
    6.66 +        }
    6.67 +
    6.68 +        pl2e = l3_pgentry_to_l2(*pl3e) + l2_table_offset(v);
    6.69 +
    6.70 +        if ( ((s|v|p) & ((1<<L2_PAGETABLE_SHIFT)-1)) == 0 )
    6.71 +        {
    6.72 +            /* Super-page mapping. */
    6.73 +            if ( (l2_pgentry_val(*pl2e) & _PAGE_PRESENT) )
    6.74 +                __flush_tlb_pge();
    6.75 +            *pl2e = mk_l2_pgentry(p|flags|_PAGE_PSE);
    6.76  
    6.77 -    if ( likely(idx < __end_of_fixed_addresses) )
    6.78 -        set_pte_phys(address, entry);
    6.79 -    else
    6.80 -        printk("Invalid __set_fixmap\n");
    6.81 +            v += 1 << L2_PAGETABLE_SHIFT;
    6.82 +            p += 1 << L2_PAGETABLE_SHIFT;
    6.83 +            s -= 1 << L2_PAGETABLE_SHIFT;
    6.84 +        }
    6.85 +        else
    6.86 +        {
    6.87 +            /* Normal page mapping. */
    6.88 +            if ( !(l2_pgentry_val(*pl2e) & _PAGE_PRESENT) )
    6.89 +            {
    6.90 +                newpg = safe_page_alloc();
    6.91 +                clear_page(newpg);
    6.92 +                *pl2e = mk_l2_pgentry(__pa(newpg) | __PAGE_HYPERVISOR);
    6.93 +            }
    6.94 +            pl1e = l2_pgentry_to_l1(*pl2e) + l1_table_offset(v);
    6.95 +            if ( (l1_pgentry_val(*pl1e) & _PAGE_PRESENT) )
    6.96 +                __flush_tlb_one(v);
    6.97 +            *pl1e = mk_l1_pgentry(p|flags);
    6.98 +
    6.99 +            v += 1 << L1_PAGETABLE_SHIFT;
   6.100 +            p += 1 << L1_PAGETABLE_SHIFT;
   6.101 +            s -= 1 << L1_PAGETABLE_SHIFT;
   6.102 +        }
   6.103 +    }
   6.104 +
   6.105 +    return 0;
   6.106 +}
   6.107 +
   6.108 +void __set_fixmap(
   6.109 +    enum fixed_addresses idx, unsigned long p, unsigned long flags)
   6.110 +{
   6.111 +    if ( unlikely(idx >= __end_of_fixed_addresses) )
   6.112 +        BUG();
   6.113 +    map_pages(idle_pg_table, fix_to_virt(idx), p, PAGE_SIZE, flags);
   6.114  }
   6.115  
   6.116  
   6.117  void __init paging_init(void)
   6.118  {
   6.119 +    void *newpt;
   6.120 +
   6.121 +    /* Allocate and map the machine-to-phys table. */
   6.122 +    /* XXX TODO XXX */
   6.123 +
   6.124 +    /* Create page table for ioremap(). */
   6.125 +    newpt = (void *)alloc_xenheap_page();
   6.126 +    clear_page(newpt);
   6.127 +    idle_pg_table[IOREMAP_VIRT_START >> L4_PAGETABLE_SHIFT] = 
   6.128 +        mk_l4_pgentry(__pa(newpt) | __PAGE_HYPERVISOR);
   6.129 +
   6.130 +    /* Create read-only mapping of MPT for guest-OS use. */
   6.131 +    newpt = (void *)alloc_xenheap_page();
   6.132 +    clear_page(newpt);
   6.133 +    idle_pg_table[RO_MPT_VIRT_START >> L4_PAGETABLE_SHIFT] = 
   6.134 +        mk_l4_pgentry((__pa(newpt) | __PAGE_HYPERVISOR | _PAGE_USER) &
   6.135 +                      ~_PAGE_RW);
   6.136 +    /* XXX TODO: Copy appropriate L3 entries from RDWR_MPT_VIRT_START XXX */
   6.137 +
   6.138      /* Set up linear page table mapping. */
   6.139      idle_pg_table[LINEAR_PT_VIRT_START >> L4_PAGETABLE_SHIFT] =
   6.140          mk_l4_pgentry(__pa(idle_pg_table) | __PAGE_HYPERVISOR);
     7.1 --- a/xen/include/asm-x86/config.h	Sat Jan 29 22:42:20 2005 +0000
     7.2 +++ b/xen/include/asm-x86/config.h	Mon Jan 31 23:16:27 2005 +0000
     7.3 @@ -100,7 +100,10 @@ extern void __out_of_line_bug(int line) 
     7.4  #define XENHEAP_DEFAULT_MB (16)
     7.5  
     7.6  #define PML4_ENTRY_BITS  39
     7.7 -#define PML4_ENTRY_BYTES (1UL<<PML4_ENTRY_BITS)
     7.8 +#define PML4_ENTRY_BYTES (1UL << PML4_ENTRY_BITS)
     7.9 +#define PML4_ADDR(_slot)                             \
    7.10 +    ((((_slot ## UL) >> 8) * 0xffff000000000000UL) | \
    7.11 +     (_slot ## UL << PML4_ENTRY_BITS))
    7.12  
    7.13  /*
    7.14   * Memory layout:
    7.15 @@ -120,7 +123,13 @@ extern void __out_of_line_bug(int line) 
    7.16   *    Shadow linear page table.
    7.17   *  0xffff820000000000 - 0xffff827fffffffff [512GB, 2^39 bytes, PML4:260]
    7.18   *    Per-domain mappings (e.g., GDT, LDT).
    7.19 - *  0xffff828000000000 - 0xffff8287ffffffff [512GB, 2^39 bytes, PML4:261]
    7.20 + *  0xffff828000000000 - 0xffff8283ffffffff [16GB,  2^34 bytes, PML4:261]
    7.21 + *    Machine-to-phys translation table.
    7.22 + *  0xffff828400000000 - 0xffff8287ffffffff [16GB,  2^34 bytes, PML4:261]
    7.23 + *    Page-frame information array.
    7.24 + *  0xffff828800000000 - 0xffff828bffffffff [16GB,  2^34 bytes, PML4:261]
    7.25 + *    ioremap()/fixmap area.
    7.26 + *  0xffff828c00000000 - 0xffff82ffffffffff [464GB,             PML4:261]
    7.27   *    Reserved for future use.
    7.28   *  0xffff830000000000 - 0xffff83ffffffffff [1TB,   2^40 bytes, PML4:262-263]
    7.29   *    1:1 direct mapping of all physical memory. Xen and its heap live here.
    7.30 @@ -130,26 +139,36 @@ extern void __out_of_line_bug(int line) 
    7.31   *    Guest-defined use.
    7.32   */
    7.33  
    7.34 +
    7.35  /* Hypervisor reserves PML4 slots 256 to 271 inclusive. */
    7.36 -#define HYPERVISOR_VIRT_START   (0xFFFF800000000000UL)
    7.37 -#define HYPERVISOR_VIRT_END     (0xFFFF880000000000UL)
    7.38 +#define HYPERVISOR_VIRT_START   (PML4_ADDR(256))
    7.39 +#define HYPERVISOR_VIRT_END     (HYPERVISOR_VIRT_START + PML4_ENTRY_BYTES*16)
    7.40  /* Slot 256: read-only guest-accessible machine-to-phys translation table. */
    7.41 -#define RO_MPT_VIRT_START       (HYPERVISOR_VIRT_START)
    7.42 +#define RO_MPT_VIRT_START       (PML4_ADDR(256))
    7.43  #define RO_MPT_VIRT_END         (RO_MPT_VIRT_START + PML4_ENTRY_BYTES/2)
    7.44  /* Slot 257: read-only guest-accessible linear page table. */
    7.45 -#define RO_LINEAR_PT_VIRT_START (RO_MPT_VIRT_END + PML4_ENTRY_BYTES/2)
    7.46 +#define RO_LINEAR_PT_VIRT_START (PML4_ADDR(257))
    7.47  #define RO_LINEAR_PT_VIRT_END   (RO_LINEAR_PT_VIRT_START + PML4_ENTRY_BYTES)
    7.48  /* Slot 258: linear page table (guest table). */
    7.49 -#define LINEAR_PT_VIRT_START    (RO_LINEAR_PT_VIRT_END)
    7.50 +#define LINEAR_PT_VIRT_START    (PML4_ADDR(258))
    7.51  #define LINEAR_PT_VIRT_END      (LINEAR_PT_VIRT_START + PML4_ENTRY_BYTES)
    7.52  /* Slot 259: linear page table (shadow table). */
    7.53 -#define SH_LINEAR_PT_VIRT_START (LINEAR_PT_VIRT_END)
    7.54 +#define SH_LINEAR_PT_VIRT_START (PML4_ADDR(259))
    7.55  #define SH_LINEAR_PT_VIRT_END   (SH_LINEAR_PT_VIRT_START + PML4_ENTRY_BYTES)
    7.56  /* Slot 260: per-domain mappings. */
    7.57 -#define PERDOMAIN_VIRT_START    (SH_LINEAR_PT_VIRT_END)
    7.58 +#define PERDOMAIN_VIRT_START    (PML4_ADDR(260))
    7.59  #define PERDOMAIN_VIRT_END      (PERDOMAIN_VIRT_START + PML4_ENTRY_BYTES)
    7.60 +/* Slot 261: machine-to-phys conversion table (16GB). */
    7.61 +#define RDWR_MPT_VIRT_START     (PML4_ADDR(261))
    7.62 +#define RDWR_MPT_VIRT_END       (RDWR_MPT_VIRT_START + (16UL<<30))
    7.63 +/* Slot 261: page-frame information array (16GB). */
    7.64 +#define FRAMETABLE_VIRT_START   (RDWR_MPT_VIRT_END)
    7.65 +#define FRAMETABLE_VIRT_END     (FRAMETABLE_VIRT_START + (16UL<<30))
    7.66 +/* Slot 261: ioremap()/fixmap area (16GB). */
    7.67 +#define IOREMAP_VIRT_START      (FRAMETABLE_VIRT_END)
    7.68 +#define IOREMAP_VIRT_END        (IOREMAP_VIRT_START + (16UL<<30))
    7.69  /* Slot 262-263: A direct 1:1 mapping of all of physical memory. */
    7.70 -#define DIRECTMAP_VIRT_START    (PERDOMAIN_VIRT_END + PML4_ENTRY_BYTES)
    7.71 +#define DIRECTMAP_VIRT_START    (PML4_ADDR(262))
    7.72  #define DIRECTMAP_VIRT_END      (DIRECTMAP_VIRT_START + PML4_ENTRY_BYTES*2)
    7.73  
    7.74  #define PGT_base_page_table PGT_l4_page_table
    7.75 @@ -180,10 +199,8 @@ extern void __out_of_line_bug(int line) 
    7.76  /* Xen heap extends to end of 1:1 direct-mapped memory region. */
    7.77  #define DIRECTMAP_VIRT_START  (RO_MPT_VIRT_END)
    7.78  #define DIRECTMAP_VIRT_END    (DIRECTMAP_VIRT_START + DIRECTMAP_PHYS_END)
    7.79 -#define XENHEAP_VIRT_START    (DIRECTMAP_VIRT_START)
    7.80 -#define XENHEAP_VIRT_END      (DIRECTMAP_VIRT_END)
    7.81  /* Machine-to-phys conversion table. */
    7.82 -#define RDWR_MPT_VIRT_START   (XENHEAP_VIRT_END)
    7.83 +#define RDWR_MPT_VIRT_START   (DIRECTMAP_VIRT_END)
    7.84  #define RDWR_MPT_VIRT_END     (RDWR_MPT_VIRT_START + (4*1024*1024))
    7.85  /* Variable-length page-frame information array. */
    7.86  #define FRAMETABLE_VIRT_START (RDWR_MPT_VIRT_END)
     8.1 --- a/xen/include/asm-x86/domain_page.h	Sat Jan 29 22:42:20 2005 +0000
     8.2 +++ b/xen/include/asm-x86/domain_page.h	Mon Jan 31 23:16:27 2005 +0000
     8.3 @@ -1,29 +1,5 @@
     8.4 -/******************************************************************************
     8.5 - * domain_page.h
     8.6 - * 
     8.7 - * Allow temporary mapping of domain page frames into Xen space.
     8.8 - */
     8.9 -
    8.10 -#ifndef __ASM_DOMAIN_PAGE_H__
    8.11 -#define __ASM_DOMAIN_PAGE_H__
    8.12 -
    8.13 -#include <xen/config.h>
    8.14 -#include <xen/sched.h>
    8.15 -
    8.16 -extern unsigned long *mapcache;
    8.17 -#define MAPCACHE_ENTRIES        1024
    8.18 -
    8.19 -/*
    8.20 - * Maps a given physical address, returning corresponding virtual address.
    8.21 - * The entire page containing that VA is now accessible until a 
    8.22 - * corresponding call to unmap_domain_mem().
    8.23 - */
    8.24 -extern void *map_domain_mem(unsigned long pa);
    8.25 -
    8.26 -/*
    8.27 - * Pass a VA within a page previously mapped with map_domain_mem().
    8.28 - * That page will then be removed from the mapping lists.
    8.29 - */
    8.30 -extern void unmap_domain_mem(void *va);
    8.31 -
    8.32 -#endif /* __ASM_DOMAIN_PAGE_H__ */
    8.33 +#ifdef __x86_64__
    8.34 +#include <asm/x86_64/domain_page.h>
    8.35 +#else
    8.36 +#include <asm/x86_32/domain_page.h>
    8.37 +#endif
     9.1 --- a/xen/include/asm-x86/fixmap.h	Sat Jan 29 22:42:20 2005 +0000
     9.2 +++ b/xen/include/asm-x86/fixmap.h	Mon Jan 31 23:16:27 2005 +0000
     9.3 @@ -39,18 +39,18 @@ enum fixed_addresses {
     9.4      __end_of_fixed_addresses
     9.5  };
     9.6  
     9.7 -#define FIXADDR_TOP   (0xffffe000UL)
     9.8 +#define FIXADDR_TOP   (IOREMAP_VIRT_END - PAGE_SIZE)
     9.9  #define FIXADDR_SIZE  (__end_of_fixed_addresses << PAGE_SHIFT)
    9.10  #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
    9.11  
    9.12 -extern void __set_fixmap(enum fixed_addresses idx,
    9.13 -                         l1_pgentry_t entry);
    9.14 +extern void __set_fixmap(
    9.15 +    enum fixed_addresses idx, unsigned long p, unsigned long flags);
    9.16  
    9.17  #define set_fixmap(idx, phys) \
    9.18 -    __set_fixmap(idx, mk_l1_pgentry(phys|PAGE_HYPERVISOR))
    9.19 +    __set_fixmap(idx, phys, PAGE_HYPERVISOR)
    9.20  
    9.21  #define set_fixmap_nocache(idx, phys) \
    9.22 -    __set_fixmap(idx, mk_l1_pgentry(phys|PAGE_HYPERVISOR_NOCACHE))
    9.23 +    __set_fixmap(idx, phys, PAGE_HYPERVISOR_NOCACHE)
    9.24  
    9.25  #define fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
    9.26  
    10.1 --- a/xen/include/asm-x86/mm.h	Sat Jan 29 22:42:20 2005 +0000
    10.2 +++ b/xen/include/asm-x86/mm.h	Mon Jan 31 23:16:27 2005 +0000
    10.3 @@ -222,17 +222,11 @@ void synchronise_pagetables(unsigned lon
    10.4   */
    10.5  #undef  phys_to_machine_mapping
    10.6  
    10.7 -#ifdef __x86_64__
    10.8 -extern unsigned long *machine_to_phys_mapping;
    10.9 -extern unsigned long *phys_to_machine_mapping;
   10.10 -#define m2p_start_mfn virt_to_phys(machine_to_phys_mapping)
   10.11 -#else
   10.12  /* Don't call virt_to_phys on this: it isn't direct mapped.  Using
   10.13     m2p_start_mfn instead. */
   10.14  #define machine_to_phys_mapping ((unsigned long *)RDWR_MPT_VIRT_START)
   10.15  extern unsigned long m2p_start_mfn;
   10.16  #define phys_to_machine_mapping ((unsigned long *)PERDOMAIN_VIRT_START)
   10.17 -#endif
   10.18  
   10.19  #define set_machinetophys(_mfn, _pfn) machine_to_phys_mapping[(_mfn)] = (_pfn)
   10.20  
    11.1 --- a/xen/include/asm-x86/page.h	Sat Jan 29 22:42:20 2005 +0000
    11.2 +++ b/xen/include/asm-x86/page.h	Mon Jan 31 23:16:27 2005 +0000
    11.3 @@ -46,7 +46,6 @@ typedef struct { unsigned long l1_lo; } 
    11.4  typedef struct { unsigned long l2_lo; } l2_pgentry_t;
    11.5  typedef struct { unsigned long l3_lo; } l3_pgentry_t;
    11.6  typedef struct { unsigned long l4_lo; } l4_pgentry_t;
    11.7 -typedef struct { unsigned long pt_lo; } pagetable_t;
    11.8  #endif /* !__ASSEMBLY__ */
    11.9  
   11.10  /* Strip type from a table entry. */
   11.11 @@ -54,14 +53,12 @@ typedef struct { unsigned long pt_lo; } 
   11.12  #define l2_pgentry_val(_x) ((_x).l2_lo)
   11.13  #define l3_pgentry_val(_x) ((_x).l3_lo)
   11.14  #define l4_pgentry_val(_x) ((_x).l4_lo)
   11.15 -#define pagetable_val(_x)  ((_x).pt_lo)
   11.16  
   11.17  /* Add type to a table entry. */
   11.18  #define mk_l1_pgentry(_x)  ( (l1_pgentry_t) { (_x) } )
   11.19  #define mk_l2_pgentry(_x)  ( (l2_pgentry_t) { (_x) } )
   11.20  #define mk_l3_pgentry(_x)  ( (l3_pgentry_t) { (_x) } )
   11.21  #define mk_l4_pgentry(_x)  ( (l4_pgentry_t) { (_x) } )
   11.22 -#define mk_pagetable(_x)   ( (pagetable_t) { (_x) } )
   11.23  
   11.24  /* Turn a typed table entry into a page index. */
   11.25  #define l1_pgentry_to_pagenr(_x) (l1_pgentry_val(_x) >> PAGE_SHIFT) 
   11.26 @@ -91,11 +88,23 @@ typedef struct { unsigned long pt_lo; } 
   11.27    ((_a) >> L2_PAGETABLE_SHIFT)
   11.28  #elif defined(__x86_64__)
   11.29  #define l2_table_offset(_a) \
   11.30 -  (((_a) >> L2_PAGETABLE_SHIFT) & (ENTRIES_PER_L2_PAGETABLE -1))
   11.31 +  (((_a) >> L2_PAGETABLE_SHIFT) & (ENTRIES_PER_L2_PAGETABLE - 1))
   11.32  #define l3_table_offset(_a) \
   11.33 -  (((_a) >> L3_PAGETABLE_SHIFT) & (ENTRIES_PER_L3_PAGETABLE -1))
   11.34 +  (((_a) >> L3_PAGETABLE_SHIFT) & (ENTRIES_PER_L3_PAGETABLE - 1))
   11.35  #define l4_table_offset(_a) \
   11.36 -  ((_a) >> L4_PAGETABLE_SHIFT)
   11.37 +  (((_a) >> L4_PAGETABLE_SHIFT) & (ENTRIES_PER_L4_PAGETABLE - 1))
   11.38 +#endif
   11.39 +
   11.40 +#if defined(__i386__)
   11.41 +#define pagetable_t l2_pgentry_t
   11.42 +#define pagetable_val(_x)  ((_x).l2_lo)
   11.43 +#define mk_pagetable(_x)   ( (l2_pgentry_t) { (_x) } )
   11.44 +#define ENTRIES_PER_PAGETABLE ENTRIES_PER_L2_PAGETABLE
   11.45 +#elif defined(__x86_64__)
   11.46 +#define pagetable_t l4_pgentry_t
   11.47 +#define pagetable_val(_x)  ((_x).l4_lo)
   11.48 +#define mk_pagetable(_x)   ( (l4_pgentry_t) { (_x) } )
   11.49 +#define ENTRIES_PER_PAGETABLE ENTRIES_PER_L4_PAGETABLE
   11.50  #endif
   11.51  
   11.52  #define PAGE_OFFSET		((unsigned long)__PAGE_OFFSET)
   11.53 @@ -131,11 +140,7 @@ typedef struct { unsigned long pt_lo; } 
   11.54  
   11.55  #define va_to_l1mfn(_va) (l2_pgentry_val(linear_l2_table[_va>>L2_PAGETABLE_SHIFT]) >> PAGE_SHIFT)
   11.56  
   11.57 -#ifdef __i386__
   11.58 -extern l2_pgentry_t idle_pg_table[ENTRIES_PER_L2_PAGETABLE];
   11.59 -#else
   11.60 -extern l4_pgentry_t idle_pg_table[ENTRIES_PER_L4_PAGETABLE];
   11.61 -#endif
   11.62 +extern pagetable_t idle_pg_table[ENTRIES_PER_PAGETABLE];
   11.63  
   11.64  extern void paging_init(void);
   11.65  
   11.66 @@ -191,6 +196,7 @@ extern void paging_init(void);
   11.67  #define PAGE_HYPERVISOR_NOCACHE MAKE_GLOBAL(__PAGE_HYPERVISOR_NOCACHE)
   11.68  
   11.69  #ifndef __ASSEMBLY__
   11.70 +
   11.71  static __inline__ int get_order(unsigned long size)
   11.72  {
   11.73      int order;
   11.74 @@ -205,6 +211,16 @@ static __inline__ int get_order(unsigned
   11.75  }
   11.76  
   11.77  extern void zap_low_mappings(void);
   11.78 -#endif
   11.79 +
   11.80 +/* Map physical byte range (@p, @p+@s) at virt address @v in pagetable @pt. */
   11.81 +extern int
   11.82 +map_pages(
   11.83 +    pagetable_t *pt,
   11.84 +    unsigned long v,
   11.85 +    unsigned long p,
   11.86 +    unsigned long s,
   11.87 +    unsigned long flags);
   11.88 +
   11.89 +#endif /* !__ASSEMBLY__ */
   11.90  
   11.91  #endif /* __I386_PAGE_H__ */
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/xen/include/asm-x86/x86_32/domain_page.h	Mon Jan 31 23:16:27 2005 +0000
    12.3 @@ -0,0 +1,29 @@
    12.4 +/******************************************************************************
    12.5 + * domain_page.h
    12.6 + * 
    12.7 + * Allow temporary mapping of domain page frames into Xen space.
    12.8 + */
    12.9 +
   12.10 +#ifndef __ASM_DOMAIN_PAGE_H__
   12.11 +#define __ASM_DOMAIN_PAGE_H__
   12.12 +
   12.13 +#include <xen/config.h>
   12.14 +#include <xen/sched.h>
   12.15 +
   12.16 +extern unsigned long *mapcache;
   12.17 +#define MAPCACHE_ENTRIES        1024
   12.18 +
   12.19 +/*
   12.20 + * Maps a given physical address, returning corresponding virtual address.
   12.21 + * The entire page containing that VA is now accessible until a 
   12.22 + * corresponding call to unmap_domain_mem().
   12.23 + */
   12.24 +extern void *map_domain_mem(unsigned long pa);
   12.25 +
   12.26 +/*
   12.27 + * Pass a VA within a page previously mapped with map_domain_mem().
   12.28 + * That page will then be removed from the mapping lists.
   12.29 + */
   12.30 +extern void unmap_domain_mem(void *va);
   12.31 +
   12.32 +#endif /* __ASM_DOMAIN_PAGE_H__ */
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/xen/include/asm-x86/x86_64/domain_page.h	Mon Jan 31 23:16:27 2005 +0000
    13.3 @@ -0,0 +1,13 @@
    13.4 +/******************************************************************************
    13.5 + * domain_page.h
    13.6 + * 
    13.7 + * This is a trivial no-op on x86/64, where we can 1:1 map all RAM.
    13.8 + */
    13.9 +
   13.10 +#ifndef __ASM_DOMAIN_PAGE_H__
   13.11 +#define __ASM_DOMAIN_PAGE_H__
   13.12 +
   13.13 +#define map_domain_mem(_pa)   phys_to_virt(_pa)
   13.14 +#define unmap_domain_mem(_va) ((void)(_va))
   13.15 +
   13.16 +#endif /* __ASM_DOMAIN_PAGE_H__ */