source: mainline/kernel/arch/ia32/src/ia32.c@ 156bae23

Last change on this file since 156bae23 was 6e5252a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Place AP bootstrap correctly via linker script instead of manual copy

  • Property mode set to 100644
File size: 6.3 KB
Line 
1/*
2 * Copyright (c) 2001-2004 Jakub Jermar
3 * Copyright (c) 2009 Jiri Svoboda
4 * Copyright (c) 2009 Martin Decky
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** @addtogroup kernel_ia32
32 * @{
33 */
34/** @file
35 */
36
37#include <arch.h>
38#include <arch/arch.h>
39#include <stdint.h>
40#include <errno.h>
41#include <mem.h>
42#include <interrupt.h>
43#include <console/console.h>
44#include <syscall/syscall.h>
45#include <sysinfo/sysinfo.h>
46#include <arch/bios/bios.h>
47#include <arch/boot/boot.h>
48#include <arch/drivers/i8254.h>
49#include <arch/drivers/i8259.h>
50#include <genarch/acpi/acpi.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/fb/bfb.h>
56#include <genarch/kbrd/kbrd.h>
57#include <genarch/srln/srln.h>
58#include <genarch/multiboot/multiboot.h>
59#include <genarch/multiboot/multiboot2.h>
60#include <arch/pm.h>
61#include <arch/vreg.h>
62
63#ifdef CONFIG_SMP
64#include <arch/smp/apic.h>
65#endif
66
67static void ia32_pre_mm_init(void);
68static void ia32_post_mm_init(void);
69static void ia32_post_cpu_init(void);
70static void ia32_pre_smp_init(void);
71static void ia32_post_smp_init(void);
72
73arch_ops_t ia32_ops = {
74 .pre_mm_init = ia32_pre_mm_init,
75 .post_mm_init = ia32_post_mm_init,
76 .post_cpu_init = ia32_post_cpu_init,
77 .pre_smp_init = ia32_pre_smp_init,
78 .post_smp_init = ia32_post_smp_init,
79};
80
81arch_ops_t *arch_ops = &ia32_ops;
82
83/** Perform ia32-specific initialization before main_bsp() is called.
84 *
85 * @param signature Multiboot signature.
86 * @param info Multiboot information structure.
87 *
88 */
89void ia32_pre_main(uint32_t signature, void *info)
90{
91 /* Parse multiboot information obtained from the bootloader. */
92 multiboot_info_parse(signature, (multiboot_info_t *) info);
93 multiboot2_info_parse(signature, (multiboot2_info_t *) info);
94}
95
96void ia32_pre_mm_init(void)
97{
98 pm_init();
99
100 if (config.cpu_active == 1) {
101 interrupt_init();
102 bios_init();
103
104 /* PIC */
105 i8259_init();
106 }
107}
108
109void ia32_post_mm_init(void)
110{
111 vreg_init();
112
113 if (config.cpu_active == 1) {
114 /* Initialize IRQ routing */
115 irq_init(IRQ_COUNT, IRQ_COUNT);
116
117 /* hard clock */
118 i8254_init();
119
120#if (defined(CONFIG_FB) || defined(CONFIG_EGA))
121 bool bfb = false;
122#endif
123
124#ifdef CONFIG_FB
125 bfb = bfb_init();
126#endif
127
128#ifdef CONFIG_EGA
129 if (!bfb) {
130 outdev_t *egadev = ega_init(EGA_BASE, EGA_VIDEORAM);
131 if (egadev)
132 stdout_wire(egadev);
133 }
134#endif
135
136 /* Merge all memory zones to 1 big zone */
137 zone_merge_all();
138 }
139}
140
141void ia32_post_cpu_init(void)
142{
143#ifdef CONFIG_SMP
144 if (config.cpu_active > 1) {
145 l_apic_init();
146 l_apic_debug();
147 }
148#endif
149}
150
151void ia32_pre_smp_init(void)
152{
153 if (config.cpu_active == 1) {
154#ifdef CONFIG_SMP
155 acpi_init();
156#endif /* CONFIG_SMP */
157 }
158}
159
160void ia32_post_smp_init(void)
161{
162 /* Currently the only supported platform for ia32 is 'pc'. */
163 static const char *platform = "pc";
164
165 sysinfo_set_item_data("platform", NULL, (void *) platform,
166 str_size(platform));
167
168#ifdef CONFIG_PC_KBD
169 /*
170 * Initialize the i8042 controller. Then initialize the keyboard
171 * module and connect it to i8042. Enable keyboard interrupts.
172 */
173 i8042_instance_t *i8042_instance = i8042_init((i8042_t *) I8042_BASE, IRQ_KBD);
174 if (i8042_instance) {
175 kbrd_instance_t *kbrd_instance = kbrd_init();
176 if (kbrd_instance) {
177 indev_t *sink = stdin_wire();
178 indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
179 i8042_wire(i8042_instance, kbrd);
180 trap_virtual_enable_irqs(1 << IRQ_KBD);
181 trap_virtual_enable_irqs(1 << IRQ_MOUSE);
182 }
183 }
184#endif
185
186#if (defined(CONFIG_NS16550) || defined(CONFIG_NS16550_OUT))
187 /*
188 * Initialize the ns16550 controller.
189 */
190#ifdef CONFIG_NS16550_OUT
191 outdev_t *ns16550_out;
192 outdev_t **ns16550_out_ptr = &ns16550_out;
193#else
194 outdev_t **ns16550_out_ptr = NULL;
195#endif
196 ns16550_instance_t *ns16550_instance =
197 ns16550_init(NS16550_BASE, 0, IRQ_NS16550, NULL, NULL,
198 ns16550_out_ptr);
199 if (ns16550_instance) {
200#ifdef CONFIG_NS16550
201 srln_instance_t *srln_instance = srln_init();
202 if (srln_instance) {
203 indev_t *sink = stdin_wire();
204 indev_t *srln = srln_wire(srln_instance, sink);
205 ns16550_wire(ns16550_instance, srln);
206 trap_virtual_enable_irqs(1 << IRQ_NS16550);
207 }
208#endif
209#ifdef CONFIG_NS16550_OUT
210 if (ns16550_out) {
211 stdout_wire(ns16550_out);
212 }
213#endif
214 }
215#endif
216
217 if (irqs_info != NULL)
218 sysinfo_set_item_val(irqs_info, NULL, true);
219}
220
221void calibrate_delay_loop(void)
222{
223 i8254_calibrate_delay_loop();
224 if (config.cpu_active == 1) {
225 /*
226 * This has to be done only on UP.
227 * On SMP, i8254 is not used for time keeping and its interrupt pin remains masked.
228 */
229 i8254_normal_operation();
230 }
231}
232
233/** Construct function pointer
234 *
235 * @param fptr function pointer structure
236 * @param addr function address
237 * @param caller calling function address
238 *
239 * @return address of the function pointer
240 *
241 */
242void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
243{
244 return addr;
245}
246
247void arch_reboot(void)
248{
249#ifdef CONFIG_PC_KBD
250 i8042_cpu_reset((i8042_t *) I8042_BASE);
251#endif
252}
253
254void irq_initialize_arch(irq_t *irq)
255{
256 (void) irq;
257}
258
259/** @}
260 */
Note: See TracBrowser for help on using the repository browser.