[6ac14a70] | 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 |
|
---|
[66fcba2] | 58 | struct arm_machine_ops gxemul_machine_ops = {
|
---|
[6ac14a70] | 59 | gxemul_init,
|
---|
| 60 | gxemul_timer_irq_start,
|
---|
| 61 | gxemul_cpu_halt,
|
---|
| 62 | gxemul_get_memory_size,
|
---|
| 63 | gxemul_irq_exception,
|
---|
| 64 | gxemul_frame_init,
|
---|
| 65 | gxemul_output_init,
|
---|
| 66 | gxemul_input_init
|
---|
| 67 | };
|
---|
| 68 |
|
---|
| 69 | void 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 |
|
---|
[a71c158] | 76 | void gxemul_output_init(void)
|
---|
[6ac14a70] | 77 | {
|
---|
[a71c158] | 78 | #ifdef CONFIG_FB
|
---|
[6ac14a70] | 79 | fb_properties_t prop = {
|
---|
| 80 | .addr = GXEMUL_FB_ADDRESS,
|
---|
| 81 | .offset = 0,
|
---|
| 82 | .x = 640,
|
---|
| 83 | .y = 480,
|
---|
| 84 | .scan = 1920,
|
---|
[30885b9] | 85 | .visual = VISUAL_RGB_8_8_8,
|
---|
[6ac14a70] | 86 | };
|
---|
[a71c158] | 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
|
---|
[6ac14a70] | 98 | }
|
---|
| 99 |
|
---|
| 100 | void 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 | */
|
---|
| 132 | static void gxemul_timer_start(uint32_t frequency)
|
---|
| 133 | {
|
---|
| 134 | *((uint32_t *) (gxemul_rtc + GXEMUL_RTC_FREQ_OFFSET))
|
---|
| 135 | = frequency;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | static 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 | */
|
---|
| 148 | static 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. */
|
---|
| 164 | static 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 | */
|
---|
| 181 | void gxemul_timer_irq_start(void)
|
---|
| 182 | {
|
---|
| 183 | gxemul_timer_irq_init();
|
---|
| 184 | gxemul_timer_start(GXEMUL_TIMER_FREQ);
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | /** Returns the size of emulated memory.
|
---|
| 188 | *
|
---|
| 189 | * @return Size in bytes.
|
---|
| 190 | */
|
---|
| 191 | uintptr_t gxemul_get_memory_size(void)
|
---|
| 192 | {
|
---|
| 193 | return *((uintptr_t *) (GXEMUL_MP_ADDRESS + GXEMUL_MP_MEMSIZE_OFFSET));
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | /** Returns the mask of active interrupts. */
|
---|
| 198 | static inline uint32_t gxemul_irqc_get_sources(void)
|
---|
| 199 | {
|
---|
| 200 | return *((uint32_t *) gxemul_irqc);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /** Interrupt Exception handler.
|
---|
| 204 | *
|
---|
| 205 | * Determines the sources of interrupt and calls their handlers.
|
---|
| 206 | */
|
---|
[214ec25c] | 207 | void gxemul_irq_exception(unsigned int exc_no, istate_t *istate)
|
---|
[6ac14a70] | 208 | {
|
---|
| 209 | uint32_t sources = gxemul_irqc_get_sources();
|
---|
| 210 | unsigned int i;
|
---|
| 211 |
|
---|
| 212 | for (i = 0; i < GXEMUL_IRQC_MAX_IRQ; i++) {
|
---|
| 213 | if (sources & (1 << i)) {
|
---|
| 214 | irq_t *irq = irq_dispatch_and_lock(i);
|
---|
| 215 | if (irq) {
|
---|
| 216 | /* The IRQ handler was found. */
|
---|
| 217 | irq->handler(irq);
|
---|
| 218 | spinlock_unlock(&irq->lock);
|
---|
| 219 | } else {
|
---|
| 220 | /* Spurious interrupt.*/
|
---|
| 221 | printf("cpu%d: spurious interrupt (inum=%d)\n",
|
---|
| 222 | CPU->id, i);
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | void gxemul_cpu_halt(void)
|
---|
| 229 | {
|
---|
| 230 | *((char *) (gxemul_kbd + GXEMUL_HALT_OFFSET)) = 0;
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | void gxemul_frame_init(void)
|
---|
| 234 | {
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | /** @}
|
---|
| 238 | */
|
---|