1 | /*
|
---|
2 | * Copyright (c) 2007 Michal Kebrt, Petr Stepan
|
---|
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 arm32gxemul
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief GXemul drivers.
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <arch/exception.h>
|
---|
37 | #include <arch/mach/testarm/testarm.h>
|
---|
38 | #include <mm/page.h>
|
---|
39 | #include <genarch/fb/fb.h>
|
---|
40 | #include <genarch/fb/visuals.h>
|
---|
41 | #include <genarch/drivers/dsrln/dsrlnin.h>
|
---|
42 | #include <genarch/drivers/dsrln/dsrlnout.h>
|
---|
43 | #include <genarch/srln/srln.h>
|
---|
44 | #include <console/console.h>
|
---|
45 | #include <ddi/irq.h>
|
---|
46 | #include <ddi/device.h>
|
---|
47 | #include <config.h>
|
---|
48 | #include <sysinfo/sysinfo.h>
|
---|
49 | #include <interrupt.h>
|
---|
50 | #include <print.h>
|
---|
51 |
|
---|
52 |
|
---|
53 | void *gxemul_kbd;
|
---|
54 | void *gxemul_rtc;
|
---|
55 | void *gxemul_irqc;
|
---|
56 | static irq_t gxemul_timer_irq;
|
---|
57 |
|
---|
58 | struct arm_machine_ops gxemul_machine_ops = {
|
---|
59 | gxemul_init,
|
---|
60 | gxemul_timer_irq_start,
|
---|
61 | gxemul_cpu_halt,
|
---|
62 | gxemul_get_memory_extents,
|
---|
63 | gxemul_irq_exception,
|
---|
64 | gxemul_frame_init,
|
---|
65 | gxemul_output_init,
|
---|
66 | gxemul_input_init,
|
---|
67 | gxemul_get_irq_count
|
---|
68 | };
|
---|
69 |
|
---|
70 | void gxemul_init(void)
|
---|
71 | {
|
---|
72 | gxemul_kbd = (void *) hw_map(GXEMUL_KBD_ADDRESS, PAGE_SIZE);
|
---|
73 | gxemul_rtc = (void *) hw_map(GXEMUL_RTC_ADDRESS, PAGE_SIZE);
|
---|
74 | gxemul_irqc = (void *) hw_map(GXEMUL_IRQC_ADDRESS, PAGE_SIZE);
|
---|
75 | }
|
---|
76 |
|
---|
77 | void gxemul_output_init(void)
|
---|
78 | {
|
---|
79 | #ifdef CONFIG_FB
|
---|
80 | fb_properties_t prop = {
|
---|
81 | .addr = GXEMUL_FB_ADDRESS,
|
---|
82 | .offset = 0,
|
---|
83 | .x = 640,
|
---|
84 | .y = 480,
|
---|
85 | .scan = 1920,
|
---|
86 | .visual = VISUAL_RGB_8_8_8,
|
---|
87 | };
|
---|
88 |
|
---|
89 | outdev_t *fbdev = fb_init(&prop);
|
---|
90 | if (fbdev)
|
---|
91 | stdout_wire(fbdev);
|
---|
92 | #endif
|
---|
93 |
|
---|
94 | #ifdef CONFIG_ARM_PRN
|
---|
95 | outdev_t *dsrlndev = dsrlnout_init((ioport8_t *) gxemul_kbd);
|
---|
96 | if (dsrlndev)
|
---|
97 | stdout_wire(dsrlndev);
|
---|
98 | #endif
|
---|
99 | }
|
---|
100 |
|
---|
101 | void gxemul_input_init(void)
|
---|
102 | {
|
---|
103 | #ifdef CONFIG_ARM_KBD
|
---|
104 | /*
|
---|
105 | * Initialize the GXemul keyboard port. Then initialize the serial line
|
---|
106 | * module and connect it to the GXemul keyboard.
|
---|
107 | */
|
---|
108 | dsrlnin_instance_t *dsrlnin_instance
|
---|
109 | = dsrlnin_init((dsrlnin_t *) gxemul_kbd, GXEMUL_KBD_IRQ);
|
---|
110 | if (dsrlnin_instance) {
|
---|
111 | srln_instance_t *srln_instance = srln_init();
|
---|
112 | if (srln_instance) {
|
---|
113 | indev_t *sink = stdin_wire();
|
---|
114 | indev_t *srln = srln_wire(srln_instance, sink);
|
---|
115 | dsrlnin_wire(dsrlnin_instance, srln);
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | /*
|
---|
120 | * This is the necessary evil until the userspace driver is entirely
|
---|
121 | * self-sufficient.
|
---|
122 | */
|
---|
123 | sysinfo_set_item_val("kbd", NULL, true);
|
---|
124 | sysinfo_set_item_val("kbd.inr", NULL, GXEMUL_KBD_IRQ);
|
---|
125 | sysinfo_set_item_val("kbd.address.virtual", NULL, (sysarg_t) gxemul_kbd);
|
---|
126 | #endif
|
---|
127 | }
|
---|
128 |
|
---|
129 | size_t gxemul_get_irq_count(void)
|
---|
130 | {
|
---|
131 | return GXEMUL_IRQ_COUNT;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /** Starts gxemul Real Time Clock device, which asserts regular interrupts.
|
---|
135 | *
|
---|
136 | * @param frequency Interrupts frequency (0 disables RTC).
|
---|
137 | */
|
---|
138 | static void gxemul_timer_start(uint32_t frequency)
|
---|
139 | {
|
---|
140 | *((uint32_t *) (gxemul_rtc + GXEMUL_RTC_FREQ_OFFSET))
|
---|
141 | = frequency;
|
---|
142 | }
|
---|
143 |
|
---|
144 | static irq_ownership_t gxemul_timer_claim(irq_t *irq)
|
---|
145 | {
|
---|
146 | return IRQ_ACCEPT;
|
---|
147 | }
|
---|
148 |
|
---|
149 | /** Timer interrupt handler.
|
---|
150 | *
|
---|
151 | * @param irq Interrupt information.
|
---|
152 | * @param arg Not used.
|
---|
153 | */
|
---|
154 | static void gxemul_timer_irq_handler(irq_t *irq)
|
---|
155 | {
|
---|
156 | /*
|
---|
157 | * We are holding a lock which prevents preemption.
|
---|
158 | * Release the lock, call clock() and reacquire the lock again.
|
---|
159 | */
|
---|
160 | spinlock_unlock(&irq->lock);
|
---|
161 | clock();
|
---|
162 | spinlock_lock(&irq->lock);
|
---|
163 |
|
---|
164 | /* acknowledge tick */
|
---|
165 | *((uint32_t *) (gxemul_rtc + GXEMUL_RTC_ACK_OFFSET))
|
---|
166 | = 0;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /** Initializes and registers timer interrupt handler. */
|
---|
170 | static void gxemul_timer_irq_init(void)
|
---|
171 | {
|
---|
172 | irq_initialize(&gxemul_timer_irq);
|
---|
173 | gxemul_timer_irq.devno = device_assign_devno();
|
---|
174 | gxemul_timer_irq.inr = GXEMUL_TIMER_IRQ;
|
---|
175 | gxemul_timer_irq.claim = gxemul_timer_claim;
|
---|
176 | gxemul_timer_irq.handler = gxemul_timer_irq_handler;
|
---|
177 |
|
---|
178 | irq_register(&gxemul_timer_irq);
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | /** Starts timer.
|
---|
183 | *
|
---|
184 | * Initiates regular timer interrupts after initializing
|
---|
185 | * corresponding interrupt handler.
|
---|
186 | */
|
---|
187 | void gxemul_timer_irq_start(void)
|
---|
188 | {
|
---|
189 | gxemul_timer_irq_init();
|
---|
190 | gxemul_timer_start(GXEMUL_TIMER_FREQ);
|
---|
191 | }
|
---|
192 |
|
---|
193 | /** Get extents of available memory.
|
---|
194 | *
|
---|
195 | * @param start Place to store memory start address.
|
---|
196 | * @param size Place to store memory size.
|
---|
197 | */
|
---|
198 | void gxemul_get_memory_extents(uintptr_t *start, uintptr_t *size)
|
---|
199 | {
|
---|
200 | *start = 0;
|
---|
201 | *size = *((uintptr_t *) (GXEMUL_MP_ADDRESS + GXEMUL_MP_MEMSIZE_OFFSET));
|
---|
202 | }
|
---|
203 |
|
---|
204 | /** Returns the mask of active interrupts. */
|
---|
205 | static inline uint32_t gxemul_irqc_get_sources(void)
|
---|
206 | {
|
---|
207 | return *((uint32_t *) gxemul_irqc);
|
---|
208 | }
|
---|
209 |
|
---|
210 | /** Interrupt Exception handler.
|
---|
211 | *
|
---|
212 | * Determines the sources of interrupt and calls their handlers.
|
---|
213 | */
|
---|
214 | void gxemul_irq_exception(unsigned int exc_no, istate_t *istate)
|
---|
215 | {
|
---|
216 | uint32_t sources = gxemul_irqc_get_sources();
|
---|
217 | unsigned int i;
|
---|
218 |
|
---|
219 | for (i = 0; i < GXEMUL_IRQ_COUNT; i++) {
|
---|
220 | if (sources & (1 << i)) {
|
---|
221 | irq_t *irq = irq_dispatch_and_lock(i);
|
---|
222 | if (irq) {
|
---|
223 | /* The IRQ handler was found. */
|
---|
224 | irq->handler(irq);
|
---|
225 | spinlock_unlock(&irq->lock);
|
---|
226 | } else {
|
---|
227 | /* Spurious interrupt.*/
|
---|
228 | printf("cpu%d: spurious interrupt (inum=%d)\n",
|
---|
229 | CPU->id, i);
|
---|
230 | }
|
---|
231 | }
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | void gxemul_cpu_halt(void)
|
---|
236 | {
|
---|
237 | *((char *) (gxemul_kbd + GXEMUL_HALT_OFFSET)) = 0;
|
---|
238 | }
|
---|
239 |
|
---|
240 | void gxemul_frame_init(void)
|
---|
241 | {
|
---|
242 | }
|
---|
243 |
|
---|
244 | /** @}
|
---|
245 | */
|
---|