source: mainline/kernel/arch/ppc32/src/ppc32.c@ 382fb4ba

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 382fb4ba was 20f8111, checked in by Martin Sucha <sucha14@…>, 13 years ago

Fix unused function warning on ppc32 with CONFIG_FB disabled

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