source: mainline/kernel/arch/arm32/src/mach/raspberrypi/raspberrypi.c@ 7f7d642

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7f7d642 was a1b9f63, checked in by Jakub Jermar <jakub@…>, 7 years ago

Add alignment argument to km_map()

km_map() currently always applies alignment requirement equal to the
size of the mapped region. Most of the time, the natural alignment is
unnecessarily strong and especially on 32-bit systems may contribute to
km_map() failures for regions with size in the order of several hundred
megabytes.

This change adds an extra argument to km_map() which allows the caller
to indicate the desired alignment. The old behaviour can be specified
by passing KM_NATURAL_ALIGNMENT as alignment.

This change only adds the alignment argument, but does not change the
alignment requirement anywhere.

  • 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 KM_NATURAL_ALIGNMENT, 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), KM_NATURAL_ALIGNMENT, 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.inr = BCM2835_TIMER1_IRQ;
120 timer_irq.claim = raspberrypi_timer_irq_claim;
121 timer_irq.handler = raspberrypi_timer_irq_handler;
122 irq_register(&timer_irq);
123
124 bcm2835_irc_enable(raspi.irc, BCM2835_TIMER1_IRQ);
125 bcm2835_timer_start(raspi.timer);
126}
127
128static void raspberrypi_cpu_halt(void)
129{
130 while (true)
131 ;
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_FB
176 fb_properties_t prop;
177 if (bcm2835_fb_init(&prop)) {
178 outdev_t *fb_dev = fb_init(&prop);
179 if (fb_dev)
180 stdout_wire(fb_dev);
181 }
182#endif
183
184#ifdef CONFIG_PL011_UART
185 if (pl011_uart_init(&raspi.uart, BCM2835_UART_IRQ,
186 BCM2835_UART0_BASE_ADDRESS))
187 stdout_wire(&raspi.uart.outdev);
188#endif
189}
190
191static void raspberrypi_input_init(void)
192{
193 srln_instance_t *srln_instance = srln_init();
194 if (srln_instance) {
195 indev_t *sink = stdin_wire();
196 indev_t *srln = srln_wire(srln_instance, sink);
197
198 pl011_uart_input_wire(&raspi.uart, srln);
199 bcm2835_irc_enable(raspi.irc, BCM2835_UART_IRQ);
200 }
201}
202
203size_t raspberrypi_get_irq_count(void)
204{
205 return BCM2835_IRQ_COUNT;
206}
207
208const char *raspberrypi_get_platform_name(void)
209{
210 return "raspberrypi";
211}
212
213/** @}
214 */
Note: See TracBrowser for help on using the repository browser.