source: mainline/kernel/arch/arm32/src/mach/testarm/testarm.c@ 6250c37

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6250c37 was 12b0d51, checked in by Jiri Svoboda <jiri@…>, 15 years ago

Fix ommisions in testarm and integratorcp.

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