Skip to content

Commit 0782e26

Browse files
morello: Add support for QEMU platform
This was tested on a baseline AArch64 Morello/QEMU without CHERI. Signed-off-by: Hesham Almatary <hesham.almatary@cl.cam.ac.uk>
1 parent af6b18b commit 0782e26

5 files changed

Lines changed: 170 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#pragma once
8+
9+
enum clk_id {
10+
CLK_MASTER,
11+
/* ----- */
12+
NCLOCKS,
13+
/* Custom clock */
14+
CLK_CUSTOM,
15+
};
16+
17+
enum clock_gate {
18+
NCLKGATES
19+
};
20+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#pragma once
8+
9+
enum i2c_id {
10+
NI2C
11+
};
12+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2019, Data61, CSIRO (ABN 41 687 119 230)
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#pragma once
8+
9+
#define UART0_PADDR 0x9000000
10+
11+
#define UART0_IRQ 33
12+
13+
enum chardev_id {
14+
PL001_UART0,
15+
/* Aliases */
16+
PS_SERIAL0 = PL001_UART0,
17+
/* defaults */
18+
PS_SERIAL_DEFAULT = PL001_UART0
19+
};
20+
21+
#define DEFAULT_SERIAL_PADDR UART0_PADDR
22+
#define DEFAULT_SERIAL_INTERRUPT UART0_IRQ
23+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2019, Data61, CSIRO (ABN 41 687 119 230)
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
/**
8+
* Contains the definition for all character devices on this platform.
9+
* Currently this is just a simple patch.
10+
*/
11+
12+
#include "../../chardev.h"
13+
#include "../../common.h"
14+
#include <utils/util.h>
15+
16+
#include "../../chardev.h"
17+
18+
static const int uart0_irqs[] = {UART0_IRQ, -1};
19+
20+
#define UART_DEFN(devid) { \
21+
.id = PL001_UART##devid, \
22+
.paddr = UART##devid##_PADDR, \
23+
.size = BIT(12), \
24+
.irqs = uart##devid##_irqs, \
25+
.init_fn = &uart_init \
26+
}
27+
28+
static const struct dev_defn dev_defn[] = {
29+
UART_DEFN(0),
30+
};
31+
32+
struct ps_chardevice *ps_cdev_init(enum chardev_id id, const ps_io_ops_t *o, struct ps_chardevice *d)
33+
{
34+
unsigned int i;
35+
for (i = 0; i < ARRAY_SIZE(dev_defn); i++) {
36+
if (dev_defn[i].id == id) {
37+
return (dev_defn[i].init_fn(dev_defn + i, o, d)) ? NULL : d;
38+
}
39+
}
40+
return NULL;
41+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2019, Data61, CSIRO (ABN 41 687 119 230)
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
/* Mostly copy/paste from the HiKey plat.
8+
* Should be moved to a common driver file for PL011 */
9+
10+
#include <string.h>
11+
#include <stdlib.h>
12+
#include <platsupport/serial.h>
13+
#include "../../chardev.h"
14+
15+
#define RHR_MASK MASK(8)
16+
#define UARTDR 0x000
17+
#define UARTFR 0x018
18+
#define UARTIMSC 0x038
19+
#define UARTICR 0x044
20+
#define PL011_UARTFR_TXFF BIT(5)
21+
#define PL011_UARTFR_RXFE BIT(4)
22+
23+
#define REG_PTR(base, off) ((volatile uint32_t *)((base) + (off)))
24+
25+
int uart_getchar(ps_chardevice_t *d)
26+
{
27+
int ch = EOF;
28+
29+
if ((*REG_PTR(d->vaddr, UARTFR) & PL011_UARTFR_RXFE) == 0) {
30+
ch = *REG_PTR(d->vaddr, UARTDR) & RHR_MASK;
31+
}
32+
return ch;
33+
}
34+
35+
int uart_putchar(ps_chardevice_t *d, int c)
36+
{
37+
while ((*REG_PTR(d->vaddr, UARTFR) & PL011_UARTFR_TXFF) != 0);
38+
39+
*REG_PTR(d->vaddr, UARTDR) = c;
40+
if (c == '\n' && (d->flags & SERIAL_AUTO_CR)) {
41+
uart_putchar(d, '\r');
42+
}
43+
44+
return c;
45+
}
46+
47+
static void uart_handle_irq(ps_chardevice_t *dev)
48+
{
49+
*REG_PTR(dev->vaddr, UARTICR) = 0x7f0;
50+
}
51+
52+
int uart_init(const struct dev_defn *defn,
53+
const ps_io_ops_t *ops,
54+
ps_chardevice_t *dev)
55+
{
56+
memset(dev, 0, sizeof(*dev));
57+
void *vaddr = chardev_map(defn, ops);
58+
if (vaddr == NULL) {
59+
return -1;
60+
}
61+
62+
/* Set up all the device properties. */
63+
dev->id = defn->id;
64+
dev->vaddr = (void *)vaddr;
65+
dev->read = &uart_read;
66+
dev->write = &uart_write;
67+
dev->handle_irq = &uart_handle_irq;
68+
dev->irqs = defn->irqs;
69+
dev->ioops = *ops;
70+
dev->flags = SERIAL_AUTO_CR;
71+
72+
*REG_PTR(dev->vaddr, UARTIMSC) = 0x50;
73+
return 0;
74+
}

0 commit comments

Comments
 (0)