source: mainline/kernel/arch/ppc32/src/ppc32.c@ 09ab0a9a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 09ab0a9a was 7f7d642, checked in by Jakub Jermar <jakub@…>, 7 years ago

Let km_map() handle the unaligned addresses

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