source: mainline/kernel/arch/ppc32/src/ppc32.c@ 35bb2e7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 35bb2e7 was a71c158, checked in by Martin Decky <martin@…>, 17 years ago

kernel output devices now suport multiple instances (except ski and sgcn, which respect the same interface, but behave as singletons)
if more than one output device gets initialized, the output is cloned to all of them
get rid of arch_grab_console() and arch_release_console() (output devices can implement a generic "redraw" method, input devices respect the "silent" global variable)
related cleanups and modifications

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