source: mainline/kernel/arch/arm32/src/mach/raspberrypi/raspberrypi.c@ 3bacee1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3bacee1 was 3bacee1, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Make ccheck-fix again and commit more good files.

  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 * Copyright (c) 2013 Beniamino Galvani
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 arm32raspberrypi
30 * @{
31 */
32/** @file
33 * @brief Raspberry PI platform driver.
34 */
35
36#include <arch/exception.h>
37#include <arch/mach/raspberrypi/raspberrypi.h>
38#include <assert.h>
39#include <genarch/drivers/pl011/pl011.h>
40#include <genarch/drivers/bcm2835/irc.h>
41#include <genarch/drivers/bcm2835/timer.h>
42#include <genarch/drivers/bcm2835/mbox.h>
43#include <arch/mm/page.h>
44#include <mm/page.h>
45#include <mm/km.h>
46#include <genarch/fb/fb.h>
47#include <abi/fb/visuals.h>
48#include <genarch/srln/srln.h>
49#include <stdbool.h>
50#include <sysinfo/sysinfo.h>
51#include <interrupt.h>
52#include <ddi/ddi.h>
53
54#define RPI_DEFAULT_MEMORY_START 0
55#define RPI_DEFAULT_MEMORY_SIZE 0x08000000
56#define RPI_MEMORY_SKIP 0x8000
57
58static void raspberrypi_init(void);
59static void raspberrypi_timer_irq_start(void);
60static void raspberrypi_cpu_halt(void);
61static void raspberrypi_get_memory_extents(uintptr_t *start, size_t *size);
62static void raspberrypi_irq_exception(unsigned int exc_no, istate_t *istate);
63static void raspberrypi_frame_init(void);
64static void raspberrypi_output_init(void);
65static void raspberrypi_input_init(void);
66static size_t raspberrypi_get_irq_count(void);
67static const char *raspberrypi_get_platform_name(void);
68
69static struct {
70 pl011_uart_t uart;
71 bcm2835_irc_t *irc;
72 bcm2835_timer_t *timer;
73} raspi;
74
75struct arm_machine_ops raspberrypi_machine_ops = {
76 raspberrypi_init,
77 raspberrypi_timer_irq_start,
78 raspberrypi_cpu_halt,
79 raspberrypi_get_memory_extents,
80 raspberrypi_irq_exception,
81 raspberrypi_frame_init,
82 raspberrypi_output_init,
83 raspberrypi_input_init,
84 raspberrypi_get_irq_count,
85 raspberrypi_get_platform_name
86};
87
88static irq_ownership_t raspberrypi_timer_irq_claim(irq_t *irq)
89{
90 return IRQ_ACCEPT;
91}
92
93static void raspberrypi_timer_irq_handler(irq_t *irq)
94{
95 bcm2835_timer_irq_ack(raspi.timer);
96 spinlock_unlock(&irq->lock);
97 clock();
98 spinlock_lock(&irq->lock);
99}
100
101static void raspberrypi_init(void)
102{
103 /* Initialize interrupt controller */
104 raspi.irc = (void *) km_map(BCM2835_IRC_ADDR, sizeof(bcm2835_irc_t),
105 PAGE_NOT_CACHEABLE);
106 assert(raspi.irc);
107 bcm2835_irc_init(raspi.irc);
108
109 /* Initialize system timer */
110 raspi.timer = (void *) km_map(BCM2835_TIMER_ADDR,
111 sizeof(bcm2835_timer_t),
112 PAGE_NOT_CACHEABLE);
113}
114
115static void raspberrypi_timer_irq_start(void)
116{
117 /* Initialize timer IRQ */
118 static irq_t timer_irq;
119 irq_initialize(&timer_irq);
120 timer_irq.inr = BCM2835_TIMER1_IRQ;
121 timer_irq.claim = raspberrypi_timer_irq_claim;
122 timer_irq.handler = raspberrypi_timer_irq_handler;
123 irq_register(&timer_irq);
124
125 bcm2835_irc_enable(raspi.irc, BCM2835_TIMER1_IRQ);
126 bcm2835_timer_start(raspi.timer);
127}
128
129static void raspberrypi_cpu_halt(void)
130{
131 while (true)
132 ;
133}
134
135/** Get extents of available memory.
136 *
137 * @param start Place to store memory start address (physical).
138 * @param size Place to store memory size.
139 */
140static void raspberrypi_get_memory_extents(uintptr_t *start, size_t *size)
141{
142 uint32_t mbase, msize;
143
144 if (bcm2835_prop_get_memory(&mbase, &msize)) {
145 *start = mbase + RPI_MEMORY_SKIP;
146 *size = msize - RPI_MEMORY_SKIP;
147 } else {
148 /* Stick to safe default values */
149 *start = RPI_DEFAULT_MEMORY_START + RPI_MEMORY_SKIP;
150 *size = RPI_DEFAULT_MEMORY_SIZE - RPI_MEMORY_SKIP;
151 }
152}
153
154static void raspberrypi_irq_exception(unsigned int exc_no, istate_t *istate)
155{
156 const unsigned inum = bcm2835_irc_inum_get(raspi.irc);
157
158 irq_t *irq = irq_dispatch_and_lock(inum);
159 if (irq) {
160 /* The IRQ handler was found. */
161 irq->handler(irq);
162 spinlock_unlock(&irq->lock);
163 } else {
164 /* Spurious interrupt.*/
165 printf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, inum);
166 bcm2835_irc_disable(raspi.irc, inum);
167 }
168}
169
170static void raspberrypi_frame_init(void)
171{
172}
173
174static void raspberrypi_output_init(void)
175{
176#ifdef CONFIG_FB
177 fb_properties_t prop;
178 if (bcm2835_fb_init(&prop)) {
179 outdev_t *fb_dev = fb_init(&prop);
180 if (fb_dev)
181 stdout_wire(fb_dev);
182 }
183#endif
184
185#ifdef CONFIG_PL011_UART
186 if (pl011_uart_init(&raspi.uart, BCM2835_UART_IRQ,
187 BCM2835_UART0_BASE_ADDRESS))
188 stdout_wire(&raspi.uart.outdev);
189#endif
190}
191
192static void raspberrypi_input_init(void)
193{
194 srln_instance_t *srln_instance = srln_init();
195 if (srln_instance) {
196 indev_t *sink = stdin_wire();
197 indev_t *srln = srln_wire(srln_instance, sink);
198
199 pl011_uart_input_wire(&raspi.uart, srln);
200 bcm2835_irc_enable(raspi.irc, BCM2835_UART_IRQ);
201 }
202}
203
204size_t raspberrypi_get_irq_count(void)
205{
206 return BCM2835_IRQ_COUNT;
207}
208
209const char *raspberrypi_get_platform_name(void)
210{
211 return "raspberrypi";
212}
213
214/** @}
215 */
Note: See TracBrowser for help on using the repository browser.