ia64/xen-unstable

view extras/mini-os/arch/ia64/common.c @ 13907:ac18d251df63

[IA64][MINIOS] Port of mini-os to ia64

ia64 specific parts of mini-os.

Minimal config:

# Kernel image file.
kernel = "mini-os.gz"
# Initial memory allocation (in megabytes) for the new domain.
memory = 64
# A name for your domain.
name = "Mini-OS"

Signed-off-by: Dietmar Hahn <dietmar.hahn@fujitsu-siemens.com>
author awilliam@xenbuild2.aw
date Thu Feb 15 13:13:36 2007 -0700 (2007-02-15)
parents
children d1853a39e063
line source
1 /*
2 * Done by Dietmar Hahn <dietmar.hahn@fujitsu-siemens.com>
3 *
4 ****************************************************************************
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 ****************************************************************************
28 *
29 * Parts are taken from FreeBSD.
30 *
31 */
34 #include "os.h"
35 #include "types.h"
36 #include "lib.h"
37 #include "page.h"
38 #include "xen/xen.h"
39 #include "privop.h"
40 #include "xen/callback.h"
41 #include "ia64_cpu.h"
42 #include "hypervisor.h"
43 #include "events.h"
44 #include "console.h"
45 #include "time.h"
46 #include "xmalloc.h"
49 /* For more console boot messages. */
50 int bootverbose;
52 /*
53 * This structure contains start-of-day info, such as pagetable base pointer,
54 * address of the shared_info structure, and things like that.
55 */
56 union start_info_union start_info_union;
58 shared_info_t *HYPERVISOR_shared_info = (shared_info_t *)XSI_BASE;
60 struct machine_fw machineFwG;
63 struct xen_ia64_boot_param ia64BootParamG;
64 char boot_cmd_line[COMMAND_LINE_SIZE+1];
67 void
68 ia64_write_itr_i(ia64_pte_t* pteP, u32 reg, uint64_t vAddr,
69 uint64_t ps, uint64_t pk)
70 {
71 /* The virtual address. */
72 __asm __volatile("mov cr.ifa=%0" :: "r"(vAddr));
73 /* The page size */
74 __asm __volatile("mov cr.itir=%0;;" :: "r"((ps << IA64_ITIR_PS)|(pk << IA64_ITIR_KEY)));
75 /* Put pte into instruction translation register. */
76 __asm __volatile("itr.i itr[%0]=%1" :: "r"(reg), "r"(*(uint64_t*)pteP));
77 /* Serialization */
78 __asm __volatile("srlz.i");
79 }
81 void
82 map_pal_code(void)
83 {
84 ia64_pte_t pte;
86 xen_set_virtual_psr_ic(0);
87 memset(&pte, 0, sizeof(pte)); /* Prepare the pte */
88 pte.pte_p = 1; /* present bit */
89 pte.pte_ma = PTE_MA_WB; /* memory attribute */
90 pte.pte_a = 1; /* accessed bit */
91 pte.pte_d = 1; /* dirty bit */
92 pte.pte_pl = PTE_PL_KERN; /* privilege level */
93 pte.pte_ar = PTE_AR_RWX; /* access rights */
94 pte.pte_ppn = ((uint64_t) __pa(machineFwG.ia64_pal_base)) >> 14;
95 pte.pte_ed = 0; /* exception deferral */
97 /*
98 * Must purge here because a itc/dtc with the same address
99 * may be in the tlb!
100 */
101 ia64_ptc_l(machineFwG.ia64_pal_base, PTE_PS_16K);
102 ia64_write_itr_i(&pte, IA64_TR_PAL,
103 (uint64_t) machineFwG.ia64_pal_base, PTE_PS_16K, 0);
104 xen_set_virtual_psr_ic(1);
105 }
107 extern char hypervisor_callback;
109 static void
110 registerCallback(void)
111 {
112 struct callback_register event =
113 {
114 .type = SWAP(CALLBACKTYPE_event),
115 .address = SWAP((unsigned long)&hypervisor_callback),
116 };
117 HYPERVISOR_callback_op(CALLBACKOP_register, &event);
118 }
120 static void
121 init_start_info(start_info_t* xen_start_info)
122 {
123 /* Make a copy of the start_info structure */
124 start_info.nr_pages = SWAP(xen_start_info->nr_pages);
125 start_info.shared_info = SWAP(xen_start_info->shared_info);
126 start_info.flags = SWAP(xen_start_info->flags);
127 start_info.store_mfn = SWAP(xen_start_info->store_mfn);
128 start_info.store_evtchn = SWAP(xen_start_info->store_evtchn);
129 start_info.console.domU.mfn = SWAP(xen_start_info->console.domU.mfn);
130 start_info.console.domU.evtchn =
131 SWAP(xen_start_info->console.domU.evtchn);
132 start_info.pt_base = SWAP(xen_start_info->pt_base);
133 start_info.nr_pt_frames = SWAP(xen_start_info->nr_pt_frames);
134 start_info.mfn_list = SWAP(xen_start_info->mfn_list);
135 start_info.mod_start = SWAP(xen_start_info->mod_start);
136 start_info.mod_len = SWAP(xen_start_info->mod_len);
137 }
139 static void
140 init_boot_params(void)
141 {
142 /* ia64_boot_paramP is initialised in ia64.S! */
143 ia64BootParamG.command_line = SWAP(ia64_boot_paramP->command_line);
144 ia64BootParamG.efi_systab = SWAP(ia64_boot_paramP->efi_systab);
145 ia64BootParamG.efi_memmap = SWAP(ia64_boot_paramP->efi_memmap);
146 ia64BootParamG.efi_memmap_size =
147 SWAP(ia64_boot_paramP->efi_memmap_size);
148 ia64BootParamG.efi_memdesc_size =
149 SWAP(ia64_boot_paramP->efi_memdesc_size);
150 ia64BootParamG.efi_memdesc_version =
151 SWAP(ia64_boot_paramP->efi_memdesc_version);
152 ia64BootParamG.console_info.num_cols =
153 SWAP(ia64_boot_paramP->console_info.num_cols);
154 ia64BootParamG.console_info.num_rows =
155 SWAP(ia64_boot_paramP->console_info.num_rows);
156 ia64BootParamG.console_info.orig_x =
157 SWAP(ia64_boot_paramP->console_info.orig_x);
158 ia64BootParamG.console_info.orig_y =
159 SWAP(ia64_boot_paramP->console_info.orig_y);
160 ia64BootParamG.fpswa = SWAP(ia64_boot_paramP->fpswa);
161 ia64BootParamG.initrd_start = SWAP(ia64_boot_paramP->initrd_start);
162 ia64BootParamG.initrd_size = SWAP(ia64_boot_paramP->initrd_size);
163 ia64BootParamG.domain_start = SWAP(ia64_boot_paramP->domain_start);
164 ia64BootParamG.domain_size = SWAP(ia64_boot_paramP->domain_size);
166 /*
167 * Copy and parse the boot command line.
168 * Currently only a check of bootverbose is done.
169 */
170 memset(boot_cmd_line, 0, sizeof(boot_cmd_line));
171 strncpy(boot_cmd_line,
172 (char*)__va(ia64BootParamG.command_line), COMMAND_LINE_SIZE);
173 boot_cmd_line[COMMAND_LINE_SIZE - 1] = '\0';
175 /* Look for bootverbose. */
176 if (strstr(boot_cmd_line, "bootverbose"))
177 bootverbose = 1;
178 }
180 void
181 arch_init(start_info_t *si)
182 {
183 efi_time_t tm;
184 static int initialized;
186 if (initialized)
187 return;
189 init_start_info(si);
191 init_boot_params();
193 init_efi();
195 map_pal_code();
197 ia64_sal_init(machineFwG.ia64_sal_tableP);
199 if (efi_get_time(&tm)) {
200 printk("EFI-SystemTime: %d.%d.%d %d:%d:%d",
201 tm.Day, tm.Month, tm.Year,
202 tm.Hour, tm.Minute, tm.Second);
204 if (tm.TimeZone == EFI_UNSPECIFIED_TIMEZONE)
205 printk(" Timezone not specified!\n");
206 else
207 printk(" TimeZone: %d Daylight: 0x%x\n",
208 tm.TimeZone, tm.Daylight);
209 } else
210 printk("efi_get_time() failed\n");
212 registerCallback();
213 initialized = 1;
214 }
216 void
217 arch_print_info(void)
218 {
219 int major, minor;
221 minor = HYPERVISOR_xen_version(XENVER_version, 0);
222 major = minor >> 16;
223 minor &= ~0xffffffff;
224 printk("Running on Xen version: %d.%d\n", major, minor);
225 printk("machine addr of shared_info_t : 0x%lx\n",
226 start_info.shared_info);
227 printk("machine page number of shared page: 0x%lx\n",
228 start_info.store_mfn);
229 printk("evtchn for store communication : %d\n",
230 start_info.store_evtchn);
231 printk("MACHINE address of console page: 0x%lx\n",
232 start_info.console.domU.mfn);
233 printk("evtchn for console messages : %d\n",
234 start_info.console.domU.evtchn);
235 printk("xen_guest_cmdline : %s\n", boot_cmd_line);
236 }