source: mainline/kernel/arch/sparc32/src/machine/leon3/leon3.c@ 817d939

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 817d939 was d783145, checked in by Jakub Klama <jakub.klama@…>, 12 years ago

Finally plug in IRQMP and UART kernel drivers.

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Copyright (c) 2013 Jakub Klama
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 sparc32
30 * @{
31 */
32/** @file
33 */
34
35#include <arch.h>
36#include <typedefs.h>
37#include <arch/interrupt.h>
38#include <arch/asm.h>
39#include <arch/machine_func.h>
40
41#include <arch/machine/leon3/leon3.h>
42
43#include <genarch/drivers/grlib_uart/grlib_uart.h>
44#include <genarch/drivers/grlib_irqmp/grlib_irqmp.h>
45#include <genarch/srln/srln.h>
46
47#include <func.h>
48#include <config.h>
49#include <errno.h>
50#include <context.h>
51#include <fpu_context.h>
52#include <interrupt.h>
53#include <syscall/copy.h>
54#include <ddi/irq.h>
55#include <proc/thread.h>
56#include <syscall/syscall.h>
57#include <console/console.h>
58#include <macros.h>
59#include <memstr.h>
60#include <str.h>
61
62static void leon3_init(bootinfo_t *);
63static void leon3_cpu_halt(void);
64static void leon3_get_memory_extents(uintptr_t *, size_t *);
65static void leon3_timer_start(void);
66static void leon3_irq_exception(unsigned int, istate_t *);
67static void leon3_output_init(void);
68static void leon3_input_init(void);
69static size_t leon3_get_irq_count(void);
70static const char *leon3_get_platform_name(void);
71
72struct leon3_machine_t
73{
74 bootinfo_t *bootinfo;
75 outdev_t *scons_dev;
76 grlib_irqmp_t irqmp;
77 //grlib_timer_t timer;
78};
79
80struct sparc_machine_ops leon3_machine_ops = {
81 leon3_init,
82 leon3_cpu_halt,
83 leon3_get_memory_extents,
84 leon3_timer_start,
85 leon3_irq_exception,
86 leon3_output_init,
87 leon3_input_init,
88 leon3_get_irq_count,
89 leon3_get_platform_name
90};
91
92static struct leon3_machine_t machine;
93
94static void leon3_init(bootinfo_t *bootinfo)
95{
96 machine.bootinfo = bootinfo;
97
98 grlib_irqmp_init(&machine.irqmp, bootinfo);
99}
100
101static void leon3_cpu_halt(void)
102{
103 for (;;);
104}
105
106static void leon3_get_memory_extents(uintptr_t *start, size_t *size)
107{
108 *start = LEON3_SDRAM_START;
109 *size = machine.bootinfo->memsize;
110}
111
112static void leon3_timer_start(void)
113{
114 //machine.timer = grlib_timer_init(machine.bootinfo->timer_base, machine.bootinfo->timer_irq);
115}
116
117static void leon3_irq_exception(unsigned int exc_no, istate_t *istate)
118{
119 int irqnum = grlib_irqmp_inum_get(&machine.irqmp);
120
121 grlib_irqmp_clear(&machine.irqmp, irqnum);
122
123 irq_t *irq = irq_dispatch_and_lock(irqnum);
124 if (irq) {
125 irq->handler(irq);
126 spinlock_unlock(&irq->lock);
127 } else
128 printf("cpu%d: spurious interrupt (irq=%d)\n", CPU->id, irqnum);
129}
130
131static void leon3_output_init(void)
132{
133 printf("leon3_output_init\n");
134 printf("machine.bootinfo=%p, machine.bootinfo->uart_base=0x%08x\n", machine.bootinfo, machine.bootinfo->uart_base);
135
136 machine.scons_dev = grlib_uart_init(machine.bootinfo->uart_base, machine.bootinfo->uart_irq);
137
138 if (machine.scons_dev)
139 stdout_wire(machine.scons_dev);
140}
141
142static void leon3_input_init(void)
143{
144 grlib_uart_t *scons_inst;
145
146 if (machine.scons_dev) {
147 /* Create input device. */
148 scons_inst = (void *)machine.scons_dev->data;
149
150 srln_instance_t *srln_instance = srln_init();
151 if (srln_instance) {
152 indev_t *sink = stdin_wire();
153 indev_t *srln = srln_wire(srln_instance, sink);
154 grlib_uart_input_wire(scons_inst, srln);
155
156 /* Enable interrupts from UART */
157 grlib_irqmp_unmask(&machine.irqmp, machine.bootinfo->uart_irq);
158 }
159 }
160}
161
162static size_t leon3_get_irq_count(void)
163{
164 return LEON3_IRQ_COUNT;
165}
166
167static const char *leon3_get_platform_name(void)
168{
169 return "LEON3";
170}
171
172
Note: See TracBrowser for help on using the repository browser.