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

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

Rename hw_map() to km_map() and add protection flags argument
to make it more generic.

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