source: mainline/kernel/arch/arm32/src/mach/raspberrypi/raspberrypi.c@ 44b2b78

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 44b2b78 was 44b2b78, checked in by Beniamino Galvani <b.galvani@…>, 12 years ago

Detect amount of available memory using mailbox

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