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