[a522999] | 1 | /*
|
---|
| 2 | * Copyright (c) 2013 Jakub Jermar
|
---|
| 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 |
|
---|
[c5429fe] | 29 | /** @addtogroup kernel_mips32
|
---|
[a522999] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | * @brief msim platform driver.
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #include <arch/mach/msim/msim.h>
|
---|
[f5dd4a1] | 37 | #include <arch/mach/msim/dorder.h>
|
---|
[260f678] | 38 | #include <console/console.h>
|
---|
| 39 | #include <sysinfo/sysinfo.h>
|
---|
| 40 | #include <genarch/drivers/dsrln/dsrlnin.h>
|
---|
| 41 | #include <genarch/drivers/dsrln/dsrlnout.h>
|
---|
| 42 | #include <genarch/srln/srln.h>
|
---|
[124bc22] | 43 | #include <stdbool.h>
|
---|
[a522999] | 44 |
|
---|
| 45 | static void msim_init(void);
|
---|
| 46 | static void msim_cpu_halt(void);
|
---|
| 47 | static void msim_get_memory_extents(uintptr_t *, size_t *);
|
---|
| 48 | static void msim_frame_init(void);
|
---|
| 49 | static void msim_output_init(void);
|
---|
| 50 | static void msim_input_init(void);
|
---|
| 51 | static const char *msim_get_platform_name(void);
|
---|
| 52 |
|
---|
| 53 | struct mips32_machine_ops msim_machine_ops = {
|
---|
| 54 | .machine_init = msim_init,
|
---|
| 55 | .machine_cpu_halt = msim_cpu_halt,
|
---|
| 56 | .machine_get_memory_extents = msim_get_memory_extents,
|
---|
| 57 | .machine_frame_init = msim_frame_init,
|
---|
| 58 | .machine_output_init = msim_output_init,
|
---|
| 59 | .machine_input_init = msim_input_init,
|
---|
[1b20da0] | 60 | .machine_get_platform_name = msim_get_platform_name
|
---|
[a522999] | 61 | };
|
---|
| 62 |
|
---|
[124bc22] | 63 | static void msim_irq_handler(unsigned int i)
|
---|
| 64 | {
|
---|
| 65 | irq_t *irq = irq_dispatch_and_lock(i);
|
---|
| 66 | if (irq) {
|
---|
| 67 | irq->handler(irq);
|
---|
| 68 | irq_spinlock_unlock(&irq->lock, false);
|
---|
| 69 | } else {
|
---|
| 70 | #ifdef CONFIG_DEBUG
|
---|
| 71 | log(LF_ARCH, LVL_DEBUG, "cpu%u: spurious IRQ (irq=%u)",
|
---|
| 72 | CPU->id, i);
|
---|
| 73 | #endif
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[a522999] | 77 | void msim_init(void)
|
---|
| 78 | {
|
---|
[124bc22] | 79 | irq_init(HW_INTERRUPTS, HW_INTERRUPTS);
|
---|
| 80 |
|
---|
| 81 | int_handler[INT_HW0] = msim_irq_handler;
|
---|
| 82 | int_handler[INT_HW1] = msim_irq_handler;
|
---|
| 83 | int_handler[INT_HW2] = msim_irq_handler;
|
---|
| 84 | int_handler[INT_HW3] = msim_irq_handler;
|
---|
| 85 | int_handler[INT_HW4] = msim_irq_handler;
|
---|
| 86 |
|
---|
[f5dd4a1] | 87 | dorder_init();
|
---|
[07c913b] | 88 | cp0_unmask_int(MSIM_DDISK_IRQ);
|
---|
[a522999] | 89 | }
|
---|
| 90 |
|
---|
| 91 | void msim_cpu_halt(void)
|
---|
| 92 | {
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | void msim_get_memory_extents(uintptr_t *start, size_t *size)
|
---|
| 96 | {
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | void msim_frame_init(void)
|
---|
| 100 | {
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | void msim_output_init(void)
|
---|
| 104 | {
|
---|
[260f678] | 105 | #ifdef CONFIG_MSIM_PRN
|
---|
[e064102] | 106 | outdev_t *dsrlndev = dsrlnout_init((ioport8_t *) MSIM_KBD_ADDRESS,
|
---|
| 107 | KSEG12PA(MSIM_KBD_ADDRESS));
|
---|
[260f678] | 108 | if (dsrlndev)
|
---|
| 109 | stdout_wire(dsrlndev);
|
---|
| 110 | #endif
|
---|
[a522999] | 111 | }
|
---|
| 112 |
|
---|
| 113 | void msim_input_init(void)
|
---|
| 114 | {
|
---|
[260f678] | 115 | #ifdef CONFIG_MSIM_KBD
|
---|
| 116 | /*
|
---|
| 117 | * Initialize the msim keyboard port. Then initialize the serial line
|
---|
| 118 | * module and connect it to the msim keyboard. Enable keyboard
|
---|
| 119 | * interrupts.
|
---|
| 120 | */
|
---|
[3bacee1] | 121 | dsrlnin_instance_t *dsrlnin_instance =
|
---|
| 122 | dsrlnin_init((dsrlnin_t *) MSIM_KBD_ADDRESS, MSIM_KBD_IRQ);
|
---|
[260f678] | 123 | if (dsrlnin_instance) {
|
---|
| 124 | srln_instance_t *srln_instance = srln_init();
|
---|
| 125 | if (srln_instance) {
|
---|
| 126 | indev_t *sink = stdin_wire();
|
---|
| 127 | indev_t *srln = srln_wire(srln_instance, sink);
|
---|
| 128 | dsrlnin_wire(dsrlnin_instance, srln);
|
---|
| 129 | cp0_unmask_int(MSIM_KBD_IRQ);
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 | #endif
|
---|
[a522999] | 133 | }
|
---|
| 134 |
|
---|
| 135 | const char *msim_get_platform_name(void)
|
---|
| 136 | {
|
---|
| 137 | return "msim";
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | /** @}
|
---|
| 141 | */
|
---|