source: mainline/kernel/arch/mips32/src/mach/malta/malta.c

Last change on this file was 2a103b5, checked in by Jakub Jermar <jakub@…>, 6 years ago

Introduce PIC operations indirection mechanism

Some architectures switch from one interrupt controller implementation
to another during runtime. By providing a cleaner indirection mechanism,
it is possible e.g. for the ia32 IRQ 7 handler to distinguish i8259
spurious interrupts from actual IRQ 7 device interrupts, even when the
i8259 interrupt controller is no longer active.

  • Property mode set to 100644
File size: 4.3 KB
RevLine 
[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 MIPS Malta platform driver.
34 */
35
36#include <arch/mach/malta/malta.h>
[b5e17b1]37#include <console/console.h>
38#include <console/chardev.h>
39#include <arch/mm/page.h>
[68d8736]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>
[124bc22]44#include <stdbool.h>
45#include <byteorder.h>
[69c31abc]46#include <sysinfo/sysinfo.h>
[124bc22]47#include <log.h>
[a522999]48
49static void malta_init(void);
50static void malta_cpu_halt(void);
51static void malta_get_memory_extents(uintptr_t *, size_t *);
52static void malta_frame_init(void);
53static void malta_output_init(void);
54static void malta_input_init(void);
55static const char *malta_get_platform_name(void);
56
57struct mips32_machine_ops malta_machine_ops = {
58 .machine_init = malta_init,
59 .machine_cpu_halt = malta_cpu_halt,
60 .machine_get_memory_extents = malta_get_memory_extents,
61 .machine_frame_init = malta_frame_init,
62 .machine_output_init = malta_output_init,
63 .machine_input_init = malta_input_init,
[1b20da0]64 .machine_get_platform_name = malta_get_platform_name
[a522999]65};
66
[68d8736]67#ifdef CONFIG_NS16550
68static ns16550_instance_t *tty_instance;
69#endif
70#ifdef CONFIG_NS16550_OUT
71static outdev_t *tty_out;
72#endif
73
[124bc22]74static void malta_isa_irq_handler(unsigned int i)
[68d8736]75{
[124bc22]76 uint8_t isa_irq = host2uint32_t_le(pio_read_32(GT64120_PCI0_INTACK));
[2a103b5]77 if (i8259_is_spurious(isa_irq)) {
78 i8259_handle_spurious(isa_irq);
[f6cf76f]79#ifdef CONFIG_DEBUG
[fd67c9f]80 log(LF_ARCH, LVL_DEBUG, "cpu%u: PIC spurious interrupt %u",
81 CPU->id, isa_irq);
[f6cf76f]82 return;
83#endif
84 }
[124bc22]85 irq_t *irq = irq_dispatch_and_lock(isa_irq);
86 if (irq) {
87 irq->handler(irq);
88 irq_spinlock_unlock(&irq->lock, false);
89 } else {
90#ifdef CONFIG_DEBUG
[fd67c9f]91 log(LF_ARCH, LVL_DEBUG, "cpu%u: unhandled IRQ (irq=%u)",
[124bc22]92 CPU->id, isa_irq);
93#endif
94 }
[2a103b5]95 i8259_eoi(isa_irq);
[68d8736]96}
97
[a522999]98void malta_init(void)
99{
[1332270]100 irq_init(ISA_IRQ_COUNT, ISA_IRQ_COUNT);
[124bc22]101
[3daba42e]102 i8259_init((i8259_t *) PIC0_BASE, (i8259_t *) PIC1_BASE, 0);
[69c31abc]103 sysinfo_set_item_val("i8259", NULL, true);
[68d8736]104
[124bc22]105 int_handler[INT_HW0] = malta_isa_irq_handler;
106 cp0_unmask_int(INT_HW0);
107
[68d8736]108#if (defined(CONFIG_NS16550) || defined(CONFIG_NS16550_OUT))
109#ifdef CONFIG_NS16550_OUT
110 outdev_t **tty_out_ptr = &tty_out;
111#else
112 outdev_t **tty_out_ptr = NULL;
113#endif
[124bc22]114 tty_instance = ns16550_init((ioport8_t *) TTY_BASE, 0, TTY_ISA_IRQ,
115 NULL, NULL, tty_out_ptr);
[68d8736]116#endif
[a522999]117}
118
119void malta_cpu_halt(void)
120{
121}
122
123void malta_get_memory_extents(uintptr_t *start, size_t *size)
124{
125}
126
127void malta_frame_init(void)
128{
129}
130
131void malta_output_init(void)
132{
[68d8736]133#ifdef CONFIG_NS16550_OUT
134 if (tty_out)
135 stdout_wire(tty_out);
136#endif
[a522999]137}
138
139void malta_input_init(void)
140{
[68d8736]141#ifdef CONFIG_NS16550
142 if (tty_instance) {
143 srln_instance_t *srln_instance = srln_init();
144 if (srln_instance) {
145 indev_t *sink = stdin_wire();
146 indev_t *srln = srln_wire(srln_instance, sink);
147 ns16550_wire(tty_instance, srln);
[2a103b5]148 i8259_enable_irqs(1 << TTY_ISA_IRQ);
[68d8736]149 }
150 }
151#endif
[a522999]152}
153
154const char *malta_get_platform_name(void)
155{
156 return "malta";
157}
158
159/** @}
160 */
Note: See TracBrowser for help on using the repository browser.