source: mainline/kernel/arch/ppc32/src/ppc32.c@ 3ab2d1e

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3ab2d1e was 4a99c57, checked in by Jakub Jermar <jakub@…>, 11 years ago

According to the PowerPC PRG, section 1.20, DEC uses the same frequency
as TB, so use timebase-frequency for DEC rather than clock-frequency.

  • Property mode set to 100644
File size: 8.1 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 <abi/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 <mm/km.h>
49#include <time/clock.h>
50#include <abi/proc/uarg.h>
51#include <console/console.h>
52#include <sysinfo/sysinfo.h>
53#include <ddi/irq.h>
54#include <arch/drivers/pic.h>
55#include <align.h>
56#include <macros.h>
57#include <str.h>
58#include <print.h>
59
60#define IRQ_COUNT 64
61#define IRQ_CUDA 10
62
63bootinfo_t bootinfo;
64
65static cir_t pic_cir;
66static void *pic_cir_arg;
67
68/** Performs ppc32-specific initialization before main_bsp() is called. */
69void arch_pre_main(bootinfo_t *bootinfo)
70{
71 /* Copy tasks map. */
72 init.cnt = min3(bootinfo->taskmap.cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
73 size_t i;
74 for (i = 0; i < init.cnt; i++) {
75 init.tasks[i].paddr = KA2PA(bootinfo->taskmap.tasks[i].addr);
76 init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
77 str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
78 bootinfo->taskmap.tasks[i].name);
79 }
80
81 /* Copy physical memory map. */
82 memmap.total = bootinfo->memmap.total;
83 memmap.cnt = min(bootinfo->memmap.cnt, MEMMAP_MAX_RECORDS);
84 for (i = 0; i < memmap.cnt; i++) {
85 memmap.zones[i].start = bootinfo->memmap.zones[i].start;
86 memmap.zones[i].size = bootinfo->memmap.zones[i].size;
87 }
88
89 /* Copy boot allocations info. */
90 ballocs.base = bootinfo->ballocs.base;
91 ballocs.size = bootinfo->ballocs.size;
92
93 /* Copy OFW tree. */
94 ofw_tree_init(bootinfo->ofw_root);
95}
96
97void arch_pre_mm_init(void)
98{
99 /* Initialize dispatch table */
100 interrupt_init();
101
102 ofw_tree_node_t *cpus_node;
103 ofw_tree_node_t *cpu_node;
104 ofw_tree_property_t *freq_prop;
105
106 cpus_node = ofw_tree_lookup("/cpus");
107 if (!cpus_node)
108 panic("Could not find cpus node.");
109
110 cpu_node = cpus_node->child;
111 if (!cpu_node)
112 panic("Could not find first cpu.");
113
114 freq_prop = ofw_tree_getprop(cpu_node, "timebase-frequency");
115 if (!freq_prop)
116 panic("Could not get frequency property.");
117
118 uint32_t freq;
119 freq = *((uint32_t *) freq_prop->value);
120
121 /* Start decrementer */
122 decrementer_start(freq / HZ);
123}
124
125#ifdef CONFIG_FB
126static bool display_register(ofw_tree_node_t *node, void *arg)
127{
128 uintptr_t fb_addr = 0;
129 uint32_t fb_width = 0;
130 uint32_t fb_height = 0;
131 uint32_t fb_scanline = 0;
132 unsigned int visual = VISUAL_UNKNOWN;
133
134 ofw_tree_property_t *prop = ofw_tree_getprop(node, "address");
135 if ((prop) && (prop->value))
136 fb_addr = *((uintptr_t *) prop->value);
137
138 prop = ofw_tree_getprop(node, "width");
139 if ((prop) && (prop->value))
140 fb_width = *((uint32_t *) prop->value);
141
142 prop = ofw_tree_getprop(node, "height");
143 if ((prop) && (prop->value))
144 fb_height = *((uint32_t *) prop->value);
145
146 prop = ofw_tree_getprop(node, "depth");
147 if ((prop) && (prop->value)) {
148 uint32_t fb_bpp = *((uint32_t *) prop->value);
149 switch (fb_bpp) {
150 case 8:
151 visual = VISUAL_INDIRECT_8;
152 break;
153 case 15:
154 visual = VISUAL_RGB_5_5_5_BE;
155 break;
156 case 16:
157 visual = VISUAL_RGB_5_6_5_BE;
158 break;
159 case 24:
160 visual = VISUAL_BGR_8_8_8;
161 break;
162 case 32:
163 visual = VISUAL_RGB_0_8_8_8;
164 break;
165 default:
166 visual = VISUAL_UNKNOWN;
167 }
168 }
169
170 prop = ofw_tree_getprop(node, "linebytes");
171 if ((prop) && (prop->value))
172 fb_scanline = *((uint32_t *) prop->value);
173
174 if ((fb_addr) && (fb_width > 0) && (fb_height > 0)
175 && (fb_scanline > 0) && (visual != VISUAL_UNKNOWN)) {
176 fb_properties_t fb_prop = {
177 .addr = fb_addr,
178 .offset = 0,
179 .x = fb_width,
180 .y = fb_height,
181 .scan = fb_scanline,
182 .visual = visual,
183 };
184
185 outdev_t *fbdev = fb_init(&fb_prop);
186 if (fbdev)
187 stdout_wire(fbdev);
188 }
189
190 return true;
191}
192#endif
193
194void arch_post_mm_init(void)
195{
196 if (config.cpu_active == 1) {
197#ifdef CONFIG_FB
198 ofw_tree_walk_by_device_type("display", display_register, NULL);
199#endif
200 /* Map OFW information into sysinfo */
201 ofw_sysinfo_map();
202
203 /* Initialize IRQ routing */
204 irq_init(IRQ_COUNT, IRQ_COUNT);
205
206 /* Merge all zones to 1 big zone */
207 zone_merge_all();
208 }
209}
210
211void arch_post_cpu_init(void)
212{
213}
214
215void arch_pre_smp_init(void)
216{
217}
218
219static bool macio_register(ofw_tree_node_t *node, void *arg)
220{
221 ofw_pci_reg_t *assigned_address = NULL;
222
223 ofw_tree_property_t *prop = ofw_tree_getprop(node, "assigned-addresses");
224 if ((prop) && (prop->value))
225 assigned_address = ((ofw_pci_reg_t *) prop->value);
226
227 if (assigned_address) {
228 /* Initialize PIC */
229 pic_init(assigned_address[0].addr, PAGE_SIZE, &pic_cir,
230 &pic_cir_arg);
231
232#ifdef CONFIG_MAC_KBD
233 uintptr_t pa = assigned_address[0].addr + 0x16000;
234 uintptr_t aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
235 size_t offset = pa - aligned_addr;
236 size_t size = 2 * PAGE_SIZE;
237
238 cuda_t *cuda = (cuda_t *) (km_map(aligned_addr, offset + size,
239 PAGE_WRITE | PAGE_NOT_CACHEABLE) + offset);
240
241 /* Initialize I/O controller */
242 cuda_instance_t *cuda_instance =
243 cuda_init(cuda, IRQ_CUDA, pic_cir, pic_cir_arg);
244 if (cuda_instance) {
245 kbrd_instance_t *kbrd_instance = kbrd_init();
246 if (kbrd_instance) {
247 indev_t *sink = stdin_wire();
248 indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
249 cuda_wire(cuda_instance, kbrd);
250 pic_enable_interrupt(IRQ_CUDA);
251 }
252 }
253
254 /*
255 * This is the necessary evil until the userspace driver is entirely
256 * self-sufficient.
257 */
258 sysinfo_set_item_val("cuda", NULL, true);
259 sysinfo_set_item_val("cuda.inr", NULL, IRQ_CUDA);
260 sysinfo_set_item_val("cuda.address.physical", NULL, pa);
261#endif
262 }
263
264 /* Consider only a single device for now */
265 return false;
266}
267
268void irq_initialize_arch(irq_t *irq)
269{
270 irq->cir = pic_cir;
271 irq->cir_arg = pic_cir_arg;
272 irq->preack = true;
273}
274
275void arch_post_smp_init(void)
276{
277 /* Currently the only supported platform for ppc32 is 'mac'. */
278 static const char *platform = "mac";
279
280 sysinfo_set_item_data("platform", NULL, (void *) platform,
281 str_size(platform));
282
283 ofw_tree_walk_by_device_type("mac-io", macio_register, NULL);
284}
285
286void calibrate_delay_loop(void)
287{
288}
289
290void userspace(uspace_arg_t *kernel_uarg)
291{
292 userspace_asm((uintptr_t) kernel_uarg->uspace_uarg,
293 (uintptr_t) kernel_uarg->uspace_stack +
294 kernel_uarg->uspace_stack_size - SP_DELTA,
295 (uintptr_t) kernel_uarg->uspace_entry);
296
297 /* Unreachable */
298 while (true);
299}
300
301/** Construct function pointer
302 *
303 * @param fptr function pointer structure
304 * @param addr function address
305 * @param caller calling function address
306 *
307 * @return address of the function pointer
308 *
309 */
310void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
311{
312 return addr;
313}
314
315void arch_reboot(void)
316{
317 // TODO
318 while (true);
319}
320
321/** @}
322 */
Note: See TracBrowser for help on using the repository browser.