source: mainline/kernel/arch/ppc32/src/ppc32.c@ 38dc82d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 38dc82d was 36df4109, checked in by Jakub Jermar <jakub@…>, 9 years ago

Introduce architecure-specific operations

This replaces the arch_*_init() functions with an arch_ops_t structure
defined for each architecture. Undefined operations are treated as NOPs.

  • Property mode set to 100644
File size: 8.3 KB
RevLine 
[393f631]1/*
[df4ed85]2 * Copyright (c) 2005 Martin Decky
[393f631]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
[281994b]29/** @addtogroup ppc32
[b45c443]30 * @{
31 */
32/** @file
33 */
34
[393f631]35#include <arch.h>
[36df4109]36#include <arch/arch.h>
37#include <config.h>
[4037847]38#include <arch/boot/boot.h>
[c2417bc]39#include <genarch/drivers/via-cuda/cuda.h>
[2a77841d]40#include <genarch/kbrd/kbrd.h>
[91d5ad6]41#include <arch/interrupt.h>
[3a2f8aa]42#include <interrupt.h>
[35f3b8c]43#include <genarch/fb/fb.h>
[c0699467]44#include <abi/fb/visuals.h>
[e731b0d]45#include <genarch/ofw/ofw_tree.h>
46#include <genarch/ofw/pci.h>
[e692a27]47#include <userspace.h>
[eae4e8f]48#include <mm/page.h>
[d4673296]49#include <mm/km.h>
[0c91cff]50#include <time/clock.h>
[c0699467]51#include <abi/proc/uarg.h>
[41d33ac]52#include <console/console.h>
[3a2f8aa]53#include <sysinfo/sysinfo.h>
[f5e39a32]54#include <ddi/irq.h>
[982f0fe]55#include <arch/drivers/pic.h>
[c2417bc]56#include <align.h>
[96e0748d]57#include <macros.h>
[19f857a]58#include <str.h>
[e731b0d]59#include <print.h>
[06e6805]60
[96e0748d]61#define IRQ_COUNT 64
[c2417bc]62#define IRQ_CUDA 10
[f5e39a32]63
[36df4109]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
[4037847]76bootinfo_t bootinfo;
77
[3a2f8aa]78static cir_t pic_cir;
79static void *pic_cir_arg;
80
[06f96234]81/** Performs ppc32-specific initialization before main_bsp() is called. */
[36df4109]82void ppc32_pre_main(bootinfo_t *bootinfo)
[12c7f27]83{
[4872160]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++) {
[32817cc]88 init.tasks[i].paddr = KA2PA(bootinfo->taskmap.tasks[i].addr);
[4872160]89 init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
[f4b1535]90 str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
[4872160]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;
[59477e3]100 }
[e731b0d]101
102 /* Copy boot allocations info. */
[4872160]103 ballocs.base = bootinfo->ballocs.base;
104 ballocs.size = bootinfo->ballocs.size;
[e731b0d]105
[4872160]106 /* Copy OFW tree. */
107 ofw_tree_init(bootinfo->ofw_root);
[12c7f27]108}
109
[36df4109]110void ppc32_pre_mm_init(void)
[393f631]111{
[91d5ad6]112 /* Initialize dispatch table */
[8965838e]113 interrupt_init();
[e731b0d]114
[0c91cff]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
[4a99c57]127 freq_prop = ofw_tree_getprop(cpu_node, "timebase-frequency");
[0c91cff]128 if (!freq_prop)
129 panic("Could not get frequency property.");
130
131 uint32_t freq;
132 freq = *((uint32_t *) freq_prop->value);
133
[8965838e]134 /* Start decrementer */
[0c91cff]135 decrementer_start(freq / HZ);
[393f631]136}
137
[20f8111]138#ifdef CONFIG_FB
[e731b0d]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;
[2e533d6f]166 case 15:
[e731b0d]167 visual = VISUAL_RGB_5_5_5_BE;
168 break;
[2e533d6f]169 case 16:
170 visual = VISUAL_RGB_5_6_5_BE;
171 break;
[e731b0d]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 };
[a71c158]197
198 outdev_t *fbdev = fb_init(&fb_prop);
199 if (fbdev)
200 stdout_wire(fbdev);
[e731b0d]201 }
202
[a71c158]203 return true;
[e731b0d]204}
[20f8111]205#endif
[e731b0d]206
[36df4109]207void ppc32_post_mm_init(void)
[393f631]208{
[f6a0f06]209 if (config.cpu_active == 1) {
[d0688a3]210#ifdef CONFIG_FB
[e731b0d]211 ofw_tree_walk_by_device_type("display", display_register, NULL);
[d0688a3]212#endif
[de3db94a]213 /* Map OFW information into sysinfo */
214 ofw_sysinfo_map();
[f5e39a32]215
216 /* Initialize IRQ routing */
217 irq_init(IRQ_COUNT, IRQ_COUNT);
[afc12d0]218
[f6a0f06]219 /* Merge all zones to 1 big zone */
220 zone_merge_all();
221 }
[393f631]222}
223
[e731b0d]224static bool macio_register(ofw_tree_node_t *node, void *arg)
[393f631]225{
[e731b0d]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) {
[2a77841d]233 /* Initialize PIC */
[3a2f8aa]234 pic_init(assigned_address[0].addr, PAGE_SIZE, &pic_cir,
235 &pic_cir_arg);
[666f492]236
[2a77841d]237#ifdef CONFIG_MAC_KBD
[e731b0d]238 uintptr_t pa = assigned_address[0].addr + 0x16000;
[2a77841d]239 uintptr_t aligned_addr = ALIGN_DOWN(pa, PAGE_SIZE);
240 size_t offset = pa - aligned_addr;
241 size_t size = 2 * PAGE_SIZE;
[e731b0d]242
[adec5b45]243 cuda_t *cuda = (cuda_t *) (km_map(aligned_addr, offset + size,
244 PAGE_WRITE | PAGE_NOT_CACHEABLE) + offset);
[e731b0d]245
[2a77841d]246 /* Initialize I/O controller */
247 cuda_instance_t *cuda_instance =
[3a2f8aa]248 cuda_init(cuda, IRQ_CUDA, pic_cir, pic_cir_arg);
[2a77841d]249 if (cuda_instance) {
250 kbrd_instance_t *kbrd_instance = kbrd_init();
251 if (kbrd_instance) {
252 indev_t *sink = stdin_wire();
253 indev_t *kbrd = kbrd_wire(kbrd_instance, sink);
254 cuda_wire(cuda_instance, kbrd);
255 pic_enable_interrupt(IRQ_CUDA);
256 }
257 }
[666f492]258
[3a2f8aa]259 /*
260 * This is the necessary evil until the userspace driver is entirely
261 * self-sufficient.
262 */
263 sysinfo_set_item_val("cuda", NULL, true);
264 sysinfo_set_item_val("cuda.inr", NULL, IRQ_CUDA);
265 sysinfo_set_item_val("cuda.address.physical", NULL, pa);
[2a77841d]266#endif
267 }
[e731b0d]268
269 /* Consider only a single device for now */
270 return false;
271}
272
[3a2f8aa]273void irq_initialize_arch(irq_t *irq)
274{
275 irq->cir = pic_cir;
276 irq->cir_arg = pic_cir_arg;
277 irq->preack = true;
278}
279
[36df4109]280void ppc32_post_smp_init(void)
[e731b0d]281{
[eff1f033]282 /* Currently the only supported platform for ppc32 is 'mac'. */
283 static const char *platform = "mac";
284
285 sysinfo_set_item_data("platform", NULL, (void *) platform,
286 str_size(platform));
287
[e731b0d]288 ofw_tree_walk_by_device_type("mac-io", macio_register, NULL);
[393f631]289}
290
291void calibrate_delay_loop(void)
292{
293}
[8965838e]294
[e692a27]295void userspace(uspace_arg_t *kernel_uarg)
296{
[965dc18]297 userspace_asm((uintptr_t) kernel_uarg->uspace_uarg,
[2902e1bb]298 (uintptr_t) kernel_uarg->uspace_stack +
299 kernel_uarg->uspace_stack_size - SP_DELTA,
[965dc18]300 (uintptr_t) kernel_uarg->uspace_entry);
[e692a27]301
302 /* Unreachable */
[516ff92]303 while (true);
[e692a27]304}
[41d33ac]305
[6da1013f]306/** Construct function pointer
307 *
308 * @param fptr function pointer structure
309 * @param addr function address
310 * @param caller calling function address
311 *
312 * @return address of the function pointer
313 *
314 */
315void *arch_construct_function(fncptr_t *fptr, void *addr, void *caller)
316{
317 return addr;
318}
319
[c2417bc]320void arch_reboot(void)
321{
322 // TODO
[666f492]323 while (true);
[c2417bc]324}
325
[281994b]326/** @}
[b45c443]327 */
Note: See TracBrowser for help on using the repository browser.