source: mainline/kernel/arch/ppc32/src/ppc32.c@ 8e33e1d

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

Fix missing includes.

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