source: mainline/kernel/arch/ia64/src/ia64.c@ eec201d

Last change on this file since eec201d was c5429fe, checked in by Jakub Jermar <jakub@…>, 7 years ago

Disambiguate architecture specific doxygroups

  • Property mode set to 100644
File size: 7.4 KB
Line 
1/*
2 * Copyright (c) 2005 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - 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 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup kernel_ia64
30 * @{
31 */
32/** @file
33 */
34
35#include <arch.h>
36#include <arch/arch.h>
37#include <typedefs.h>
38#include <errno.h>
39#include <interrupt.h>
40#include <arch/interrupt.h>
41#include <macros.h>
42#include <stdbool.h>
43#include <str.h>
44#include <userspace.h>
45#include <console/console.h>
46#include <syscall/syscall.h>
47#include <sysinfo/sysinfo.h>
48#include <arch/drivers/it.h>
49#include <arch/drivers/kbd.h>
50#include <arch/legacyio.h>
51#include <genarch/drivers/ega/ega.h>
52#include <genarch/drivers/i8042/i8042.h>
53#include <genarch/drivers/ns16550/ns16550.h>
54#include <genarch/drivers/legacy/ia32/io.h>
55#include <genarch/kbrd/kbrd.h>
56#include <genarch/srln/srln.h>
57#include <mm/page.h>
58#include <mm/km.h>
59
60#ifdef MACHINE_ski
61#include <arch/drivers/ski.h>
62#endif
63
64static void ia64_pre_mm_init(void);
65static void ia64_post_mm_init(void);
66static void ia64_post_smp_init(void);
67
68arch_ops_t ia64_ops = {
69 .pre_mm_init = ia64_pre_mm_init,
70 .post_mm_init = ia64_post_mm_init,
71 .post_smp_init = ia64_post_smp_init,
72};
73
74arch_ops_t *arch_ops = &ia64_ops;
75
76/* NS16550 as a COM 1 */
77#define NS16550_IRQ (4 + LEGACY_INTERRUPT_BASE)
78
79bootinfo_t *bootinfo;
80
81static uint64_t iosapic_base = 0xfec00000;
82uintptr_t legacyio_virt_base = 0;
83
84/** Performs ia64-specific initialization before main_bsp() is called. */
85void ia64_pre_main(void)
86{
87 init.cnt = min3(bootinfo->taskmap.cnt, TASKMAP_MAX_RECORDS,
88 CONFIG_INIT_TASKS);
89 size_t i;
90
91 for (i = 0; i < init.cnt; i++) {
92 init.tasks[i].paddr =
93 (uintptr_t) bootinfo->taskmap.tasks[i].addr;
94 init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
95 str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
96 bootinfo->taskmap.tasks[i].name);
97 }
98}
99
100void ia64_pre_mm_init(void)
101{
102 if (config.cpu_active == 1)
103 exception_init();
104}
105
106static void iosapic_init(void)
107{
108 uintptr_t IOSAPIC = km_map(iosapic_base, PAGE_SIZE, PAGE_SIZE,
109 PAGE_WRITE | PAGE_NOT_CACHEABLE);
110 int i;
111
112 int myid, myeid;
113
114 myid = ia64_get_cpu_id();
115 myeid = ia64_get_cpu_eid();
116
117 for (i = 0; i < 16; i++) {
118 if (i == 2)
119 continue; /* Disable Cascade interrupt */
120 ((uint32_t *)(IOSAPIC + 0x00))[0] = 0x10 + 2 * i;
121 srlz_d();
122 ((uint32_t *)(IOSAPIC + 0x10))[0] = LEGACY_INTERRUPT_BASE + i;
123 srlz_d();
124 ((uint32_t *)(IOSAPIC + 0x00))[0] = 0x10 + 2 * i + 1;
125 srlz_d();
126 ((uint32_t *)(IOSAPIC + 0x10))[0] = myid << (56 - 32) |
127 myeid << (48 - 32);
128 srlz_d();
129 }
130
131}
132
133void ia64_post_mm_init(void)
134{
135 if (config.cpu_active == 1) {
136 /* Map the page with legacy I/O. */
137 legacyio_virt_base = km_map(LEGACYIO_PHYS_BASE, LEGACYIO_SIZE,
138 KM_NATURAL_ALIGNMENT, PAGE_WRITE | PAGE_NOT_CACHEABLE);
139
140 iosapic_init();
141 irq_init(INR_COUNT, INR_COUNT);
142 }
143 it_init();
144}
145
146void ia64_post_smp_init(void)
147{
148 static const char *platform;
149
150 /* Set platform name. */
151#ifdef MACHINE_ski
152 platform = "ski";
153#endif
154#ifdef MACHINE_i460GX
155 platform = "pc";
156#endif
157 sysinfo_set_item_data("platform", NULL, (void *) platform,
158 str_size(platform));
159
160#ifdef MACHINE_ski
161 ski_instance_t *ski_instance = skiin_init();
162 if (ski_instance) {
163 srln_instance_t *srln_instance = srln_init();
164 if (srln_instance) {
165 indev_t *sink = stdin_wire();
166 indev_t *srln = srln_wire(srln_instance, sink);
167 skiin_wire(ski_instance, srln);
168 }
169 }
170
171 outdev_t *skidev = skiout_init();
172 if (skidev)
173 stdout_wire(skidev);
174#endif
175
176#ifdef CONFIG_EGA
177 outdev_t *egadev = ega_init(EGA_BASE, EGA_VIDEORAM);
178 if (egadev)
179 stdout_wire(egadev);
180#endif
181
182#ifdef CONFIG_NS16550
183 ns16550_instance_t *ns16550_instance =
184 ns16550_init(NS16550_BASE, 0, NS16550_IRQ, NULL, NULL,
185 NULL);
186 if (ns16550_instance) {
187 srln_instance_t *srln_instance = srln_init();
188 if (srln_instance) {
189 indev_t *sink = stdin_wire();
190 indev_t *srln = srln_wire(srln_instance, sink);
191 ns16550_wire(ns16550_instance, srln);
192 }
193 }
194
195 sysinfo_set_item_val("kbd", NULL, true);
196 sysinfo_set_item_val("kbd.inr", NULL, NS16550_IRQ);
197 sysinfo_set_item_val("kbd.type", NULL, KBD_NS16550);
198 sysinfo_set_item_val("kbd.address.physical", NULL,
199 (uintptr_t) NS16550_BASE);
200#endif
201
202#ifdef CONFIG_I8042
203 i8042_instance_t *i8042_instance = i8042_init((i8042_t *) I8042_BASE,
204 IRQ_KBD);
205 if (i8042_instance) {
206 kbrd_instance_t *kbrd_instance = kbrd_init();
207 if (kbrd_instance) {
208 indev_t *sink = stdin_wire();
209 indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
210 i8042_wire(i8042_instance, kbrd);
211 }
212 }
213#endif
214
215 sysinfo_set_item_val("ia64_iospace", NULL, true);
216 sysinfo_set_item_val("ia64_iospace.address", NULL, true);
217 sysinfo_set_item_val("ia64_iospace.address.virtual", NULL, LEGACYIO_USER_BASE);
218}
219
220/** Enter userspace and never return. */
221void userspace(uspace_arg_t *kernel_uarg)
222{
223 psr_t psr;
224 rsc_t rsc;
225
226 psr.value = psr_read();
227 psr.cpl = PL_USER;
228 psr.i = true; /* start with interrupts enabled */
229 psr.ic = true;
230 psr.ri = 0; /* start with instruction #0 */
231 psr.bn = 1; /* start in bank 0 */
232
233 asm volatile ("mov %0 = ar.rsc\n" : "=r" (rsc.value));
234 rsc.loadrs = 0;
235 rsc.be = false;
236 rsc.pl = PL_USER;
237 rsc.mode = 3; /* eager mode */
238
239 /*
240 * Switch to userspace.
241 *
242 * When calculating stack addresses, mind the stack split between the
243 * memory stack and the RSE stack. Each occuppies
244 * uspace_stack_size / 2 bytes.
245 */
246 switch_to_userspace((uintptr_t) kernel_uarg->uspace_entry,
247 ((uintptr_t) kernel_uarg->uspace_stack) +
248 kernel_uarg->uspace_stack_size / 2 -
249 ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT),
250 ((uintptr_t) kernel_uarg->uspace_stack) +
251 kernel_uarg->uspace_stack_size / 2,
252 (uintptr_t) kernel_uarg->uspace_uarg, psr.value, rsc.value);
253
254 while (true)
255 ;
256}
257
258void arch_reboot(void)
259{
260 pio_write_8((ioport8_t *)0x64, 0xfe);
261 while (true)
262 ;
263}
264
265/** Construct function pointer
266 *
267 * @param fptr function pointer structure
268 * @param addr function address
269 * @param caller calling function address
270 *
271 * @return address of the function pointer
272 *
273 */
274void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
275{
276 fptr->fnc = (sysarg_t) addr;
277 fptr->gp = ((sysarg_t *) caller)[1];
278
279 return (void *) fptr;
280}
281
282void irq_initialize_arch(irq_t *irq)
283{
284 (void) irq;
285}
286
287/** @}
288 */
Note: See TracBrowser for help on using the repository browser.