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

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

Define a PIO range for GXemul keyboard.

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