source: mainline/kernel/arch/ppc32/src/ppc32.c@ 8023571

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8023571 was 19f857a, checked in by Jiri Svoboda <jiri@…>, 15 years ago

Rename string.h to str.h to avoid header conflict with standard C string.h.

  • Property mode set to 100644
File size: 6.9 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
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 ppc32
30 * @{
31 */
32/** @file
33 */
34
35#include <config.h>
36#include <arch.h>
37#include <arch/boot/boot.h>
38#include <genarch/drivers/via-cuda/cuda.h>
39#include <genarch/kbrd/kbrd.h>
40#include <arch/interrupt.h>
41#include <interrupt.h>
42#include <genarch/fb/fb.h>
43#include <genarch/fb/visuals.h>
44#include <genarch/ofw/ofw_tree.h>
45#include <genarch/ofw/pci.h>
46#include <userspace.h>
47#include <mm/page.h>
48#include <proc/uarg.h>
49#include <console/console.h>
50#include <sysinfo/sysinfo.h>
51#include <ddi/irq.h>
52#include <arch/drivers/pic.h>
53#include <align.h>
54#include <macros.h>
55#include <str.h>
56#include <print.h>
57
58#define IRQ_COUNT 64
59#define IRQ_CUDA 10
60
61bootinfo_t bootinfo;
62
63static cir_t pic_cir;
64static void *pic_cir_arg;
65
66/** Performs ppc32-specific initialization before main_bsp() is called. */
67void arch_pre_main(void)
68{
69 init.cnt = bootinfo.taskmap.count;
70
71 uint32_t i;
72
73 for (i = 0; i < min3(bootinfo.taskmap.count, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); i++) {
74 init.tasks[i].addr = bootinfo.taskmap.tasks[i].addr;
75 init.tasks[i].size = bootinfo.taskmap.tasks[i].size;
76 str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
77 bootinfo.taskmap.tasks[i].name);
78 }
79
80 /* Copy boot allocations info. */
81 ballocs.base = bootinfo.ballocs.base;
82 ballocs.size = bootinfo.ballocs.size;
83
84 ofw_tree_init(bootinfo.ofw_root);
85}
86
87void arch_pre_mm_init(void)
88{
89 /* Initialize dispatch table */
90 interrupt_init();
91
92 /* Start decrementer */
93 start_decrementer();
94}
95
96static bool display_register(ofw_tree_node_t *node, void *arg)
97{
98 uintptr_t fb_addr = 0;
99 uint32_t fb_width = 0;
100 uint32_t fb_height = 0;
101 uint32_t fb_scanline = 0;
102 unsigned int visual = VISUAL_UNKNOWN;
103
104 ofw_tree_property_t *prop = ofw_tree_getprop(node, "address");
105 if ((prop) && (prop->value))
106 fb_addr = *((uintptr_t *) prop->value);
107
108 prop = ofw_tree_getprop(node, "width");
109 if ((prop) && (prop->value))
110 fb_width = *((uint32_t *) prop->value);
111
112 prop = ofw_tree_getprop(node, "height");
113 if ((prop) && (prop->value))
114 fb_height = *((uint32_t *) prop->value);
115
116 prop = ofw_tree_getprop(node, "depth");
117 if ((prop) && (prop->value)) {
118 uint32_t fb_bpp = *((uint32_t *) prop->value);
119 switch (fb_bpp) {
120 case 8:
121 visual = VISUAL_INDIRECT_8;
122 break;
123 case 16:
124 visual = VISUAL_RGB_5_5_5_BE;
125 break;
126 case 24:
127 visual = VISUAL_BGR_8_8_8;
128 break;
129 case 32:
130 visual = VISUAL_RGB_0_8_8_8;
131 break;
132 default:
133 visual = VISUAL_UNKNOWN;
134 }
135 }
136
137 prop = ofw_tree_getprop(node, "linebytes");
138 if ((prop) && (prop->value))
139 fb_scanline = *((uint32_t *) prop->value);
140
141 if ((fb_addr) && (fb_width > 0) && (fb_height > 0)
142 && (fb_scanline > 0) && (visual != VISUAL_UNKNOWN)) {
143 fb_properties_t fb_prop = {
144 .addr = fb_addr,
145 .offset = 0,
146 .x = fb_width,
147 .y = fb_height,
148 .scan = fb_scanline,
149 .visual = visual,
150 };
151
152 outdev_t *fbdev = fb_init(&fb_prop);
153 if (fbdev)
154 stdout_wire(fbdev);
155 }
156
157 return true;
158}
159
160void arch_post_mm_init(void)
161{
162 if (config.cpu_active == 1) {
163#ifdef CONFIG_FB
164 ofw_tree_walk_by_device_type("display", display_register, NULL);
165#endif
166
167 /* Initialize IRQ routing */
168 irq_init(IRQ_COUNT, IRQ_COUNT);
169
170 /* Merge all zones to 1 big zone */
171 zone_merge_all();
172 }
173}
174
175void arch_post_cpu_init(void)
176{
177}
178
179void arch_pre_smp_init(void)
180{
181}
182
183static bool macio_register(ofw_tree_node_t *node, void *arg)
184{
185 ofw_pci_reg_t *assigned_address = NULL;
186
187 ofw_tree_property_t *prop = ofw_tree_getprop(node, "assigned-addresses");
188 if ((prop) && (prop->value))
189 assigned_address = ((ofw_pci_reg_t *) prop->value);
190
191 if (assigned_address) {
192 /* Initialize PIC */
193 pic_init(assigned_address[0].addr, PAGE_SIZE, &pic_cir,
194 &pic_cir_arg);
195
196#ifdef CONFIG_MAC_KBD
197 uintptr_t pa = assigned_address[0].addr + 0x16000;
198 uintptr_t aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
199 size_t offset = pa - aligned_addr;
200 size_t size = 2 * PAGE_SIZE;
201
202 cuda_t *cuda = (cuda_t *)
203 (hw_map(aligned_addr, offset + size) + offset);
204
205 /* Initialize I/O controller */
206 cuda_instance_t *cuda_instance =
207 cuda_init(cuda, IRQ_CUDA, pic_cir, pic_cir_arg);
208 if (cuda_instance) {
209 kbrd_instance_t *kbrd_instance = kbrd_init();
210 if (kbrd_instance) {
211 indev_t *sink = stdin_wire();
212 indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
213 cuda_wire(cuda_instance, kbrd);
214 pic_enable_interrupt(IRQ_CUDA);
215 }
216 }
217
218 /*
219 * This is the necessary evil until the userspace driver is entirely
220 * self-sufficient.
221 */
222 sysinfo_set_item_val("cuda", NULL, true);
223 sysinfo_set_item_val("cuda.inr", NULL, IRQ_CUDA);
224 sysinfo_set_item_val("cuda.address.physical", NULL, pa);
225 sysinfo_set_item_val("cuda.address.kernel", NULL,
226 (uintptr_t) cuda);
227#endif
228 }
229
230 /* Consider only a single device for now */
231 return false;
232}
233
234void irq_initialize_arch(irq_t *irq)
235{
236 irq->cir = pic_cir;
237 irq->cir_arg = pic_cir_arg;
238 irq->preack = true;
239}
240
241void arch_post_smp_init(void)
242{
243 ofw_tree_walk_by_device_type("mac-io", macio_register, NULL);
244}
245
246void calibrate_delay_loop(void)
247{
248}
249
250void userspace(uspace_arg_t *kernel_uarg)
251{
252 userspace_asm((uintptr_t) kernel_uarg->uspace_uarg,
253 (uintptr_t) kernel_uarg->uspace_stack +
254 THREAD_STACK_SIZE - SP_DELTA,
255 (uintptr_t) kernel_uarg->uspace_entry);
256
257 /* Unreachable */
258 while (true);
259}
260
261/** Construct function pointer
262 *
263 * @param fptr function pointer structure
264 * @param addr function address
265 * @param caller calling function address
266 *
267 * @return address of the function pointer
268 *
269 */
270void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
271{
272 return addr;
273}
274
275void arch_reboot(void)
276{
277 // TODO
278 while (1);
279}
280
281/** @}
282 */
Note: See TracBrowser for help on using the repository browser.