1 | /*
|
---|
2 | * Copyright (c) 2013 Jakub Klama
|
---|
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 sparc32
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | */
|
---|
34 |
|
---|
35 | #include <arch.h>
|
---|
36 | #include <typedefs.h>
|
---|
37 | #include <arch/interrupt.h>
|
---|
38 | #include <arch/asm.h>
|
---|
39 | #include <arch/machine_func.h>
|
---|
40 |
|
---|
41 | #include <arch/machine/leon3/leon3.h>
|
---|
42 |
|
---|
43 | #include <genarch/drivers/grlib_uart/grlib_uart.h>
|
---|
44 | #include <genarch/drivers/grlib_irqmp/grlib_irqmp.h>
|
---|
45 | #include <genarch/srln/srln.h>
|
---|
46 |
|
---|
47 | #include <func.h>
|
---|
48 | #include <config.h>
|
---|
49 | #include <errno.h>
|
---|
50 | #include <context.h>
|
---|
51 | #include <fpu_context.h>
|
---|
52 | #include <interrupt.h>
|
---|
53 | #include <syscall/copy.h>
|
---|
54 | #include <ddi/irq.h>
|
---|
55 | #include <proc/thread.h>
|
---|
56 | #include <syscall/syscall.h>
|
---|
57 | #include <console/console.h>
|
---|
58 | #include <macros.h>
|
---|
59 | #include <memstr.h>
|
---|
60 | #include <str.h>
|
---|
61 |
|
---|
62 | static void leon3_init(bootinfo_t *);
|
---|
63 | static void leon3_cpu_halt(void);
|
---|
64 | static void leon3_get_memory_extents(uintptr_t *, size_t *);
|
---|
65 | static void leon3_timer_start(void);
|
---|
66 | static void leon3_irq_exception(unsigned int, istate_t *);
|
---|
67 | static void leon3_output_init(void);
|
---|
68 | static void leon3_input_init(void);
|
---|
69 | static size_t leon3_get_irq_count(void);
|
---|
70 | static const char *leon3_get_platform_name(void);
|
---|
71 |
|
---|
72 | struct leon3_machine_t
|
---|
73 | {
|
---|
74 | bootinfo_t *bootinfo;
|
---|
75 | outdev_t *scons_dev;
|
---|
76 | grlib_irqmp_t irqmp;
|
---|
77 | //grlib_timer_t timer;
|
---|
78 | };
|
---|
79 |
|
---|
80 | struct sparc_machine_ops leon3_machine_ops = {
|
---|
81 | leon3_init,
|
---|
82 | leon3_cpu_halt,
|
---|
83 | leon3_get_memory_extents,
|
---|
84 | leon3_timer_start,
|
---|
85 | leon3_irq_exception,
|
---|
86 | leon3_output_init,
|
---|
87 | leon3_input_init,
|
---|
88 | leon3_get_irq_count,
|
---|
89 | leon3_get_platform_name
|
---|
90 | };
|
---|
91 |
|
---|
92 | static struct leon3_machine_t machine;
|
---|
93 |
|
---|
94 | static void leon3_init(bootinfo_t *bootinfo)
|
---|
95 | {
|
---|
96 | machine.bootinfo = bootinfo;
|
---|
97 |
|
---|
98 | grlib_irqmp_init(&machine.irqmp, bootinfo);
|
---|
99 | }
|
---|
100 |
|
---|
101 | static void leon3_cpu_halt(void)
|
---|
102 | {
|
---|
103 | for (;;);
|
---|
104 | }
|
---|
105 |
|
---|
106 | static void leon3_get_memory_extents(uintptr_t *start, size_t *size)
|
---|
107 | {
|
---|
108 | *start = LEON3_SDRAM_START;
|
---|
109 | *size = 64 * 1024 * 1024;//machine.bootinfo->memsize;
|
---|
110 | }
|
---|
111 |
|
---|
112 | static void leon3_timer_start(void)
|
---|
113 | {
|
---|
114 | //machine.timer = grlib_timer_init(machine.bootinfo->timer_base, machine.bootinfo->timer_irq);
|
---|
115 | }
|
---|
116 |
|
---|
117 | static void leon3_irq_exception(unsigned int exc_no, istate_t *istate)
|
---|
118 | {
|
---|
119 | int irqnum = grlib_irqmp_inum_get(&machine.irqmp);
|
---|
120 |
|
---|
121 | grlib_irqmp_clear(&machine.irqmp, irqnum);
|
---|
122 |
|
---|
123 | irq_t *irq = irq_dispatch_and_lock(irqnum);
|
---|
124 | if (irq) {
|
---|
125 | irq->handler(irq);
|
---|
126 | spinlock_unlock(&irq->lock);
|
---|
127 | } else
|
---|
128 | printf("cpu%d: spurious interrupt (irq=%d)\n", CPU->id, irqnum);
|
---|
129 | }
|
---|
130 |
|
---|
131 | static void leon3_output_init(void)
|
---|
132 | {
|
---|
133 | printf("leon3_output_init\n");
|
---|
134 | printf("machine.bootinfo=%p, machine.bootinfo->uart_base=0x%08x\n", machine.bootinfo, machine.bootinfo->uart_base);
|
---|
135 |
|
---|
136 | machine.scons_dev = grlib_uart_init(machine.bootinfo->uart_base, machine.bootinfo->uart_irq);
|
---|
137 |
|
---|
138 | if (machine.scons_dev)
|
---|
139 | stdout_wire(machine.scons_dev);
|
---|
140 | }
|
---|
141 |
|
---|
142 | static void leon3_input_init(void)
|
---|
143 | {
|
---|
144 | #if 0
|
---|
145 | grlib_uart_t *scons_inst;
|
---|
146 |
|
---|
147 | if (machine.scons_dev) {
|
---|
148 | /* Create input device. */
|
---|
149 | scons_inst = (void *)machine.scons_dev->data;
|
---|
150 |
|
---|
151 | srln_instance_t *srln_instance = srln_init();
|
---|
152 | if (srln_instance) {
|
---|
153 | indev_t *sink = stdin_wire();
|
---|
154 | indev_t *srln = srln_wire(srln_instance, sink);
|
---|
155 | grlib_uart_input_wire(scons_inst, srln);
|
---|
156 |
|
---|
157 | /* Enable interrupts from UART */
|
---|
158 | grlib_irqmp_unmask(&machine.irqmp, machine.bootinfo->uart_irq);
|
---|
159 | }
|
---|
160 | }
|
---|
161 | #endif
|
---|
162 | }
|
---|
163 |
|
---|
164 | static size_t leon3_get_irq_count(void)
|
---|
165 | {
|
---|
166 | return LEON3_IRQ_COUNT;
|
---|
167 | }
|
---|
168 |
|
---|
169 | static const char *leon3_get_platform_name(void)
|
---|
170 | {
|
---|
171 | return "LEON3";
|
---|
172 | }
|
---|
173 |
|
---|
174 |
|
---|