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 |
|
---|
29 | /** @addtogroup kernel_mips32
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief MIPS Malta platform driver.
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <arch/mach/malta/malta.h>
|
---|
37 | #include <console/console.h>
|
---|
38 | #include <console/chardev.h>
|
---|
39 | #include <arch/mm/page.h>
|
---|
40 | #include <genarch/drivers/i8259/i8259.h>
|
---|
41 | #include <genarch/drivers/ns16550/ns16550.h>
|
---|
42 | #include <genarch/srln/srln.h>
|
---|
43 | #include <arch/interrupt.h>
|
---|
44 | #include <stdbool.h>
|
---|
45 | #include <byteorder.h>
|
---|
46 | #include <log.h>
|
---|
47 |
|
---|
48 | static void malta_init(void);
|
---|
49 | static void malta_cpu_halt(void);
|
---|
50 | static void malta_get_memory_extents(uintptr_t *, size_t *);
|
---|
51 | static void malta_frame_init(void);
|
---|
52 | static void malta_output_init(void);
|
---|
53 | static void malta_input_init(void);
|
---|
54 | static const char *malta_get_platform_name(void);
|
---|
55 |
|
---|
56 | struct mips32_machine_ops malta_machine_ops = {
|
---|
57 | .machine_init = malta_init,
|
---|
58 | .machine_cpu_halt = malta_cpu_halt,
|
---|
59 | .machine_get_memory_extents = malta_get_memory_extents,
|
---|
60 | .machine_frame_init = malta_frame_init,
|
---|
61 | .machine_output_init = malta_output_init,
|
---|
62 | .machine_input_init = malta_input_init,
|
---|
63 | .machine_get_platform_name = malta_get_platform_name
|
---|
64 | };
|
---|
65 |
|
---|
66 | #ifdef CONFIG_NS16550
|
---|
67 | static ns16550_instance_t *tty_instance;
|
---|
68 | #endif
|
---|
69 | #ifdef CONFIG_NS16550_OUT
|
---|
70 | static outdev_t *tty_out;
|
---|
71 | #endif
|
---|
72 |
|
---|
73 | static void malta_isa_irq_handler(unsigned int i)
|
---|
74 | {
|
---|
75 | uint8_t isa_irq = host2uint32_t_le(pio_read_32(GT64120_PCI0_INTACK));
|
---|
76 | irq_t *irq = irq_dispatch_and_lock(isa_irq);
|
---|
77 | if (irq) {
|
---|
78 | irq->handler(irq);
|
---|
79 | irq_spinlock_unlock(&irq->lock, false);
|
---|
80 | } else {
|
---|
81 | #ifdef CONFIG_DEBUG
|
---|
82 | log(LF_ARCH, LVL_DEBUG, "cpu%u: spurious IRQ (irq=%u)",
|
---|
83 | CPU->id, isa_irq);
|
---|
84 | #endif
|
---|
85 | }
|
---|
86 | pic_eoi();
|
---|
87 | }
|
---|
88 |
|
---|
89 | void malta_init(void)
|
---|
90 | {
|
---|
91 | irq_init(16, 16);
|
---|
92 |
|
---|
93 | i8259_init((i8259_t *) PIC0_BASE, (i8259_t *) PIC1_BASE, 2, 0, 8);
|
---|
94 |
|
---|
95 | int_handler[INT_HW0] = malta_isa_irq_handler;
|
---|
96 | cp0_unmask_int(INT_HW0);
|
---|
97 |
|
---|
98 | #if (defined(CONFIG_NS16550) || defined(CONFIG_NS16550_OUT))
|
---|
99 | #ifdef CONFIG_NS16550_OUT
|
---|
100 | outdev_t **tty_out_ptr = &tty_out;
|
---|
101 | #else
|
---|
102 | outdev_t **tty_out_ptr = NULL;
|
---|
103 | #endif
|
---|
104 | tty_instance = ns16550_init((ioport8_t *) TTY_BASE, 0, TTY_ISA_IRQ,
|
---|
105 | NULL, NULL, tty_out_ptr);
|
---|
106 | #endif
|
---|
107 | }
|
---|
108 |
|
---|
109 | void malta_cpu_halt(void)
|
---|
110 | {
|
---|
111 | }
|
---|
112 |
|
---|
113 | void malta_get_memory_extents(uintptr_t *start, size_t *size)
|
---|
114 | {
|
---|
115 | }
|
---|
116 |
|
---|
117 | void malta_frame_init(void)
|
---|
118 | {
|
---|
119 | }
|
---|
120 |
|
---|
121 | void malta_output_init(void)
|
---|
122 | {
|
---|
123 | #ifdef CONFIG_NS16550_OUT
|
---|
124 | if (tty_out)
|
---|
125 | stdout_wire(tty_out);
|
---|
126 | #endif
|
---|
127 | }
|
---|
128 |
|
---|
129 | void malta_input_init(void)
|
---|
130 | {
|
---|
131 | #ifdef CONFIG_NS16550
|
---|
132 | if (tty_instance) {
|
---|
133 | srln_instance_t *srln_instance = srln_init();
|
---|
134 | if (srln_instance) {
|
---|
135 | indev_t *sink = stdin_wire();
|
---|
136 | indev_t *srln = srln_wire(srln_instance, sink);
|
---|
137 | ns16550_wire(tty_instance, srln);
|
---|
138 | pic_enable_irqs(1 << TTY_ISA_IRQ);
|
---|
139 | }
|
---|
140 | }
|
---|
141 | #endif
|
---|
142 | }
|
---|
143 |
|
---|
144 | const char *malta_get_platform_name(void)
|
---|
145 | {
|
---|
146 | return "malta";
|
---|
147 | }
|
---|
148 |
|
---|
149 | /** @}
|
---|
150 | */
|
---|