1
As promised, more Arm patches. The big thing in here is the
1
Another go at the v8.5-MemTag linux-user support, plus a
2
MPS2-AN521 board model.
2
couple more npcm7xx devices.
3
3
4
thanks
5
-- PMM
4
-- PMM
6
5
7
The following changes since commit cfe6c547690b06fbce54a6d0f7b05dd7f18e36ea:
6
The following changes since commit 8ba4bca570ace1e60614a0808631a517cf5df67a:
8
7
9
Merge remote-tracking branch 'remotes/xanclic/tags/pull-block-2019-01-31' into staging (2019-01-31 19:26:09 +0000)
8
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2021-02-15 17:13:57 +0000)
10
9
11
are available in the Git repository at:
10
are available in the Git repository at:
12
11
13
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20190201
12
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20210216
14
13
15
for you to fetch changes up to 7743b70ffe7a8ce168adce2cf50ad156b1fefb8c:
14
for you to fetch changes up to 64fd5bddf3b71d1b92b55382ab39768bd87ecfbd:
16
15
17
tests/microbit-test: Add tests for nRF51 NVMC (2019-02-01 15:32:17 +0000)
16
tests/qtests: Add npcm7xx emc model test (2021-02-16 14:27:05 +0000)
18
17
19
----------------------------------------------------------------
18
----------------------------------------------------------------
20
target-arm queue:
19
target-arm queue:
21
* New machine mps2-an521 -- this is a model of the AN521 FPGA image for the MPS2 devboard
20
* Support ARMv8.5-MemTag for linux-user
22
* Fix various places where we failed to UNDEF invalid A64 instructions
21
* ncpm7xx: Support SMBus, EMC ethernet devices
23
* Don't UNDEF a valid FCMLA on 32-bit inputs
22
* MAINTAINERS: add section for Clock framework
24
* Fix some bugs in the newly-added PAuth implementation
25
* microbit: Implement NVMC non-volatile memory controller
26
23
27
----------------------------------------------------------------
24
----------------------------------------------------------------
28
Aaron Lindsay OS (2):
25
Doug Evans (3):
29
target/arm: Send interrupts on PMU counter overflow
26
hw/net: Add npcm7xx emc model
30
target/arm: Add a timer to predict PMU counter overflow
27
hw/arm: Add npcm7xx emc model
28
tests/qtests: Add npcm7xx emc model test
31
29
32
Julia Suvorova (1):
30
Hao Wu (5):
33
arm: Clarify the logic of set_pc()
31
hw/i2c: Implement NPCM7XX SMBus Module Single Mode
32
hw/arm: Add I2C sensors for NPCM750 eval board
33
hw/arm: Add I2C sensors and EEPROM for GSJ machine
34
hw/i2c: Add a QTest for NPCM7XX SMBus Device
35
hw/i2c: Implement NPCM7XX SMBus Module FIFO Mode
34
36
35
Peter Maydell (33):
37
Luc Michel (1):
36
armv7m: Don't assume the NVIC's CPU is CPU 0
38
MAINTAINERS: add myself maintainer for the clock framework
37
armv7m: Make cpu object a child of the armv7m container
38
armv7m: Pass through start-powered-off CPU property
39
hw/arm/iotkit: Rename IoTKit to ARMSSE
40
hw/arm/iotkit: Refactor into abstract base class and subclass
41
hw/arm/iotkit: Rename 'iotkit' local variables and functions
42
hw/arm/iotkit: Rename files to hw/arm/armsse.[ch]
43
hw/misc/iotkit-secctl: Support 4 internal MPCs
44
hw/arm/armsse: Make number of SRAM banks parameterised
45
hw/arm/armsse: Make SRAM bank size configurable
46
hw/arm/armsse: Support dual-CPU configuration
47
hw/arm/armsse: Give each CPU its own view of memory
48
hw/arm/armsse: Put each CPU in its own cluster object
49
iotkit-sysinfo: Make SYS_VERSION and SYS_CONFIG configurable
50
hw/arm/armsse: Add unimplemented-device stubs for MHUs
51
hw/arm/armsse: Add unimplemented-device stubs for PPUs
52
hw/arm/armsse: Add unimplemented-device stub for cache control registers
53
hw/arm/armsse: Add unimplemented-device stub for CPU local control registers
54
hw/misc/armsse-cpuid: Implement SSE-200 CPU_IDENTITY register block
55
hw/arm/armsse: Add CPU_IDENTITY block to SSE-200
56
hw/arm/armsse: Add SSE-200 model
57
hw/arm/mps2-tz: Add IRQ infrastructure to support SSE-200
58
hw/arm/mps2-tz: Add mps2-an521 model
59
target/arm/translate-a64: Don't underdecode system instructions
60
target/arm/translate-a64: Don't underdecode PRFM
61
target/arm/translate-a64: Don't underdecode SIMD ld/st multiple
62
target/arm/translate-a64: Don't underdecode SIMD ld/st single
63
target/arm/translate-a64: Don't underdecode add/sub extended register
64
target/arm/translate-a64: Don't underdecode FP insns
65
target/arm/translate-a64: Don't underdecode SDOT and UDOT
66
exec.c: Don't reallocate IOMMUNotifiers that are in use
67
target/arm/translate-a64: Fix FCMLA decoding error
68
target/arm/translate-a64: Fix mishandling of size in FCMLA decode
69
39
70
Remi Denis-Courmont (2):
40
Richard Henderson (31):
71
target/arm: fix AArch64 virtual address space size
41
tcg: Introduce target-specific page data for user-only
72
target/arm: fix decoding of B{,L}RA{A,B}
42
linux-user: Introduce PAGE_ANON
43
exec: Use uintptr_t for guest_base
44
exec: Use uintptr_t in cpu_ldst.h
45
exec: Improve types for guest_addr_valid
46
linux-user: Check for overflow in access_ok
47
linux-user: Tidy VERIFY_READ/VERIFY_WRITE
48
bsd-user: Tidy VERIFY_READ/VERIFY_WRITE
49
linux-user: Do not use guest_addr_valid for h2g_valid
50
linux-user: Fix guest_addr_valid vs reserved_va
51
exec: Introduce cpu_untagged_addr
52
exec: Use cpu_untagged_addr in g2h; split out g2h_untagged
53
linux-user: Explicitly untag memory management syscalls
54
linux-user: Use guest_range_valid in access_ok
55
exec: Rename guest_{addr,range}_valid to *_untagged
56
linux-user: Use cpu_untagged_addr in access_ok; split out *_untagged
57
linux-user: Move lock_user et al out of line
58
linux-user: Fix types in uaccess.c
59
linux-user: Handle tags in lock_user/unlock_user
60
linux-user/aarch64: Implement PR_TAGGED_ADDR_ENABLE
61
target/arm: Improve gen_top_byte_ignore
62
target/arm: Use the proper TBI settings for linux-user
63
linux-user/aarch64: Implement PR_MTE_TCF and PR_MTE_TAG
64
linux-user/aarch64: Implement PROT_MTE
65
target/arm: Split out syndrome.h from internals.h
66
linux-user/aarch64: Pass syndrome to EXC_*_ABORT
67
linux-user/aarch64: Signal SEGV_MTESERR for sync tag check fault
68
linux-user/aarch64: Signal SEGV_MTEAERR for async tag check error
69
target/arm: Add allocation tag storage for user mode
70
target/arm: Enable MTE for user-only
71
tests/tcg/aarch64: Add mte smoke tests
73
72
74
Richard Henderson (5):
73
docs/system/arm/nuvoton.rst | 5 +-
75
target/arm: Enable API, APK bits in SCR, HCR
74
bsd-user/qemu.h | 17 +-
76
target/arm: Always enable pac keys for user-only
75
include/exec/cpu-all.h | 47 +-
77
aarch64-linux-user: Update HWCAP bits from linux 5.0-rc1
76
include/exec/cpu_ldst.h | 39 +-
78
aarch64-linux-user: Enable HWCAP bits for PAuth
77
include/exec/exec-all.h | 2 +-
79
linux-user: Initialize aarch64 pac keys
78
include/hw/arm/npcm7xx.h | 4 +
79
include/hw/i2c/npcm7xx_smbus.h | 113 ++++
80
include/hw/net/npcm7xx_emc.h | 286 +++++++++
81
linux-user/aarch64/target_signal.h | 3 +
82
linux-user/aarch64/target_syscall.h | 13 +
83
linux-user/qemu.h | 76 +--
84
linux-user/syscall_defs.h | 1 +
85
target/arm/cpu-param.h | 3 +
86
target/arm/cpu.h | 32 +
87
target/arm/internals.h | 249 +-------
88
target/arm/syndrome.h | 273 +++++++++
89
tests/tcg/aarch64/mte.h | 60 ++
90
accel/tcg/translate-all.c | 32 +-
91
accel/tcg/user-exec.c | 51 +-
92
bsd-user/elfload.c | 2 +-
93
bsd-user/main.c | 8 +-
94
bsd-user/mmap.c | 23 +-
95
hw/arm/npcm7xx.c | 118 +++-
96
hw/arm/npcm7xx_boards.c | 46 ++
97
hw/i2c/npcm7xx_smbus.c | 1099 +++++++++++++++++++++++++++++++++++
98
hw/net/npcm7xx_emc.c | 857 +++++++++++++++++++++++++++
99
linux-user/aarch64/cpu_loop.c | 38 +-
100
linux-user/elfload.c | 18 +-
101
linux-user/flatload.c | 2 +-
102
linux-user/hppa/cpu_loop.c | 39 +-
103
linux-user/i386/cpu_loop.c | 6 +-
104
linux-user/i386/signal.c | 5 +-
105
linux-user/main.c | 4 +-
106
linux-user/mmap.c | 88 +--
107
linux-user/ppc/signal.c | 4 +-
108
linux-user/syscall.c | 165 ++++--
109
linux-user/uaccess.c | 82 ++-
110
target/arm/cpu.c | 25 +-
111
target/arm/helper-a64.c | 4 +-
112
target/arm/mte_helper.c | 39 +-
113
target/arm/tlb_helper.c | 15 +-
114
target/arm/translate-a64.c | 25 +-
115
target/hppa/op_helper.c | 2 +-
116
target/i386/tcg/mem_helper.c | 2 +-
117
target/s390x/mem_helper.c | 4 +-
118
tests/qtest/npcm7xx_emc-test.c | 862 +++++++++++++++++++++++++++
119
tests/qtest/npcm7xx_smbus-test.c | 495 ++++++++++++++++
120
tests/tcg/aarch64/mte-1.c | 28 +
121
tests/tcg/aarch64/mte-2.c | 45 ++
122
tests/tcg/aarch64/mte-3.c | 51 ++
123
tests/tcg/aarch64/mte-4.c | 45 ++
124
tests/tcg/aarch64/pauth-2.c | 1 -
125
MAINTAINERS | 11 +
126
hw/arm/Kconfig | 1 +
127
hw/i2c/meson.build | 1 +
128
hw/i2c/trace-events | 12 +
129
hw/net/meson.build | 1 +
130
hw/net/trace-events | 17 +
131
tests/qtest/meson.build | 2 +
132
tests/tcg/aarch64/Makefile.target | 6 +
133
tests/tcg/configure.sh | 4 +
134
61 files changed, 5052 insertions(+), 556 deletions(-)
135
create mode 100644 include/hw/i2c/npcm7xx_smbus.h
136
create mode 100644 include/hw/net/npcm7xx_emc.h
137
create mode 100644 target/arm/syndrome.h
138
create mode 100644 tests/tcg/aarch64/mte.h
139
create mode 100644 hw/i2c/npcm7xx_smbus.c
140
create mode 100644 hw/net/npcm7xx_emc.c
141
create mode 100644 tests/qtest/npcm7xx_emc-test.c
142
create mode 100644 tests/qtest/npcm7xx_smbus-test.c
143
create mode 100644 tests/tcg/aarch64/mte-1.c
144
create mode 100644 tests/tcg/aarch64/mte-2.c
145
create mode 100644 tests/tcg/aarch64/mte-3.c
146
create mode 100644 tests/tcg/aarch64/mte-4.c
80
147
81
Steffen Görtz (3):
82
hw/nvram/nrf51_nvm: Add nRF51 non-volatile memories
83
arm: Instantiate NRF51 special NVM's and NVMC
84
tests/microbit-test: Add tests for nRF51 NVMC
85
86
kumar sourav (1):
87
hw/arm/nrf51_soc: set object owner in memory_region_init_ram
88
89
hw/arm/Makefile.objs | 2 +-
90
hw/misc/Makefile.objs | 1 +
91
hw/nvram/Makefile.objs | 1 +
92
include/hw/arm/{iotkit.h => armsse.h} | 113 ++-
93
include/hw/arm/armv7m.h | 1 +
94
include/hw/arm/nrf51_soc.h | 2 +
95
include/hw/misc/armsse-cpuid.h | 41 ++
96
include/hw/misc/iotkit-secctl.h | 6 +-
97
include/hw/misc/iotkit-sysinfo.h | 6 +
98
include/hw/nvram/nrf51_nvm.h | 64 ++
99
include/qom/cpu.h | 16 +-
100
linux-user/aarch64/target_syscall.h | 2 +
101
target/arm/cpu.h | 12 +-
102
exec.c | 10 +-
103
hw/arm/armsse.c | 1241 +++++++++++++++++++++++++++++++++
104
hw/arm/armv7m.c | 23 +-
105
hw/arm/boot.c | 4 -
106
hw/arm/iotkit.c | 759 --------------------
107
hw/arm/mps2-tz.c | 121 +++-
108
hw/arm/nrf51_soc.c | 44 +-
109
hw/intc/armv7m_nvic.c | 3 +-
110
hw/misc/armsse-cpuid.c | 134 ++++
111
hw/misc/iotkit-secctl.c | 5 +-
112
hw/misc/iotkit-sysinfo.c | 15 +-
113
hw/nvram/nrf51_nvm.c | 388 +++++++++++
114
linux-user/aarch64/cpu_loop.c | 31 +-
115
linux-user/elfload.c | 10 +
116
target/arm/arm-powerctl.c | 3 -
117
target/arm/cpu.c | 41 +-
118
target/arm/cpu64.c | 75 --
119
target/arm/helper.c | 139 +++-
120
target/arm/translate-a64.c | 59 +-
121
tests/microbit-test.c | 108 +++
122
MAINTAINERS | 6 +-
123
default-configs/arm-softmmu.mak | 3 +-
124
hw/misc/trace-events | 4 +
125
36 files changed, 2552 insertions(+), 941 deletions(-)
126
rename include/hw/arm/{iotkit.h => armsse.h} (53%)
127
create mode 100644 include/hw/misc/armsse-cpuid.h
128
create mode 100644 include/hw/nvram/nrf51_nvm.h
129
create mode 100644 hw/arm/armsse.c
130
delete mode 100644 hw/arm/iotkit.c
131
create mode 100644 hw/misc/armsse-cpuid.c
132
create mode 100644 hw/nvram/nrf51_nvm.c
133
diff view generated by jsdifflib
1
In preparation for adding support for the AN521 MPS2 image, we need
1
From: Richard Henderson <richard.henderson@linaro.org>
2
to handle wiring up the MPS2 device interrupt lines to both CPUs in
3
the SSE-200, rather than just the one that the IoTKit has.
4
2
5
Abstract out a "connect to the IoTKit interrupt line" function
3
This data can be allocated by page_alloc_target_data() and
6
and make it connect to a splitter which feeds both sets of inputs
4
released by page_set_flags(start, end, prot | PAGE_RESET).
7
for the SSE-200 case.
8
5
6
This data will be used to hold tag memory for AArch64 MTE.
7
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20210212184902.1251044-2-richard.henderson@linaro.org
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Message-id: 20190121185118.18550-23-peter.maydell@linaro.org
12
---
12
---
13
hw/arm/mps2-tz.c | 79 ++++++++++++++++++++++++++++++++++++------------
13
include/exec/cpu-all.h | 42 +++++++++++++++++++++++++++++++++------
14
1 file changed, 59 insertions(+), 20 deletions(-)
14
accel/tcg/translate-all.c | 28 ++++++++++++++++++++++++++
15
linux-user/mmap.c | 4 +++-
16
linux-user/syscall.c | 4 ++--
17
4 files changed, 69 insertions(+), 9 deletions(-)
15
18
16
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
19
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
17
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/arm/mps2-tz.c
21
--- a/include/exec/cpu-all.h
19
+++ b/hw/arm/mps2-tz.c
22
+++ b/include/exec/cpu-all.h
20
@@ -XXX,XX +XXX,XX @@
23
@@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask;
21
#include "net/net.h"
24
#define PAGE_EXEC 0x0004
22
#include "hw/core/split-irq.h"
25
#define PAGE_BITS (PAGE_READ | PAGE_WRITE | PAGE_EXEC)
23
26
#define PAGE_VALID 0x0008
24
+#define MPS2TZ_NUMIRQ 92
27
-/* original state of the write flag (used when tracking self-modifying
28
- code */
29
+/*
30
+ * Original state of the write flag (used when tracking self-modifying code)
31
+ */
32
#define PAGE_WRITE_ORG 0x0010
33
-/* Invalidate the TLB entry immediately, helpful for s390x
34
- * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs() */
35
-#define PAGE_WRITE_INV 0x0040
36
+/*
37
+ * Invalidate the TLB entry immediately, helpful for s390x
38
+ * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs()
39
+ */
40
+#define PAGE_WRITE_INV 0x0020
41
+/* For use with page_set_flags: page is being replaced; target_data cleared. */
42
+#define PAGE_RESET 0x0040
25
+
43
+
26
typedef enum MPS2TZFPGAType {
44
#if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY)
27
FPGA_AN505,
45
/* FIXME: Code that sets/uses this is broken and needs to go away. */
28
+ FPGA_AN521,
46
-#define PAGE_RESERVED 0x0020
29
} MPS2TZFPGAType;
47
+#define PAGE_RESERVED 0x0100
30
48
#endif
31
typedef struct {
49
/* Target-specific bits that will be used via page_get_flags(). */
32
@@ -XXX,XX +XXX,XX @@ typedef struct {
50
#define PAGE_TARGET_1 0x0080
33
SplitIRQ sec_resp_splitter;
51
@@ -XXX,XX +XXX,XX @@ int walk_memory_regions(void *, walk_memory_regions_fn);
34
qemu_or_irq uart_irq_orgate;
52
int page_get_flags(target_ulong address);
35
DeviceState *lan9118;
53
void page_set_flags(target_ulong start, target_ulong end, int flags);
36
+ SplitIRQ cpu_irq_splitter[MPS2TZ_NUMIRQ];
54
int page_check_range(target_ulong start, target_ulong len, int flags);
37
} MPS2TZMachineState;
55
+
38
56
+/**
39
#define TYPE_MPS2TZ_MACHINE "mps2tz"
57
+ * page_alloc_target_data(address, size)
40
@@ -XXX,XX +XXX,XX @@ static void make_ram_alias(MemoryRegion *mr, const char *name,
58
+ * @address: guest virtual address
41
memory_region_add_subregion(get_system_memory(), base, mr);
59
+ * @size: size of data to allocate
60
+ *
61
+ * Allocate @size bytes of out-of-band data to associate with the
62
+ * guest page at @address. If the page is not mapped, NULL will
63
+ * be returned. If there is existing data associated with @address,
64
+ * no new memory will be allocated.
65
+ *
66
+ * The memory will be freed when the guest page is deallocated,
67
+ * e.g. with the munmap system call.
68
+ */
69
+void *page_alloc_target_data(target_ulong address, size_t size);
70
+
71
+/**
72
+ * page_get_target_data(address)
73
+ * @address: guest virtual address
74
+ *
75
+ * Return any out-of-bound memory assocated with the guest page
76
+ * at @address, as per page_alloc_target_data.
77
+ */
78
+void *page_get_target_data(target_ulong address);
79
#endif
80
81
CPUArchState *cpu_copy(CPUArchState *env);
82
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
83
index XXXXXXX..XXXXXXX 100644
84
--- a/accel/tcg/translate-all.c
85
+++ b/accel/tcg/translate-all.c
86
@@ -XXX,XX +XXX,XX @@ typedef struct PageDesc {
87
unsigned int code_write_count;
88
#else
89
unsigned long flags;
90
+ void *target_data;
91
#endif
92
#ifndef CONFIG_USER_ONLY
93
QemuSpin lock;
94
@@ -XXX,XX +XXX,XX @@ int page_get_flags(target_ulong address)
95
void page_set_flags(target_ulong start, target_ulong end, int flags)
96
{
97
target_ulong addr, len;
98
+ bool reset_target_data;
99
100
/* This function should never be called with addresses outside the
101
guest address space. If this assert fires, it probably indicates
102
@@ -XXX,XX +XXX,XX @@ void page_set_flags(target_ulong start, target_ulong end, int flags)
103
if (flags & PAGE_WRITE) {
104
flags |= PAGE_WRITE_ORG;
105
}
106
+ reset_target_data = !(flags & PAGE_VALID) || (flags & PAGE_RESET);
107
+ flags &= ~PAGE_RESET;
108
109
for (addr = start, len = end - start;
110
len != 0;
111
@@ -XXX,XX +XXX,XX @@ void page_set_flags(target_ulong start, target_ulong end, int flags)
112
p->first_tb) {
113
tb_invalidate_phys_page(addr, 0);
114
}
115
+ if (reset_target_data && p->target_data) {
116
+ g_free(p->target_data);
117
+ p->target_data = NULL;
118
+ }
119
p->flags = flags;
120
}
42
}
121
}
43
122
44
+static qemu_irq get_sse_irq_in(MPS2TZMachineState *mms, int irqno)
123
+void *page_get_target_data(target_ulong address)
45
+{
124
+{
46
+ /* Return a qemu_irq which will signal IRQ n to all CPUs in the SSE. */
125
+ PageDesc *p = page_find(address >> TARGET_PAGE_BITS);
47
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
126
+ return p ? p->target_data : NULL;
48
+
49
+ assert(irqno < MPS2TZ_NUMIRQ);
50
+
51
+ switch (mmc->fpga_type) {
52
+ case FPGA_AN505:
53
+ return qdev_get_gpio_in_named(DEVICE(&mms->iotkit), "EXP_IRQ", irqno);
54
+ case FPGA_AN521:
55
+ return qdev_get_gpio_in(DEVICE(&mms->cpu_irq_splitter[irqno]), 0);
56
+ default:
57
+ g_assert_not_reached();
58
+ }
59
+}
127
+}
60
+
128
+
61
/* Most of the devices in the AN505 FPGA image sit behind
129
+void *page_alloc_target_data(target_ulong address, size_t size)
62
* Peripheral Protection Controllers. These data structures
130
+{
63
* define the layout of which devices sit behind which PPCs.
131
+ PageDesc *p = page_find(address >> TARGET_PAGE_BITS);
64
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
132
+ void *ret = NULL;
65
int txirqno = i * 2 + 1;
66
int combirqno = i + 10;
67
SysBusDevice *s;
68
- DeviceState *iotkitdev = DEVICE(&mms->iotkit);
69
DeviceState *orgate_dev = DEVICE(&mms->uart_irq_orgate);
70
71
sysbus_init_child_obj(OBJECT(mms), name, uart, sizeof(mms->uart[0]),
72
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_uart(MPS2TZMachineState *mms, void *opaque,
73
qdev_prop_set_uint32(DEVICE(uart), "pclk-frq", SYSCLK_FRQ);
74
object_property_set_bool(OBJECT(uart), true, "realized", &error_fatal);
75
s = SYS_BUS_DEVICE(uart);
76
- sysbus_connect_irq(s, 0, qdev_get_gpio_in_named(iotkitdev,
77
- "EXP_IRQ", txirqno));
78
- sysbus_connect_irq(s, 1, qdev_get_gpio_in_named(iotkitdev,
79
- "EXP_IRQ", rxirqno));
80
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, txirqno));
81
+ sysbus_connect_irq(s, 1, get_sse_irq_in(mms, rxirqno));
82
sysbus_connect_irq(s, 2, qdev_get_gpio_in(orgate_dev, i * 2));
83
sysbus_connect_irq(s, 3, qdev_get_gpio_in(orgate_dev, i * 2 + 1));
84
- sysbus_connect_irq(s, 4, qdev_get_gpio_in_named(iotkitdev,
85
- "EXP_IRQ", combirqno));
86
+ sysbus_connect_irq(s, 4, get_sse_irq_in(mms, combirqno));
87
return sysbus_mmio_get_region(SYS_BUS_DEVICE(uart), 0);
88
}
89
90
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
91
const char *name, hwaddr size)
92
{
93
SysBusDevice *s;
94
- DeviceState *iotkitdev = DEVICE(&mms->iotkit);
95
NICInfo *nd = &nd_table[0];
96
97
/* In hardware this is a LAN9220; the LAN9118 is software compatible
98
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque,
99
qdev_init_nofail(mms->lan9118);
100
101
s = SYS_BUS_DEVICE(mms->lan9118);
102
- sysbus_connect_irq(s, 0, qdev_get_gpio_in_named(iotkitdev, "EXP_IRQ", 16));
103
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 16));
104
return sysbus_mmio_get_region(s, 0);
105
}
106
107
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_dma(MPS2TZMachineState *mms, void *opaque,
108
109
s = SYS_BUS_DEVICE(dma);
110
/* Wire up DMACINTR, DMACINTERR, DMACINTTC */
111
- sysbus_connect_irq(s, 0, qdev_get_gpio_in_named(iotkitdev,
112
- "EXP_IRQ", 58 + i * 3));
113
- sysbus_connect_irq(s, 1, qdev_get_gpio_in_named(iotkitdev,
114
- "EXP_IRQ", 56 + i * 3));
115
- sysbus_connect_irq(s, 2, qdev_get_gpio_in_named(iotkitdev,
116
- "EXP_IRQ", 57 + i * 3));
117
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 58 + i * 3));
118
+ sysbus_connect_irq(s, 1, get_sse_irq_in(mms, 56 + i * 3));
119
+ sysbus_connect_irq(s, 2, get_sse_irq_in(mms, 57 + i * 3));
120
121
g_free(mscname);
122
return sysbus_mmio_get_region(s, 0);
123
@@ -XXX,XX +XXX,XX @@ static MemoryRegion *make_spi(MPS2TZMachineState *mms, void *opaque,
124
*/
125
PL022State *spi = opaque;
126
int i = spi - &mms->spi[0];
127
- DeviceState *iotkitdev = DEVICE(&mms->iotkit);
128
SysBusDevice *s;
129
130
sysbus_init_child_obj(OBJECT(mms), name, spi, sizeof(mms->spi[0]),
131
TYPE_PL022);
132
object_property_set_bool(OBJECT(spi), true, "realized", &error_fatal);
133
s = SYS_BUS_DEVICE(spi);
134
- sysbus_connect_irq(s, 0,
135
- qdev_get_gpio_in_named(iotkitdev, "EXP_IRQ", 51 + i));
136
+ sysbus_connect_irq(s, 0, get_sse_irq_in(mms, 51 + i));
137
return sysbus_mmio_get_region(s, 0);
138
}
139
140
static void mps2tz_common_init(MachineState *machine)
141
{
142
MPS2TZMachineState *mms = MPS2TZ_MACHINE(machine);
143
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_GET_CLASS(mms);
144
MachineClass *mc = MACHINE_GET_CLASS(machine);
145
MemoryRegion *system_memory = get_system_memory();
146
DeviceState *iotkitdev;
147
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
148
iotkitdev = DEVICE(&mms->iotkit);
149
object_property_set_link(OBJECT(&mms->iotkit), OBJECT(system_memory),
150
"memory", &error_abort);
151
- qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", 92);
152
+ qdev_prop_set_uint32(iotkitdev, "EXP_NUMIRQ", MPS2TZ_NUMIRQ);
153
qdev_prop_set_uint32(iotkitdev, "MAINCLK", SYSCLK_FRQ);
154
object_property_set_bool(OBJECT(&mms->iotkit), true, "realized",
155
&error_fatal);
156
157
+ /*
158
+ * The AN521 needs us to create splitters to feed the IRQ inputs
159
+ * for each CPU in the SSE-200 from each device in the board.
160
+ */
161
+ if (mmc->fpga_type == FPGA_AN521) {
162
+ for (i = 0; i < MPS2TZ_NUMIRQ; i++) {
163
+ char *name = g_strdup_printf("mps2-irq-splitter%d", i);
164
+ SplitIRQ *splitter = &mms->cpu_irq_splitter[i];
165
+
133
+
166
+ object_initialize_child(OBJECT(machine), name,
134
+ if (p->flags & PAGE_VALID) {
167
+ splitter, sizeof(*splitter),
135
+ ret = p->target_data;
168
+ TYPE_SPLIT_IRQ, &error_fatal, NULL);
136
+ if (!ret) {
169
+ g_free(name);
137
+ p->target_data = ret = g_malloc0(size);
170
+
171
+ object_property_set_int(OBJECT(splitter), 2, "num-lines",
172
+ &error_fatal);
173
+ object_property_set_bool(OBJECT(splitter), true, "realized",
174
+ &error_fatal);
175
+ qdev_connect_gpio_out(DEVICE(splitter), 0,
176
+ qdev_get_gpio_in_named(DEVICE(&mms->iotkit),
177
+ "EXP_IRQ", i));
178
+ qdev_connect_gpio_out(DEVICE(splitter), 1,
179
+ qdev_get_gpio_in_named(DEVICE(&mms->iotkit),
180
+ "EXP_CPU1_IRQ", i));
181
+ }
138
+ }
182
+ }
139
+ }
140
+ return ret;
141
+}
183
+
142
+
184
/* The sec_resp_cfg output from the IoTKit must be split into multiple
143
int page_check_range(target_ulong start, target_ulong len, int flags)
185
* lines, one for each of the PPCs we create here, plus one per MSC.
144
{
186
*/
145
PageDesc *p;
187
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
146
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
188
object_property_set_bool(OBJECT(&mms->uart_irq_orgate), true,
147
index XXXXXXX..XXXXXXX 100644
189
"realized", &error_fatal);
148
--- a/linux-user/mmap.c
190
qdev_connect_gpio_out(DEVICE(&mms->uart_irq_orgate), 0,
149
+++ b/linux-user/mmap.c
191
- qdev_get_gpio_in_named(iotkitdev, "EXP_IRQ", 15));
150
@@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
192
+ get_sse_irq_in(mms, 15));
151
}
193
152
}
194
/* Most of the devices in the FPGA are behind Peripheral Protection
153
the_end1:
195
* Controllers. The required order for initializing things is:
154
+ page_flags |= PAGE_RESET;
155
page_set_flags(start, start + len, page_flags);
156
the_end:
157
trace_target_mmap_complete(start);
158
@@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
159
new_addr = h2g(host_addr);
160
prot = page_get_flags(old_addr);
161
page_set_flags(old_addr, old_addr + old_size, 0);
162
- page_set_flags(new_addr, new_addr + new_size, prot | PAGE_VALID);
163
+ page_set_flags(new_addr, new_addr + new_size,
164
+ prot | PAGE_VALID | PAGE_RESET);
165
}
166
tb_invalidate_phys_range(new_addr, new_addr + new_size);
167
mmap_unlock();
168
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
169
index XXXXXXX..XXXXXXX 100644
170
--- a/linux-user/syscall.c
171
+++ b/linux-user/syscall.c
172
@@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,
173
raddr=h2g((unsigned long)host_raddr);
174
175
page_set_flags(raddr, raddr + shm_info.shm_segsz,
176
- PAGE_VALID | PAGE_READ |
177
- ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE));
178
+ PAGE_VALID | PAGE_RESET | PAGE_READ |
179
+ (shmflg & SHM_RDONLY ? 0 : PAGE_WRITE));
180
181
for (i = 0; i < N_SHM_REGIONS; i++) {
182
if (!shm_regions[i].in_use) {
196
--
183
--
197
2.20.1
184
2.20.1
198
185
199
186
diff view generated by jsdifflib
1
Instantiate a copy of the CPU_IDENTITY register block for each CPU
1
From: Richard Henderson <richard.henderson@linaro.org>
2
in an SSE-200.
3
2
3
Record whether the backing page is anonymous, or if it has file
4
backing. This will allow us to get close to the Linux AArch64
5
ABI for MTE, which allows tag memory only on ram-backed VMAs.
6
7
The real ABI allows tag memory on files, when those files are
8
on ram-backed filesystems, such as tmpfs. We will not be able
9
to implement that in QEMU linux-user.
10
11
Thankfully, anonymous memory for malloc arenas is the primary
12
consumer of this feature, so this restricted version should
13
still be of use.
14
15
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
17
Message-id: 20210212184902.1251044-3-richard.henderson@linaro.org
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20190121185118.18550-21-peter.maydell@linaro.org
7
---
19
---
8
include/hw/arm/armsse.h | 3 +++
20
include/exec/cpu-all.h | 2 ++
9
hw/arm/armsse.c | 28 ++++++++++++++++++++++++++++
21
linux-user/mmap.c | 3 +++
10
2 files changed, 31 insertions(+)
22
2 files changed, 5 insertions(+)
11
23
12
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
24
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
13
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
14
--- a/include/hw/arm/armsse.h
26
--- a/include/exec/cpu-all.h
15
+++ b/include/hw/arm/armsse.h
27
+++ b/include/exec/cpu-all.h
16
@@ -XXX,XX +XXX,XX @@
28
@@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask;
17
#include "hw/watchdog/cmsdk-apb-watchdog.h"
29
#define PAGE_WRITE_INV 0x0020
18
#include "hw/misc/iotkit-sysctl.h"
30
/* For use with page_set_flags: page is being replaced; target_data cleared. */
19
#include "hw/misc/iotkit-sysinfo.h"
31
#define PAGE_RESET 0x0040
20
+#include "hw/misc/armsse-cpuid.h"
32
+/* For linux-user, indicates that the page is MAP_ANON. */
21
#include "hw/misc/unimp.h"
33
+#define PAGE_ANON 0x0080
22
#include "hw/or-irq.h"
34
23
#include "hw/core/split-irq.h"
35
#if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY)
24
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
36
/* FIXME: Code that sets/uses this is broken and needs to go away. */
25
UnimplementedDeviceState cachectrl[SSE_MAX_CPUS];
37
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
26
UnimplementedDeviceState cpusecctrl[SSE_MAX_CPUS];
27
28
+ ARMSSECPUID cpuid[SSE_MAX_CPUS];
29
+
30
/*
31
* 'container' holds all devices seen by all CPUs.
32
* 'cpu_container[i]' is the view that CPU i has: this has the
33
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
34
index XXXXXXX..XXXXXXX 100644
38
index XXXXXXX..XXXXXXX 100644
35
--- a/hw/arm/armsse.c
39
--- a/linux-user/mmap.c
36
+++ b/hw/arm/armsse.c
40
+++ b/linux-user/mmap.c
37
@@ -XXX,XX +XXX,XX @@ struct ARMSSEInfo {
41
@@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
38
bool has_ppus;
39
bool has_cachectrl;
40
bool has_cpusecctrl;
41
+ bool has_cpuid;
42
};
43
44
static const ARMSSEInfo armsse_variants[] = {
45
@@ -XXX,XX +XXX,XX @@ static const ARMSSEInfo armsse_variants[] = {
46
.has_ppus = false,
47
.has_cachectrl = false,
48
.has_cpusecctrl = false,
49
+ .has_cpuid = false,
50
},
51
};
52
53
@@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj)
54
g_free(name);
55
}
42
}
56
}
43
}
57
+ if (info->has_cpuid) {
44
the_end1:
58
+ for (i = 0; i < info->num_cpus; i++) {
45
+ if (flags & MAP_ANONYMOUS) {
59
+ char *name = g_strdup_printf("cpuid%d", i);
46
+ page_flags |= PAGE_ANON;
60
+
61
+ sysbus_init_child_obj(obj, name, &s->cpuid[i],
62
+ sizeof(s->cpuid[i]),
63
+ TYPE_ARMSSE_CPUID);
64
+ g_free(name);
65
+ }
66
+ }
47
+ }
67
object_initialize_child(obj, "nmi-orgate", &s->nmi_orgate,
48
page_flags |= PAGE_RESET;
68
sizeof(s->nmi_orgate), TYPE_OR_IRQ,
49
page_set_flags(start, start + len, page_flags);
69
&error_abort, NULL);
50
the_end:
70
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
71
memory_region_add_subregion(&s->cpu_container[i], 0x50011000, mr);
72
}
73
}
74
+ if (info->has_cpuid) {
75
+ for (i = 0; i < info->num_cpus; i++) {
76
+ MemoryRegion *mr;
77
+
78
+ qdev_prop_set_uint32(DEVICE(&s->cpuid[i]), "CPUID", i);
79
+ object_property_set_bool(OBJECT(&s->cpuid[i]), true,
80
+ "realized", &err);
81
+ if (err) {
82
+ error_propagate(errp, err);
83
+ return;
84
+ }
85
+
86
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpuid[i]), 0);
87
+ memory_region_add_subregion(&s->cpu_container[i], 0x4001F000, mr);
88
+ }
89
+ }
90
91
/* 0x40020000 .. 0x4002ffff : ARMSSE system control peripheral region */
92
/* Devices behind APB PPC1:
93
--
51
--
94
2.20.1
52
2.20.1
95
53
96
54
diff view generated by jsdifflib
1
In the AdvSIMD load/store single structure encodings, the
1
From: Richard Henderson <richard.henderson@linaro.org>
2
non-post-indexed case should have zeroes in [20:16] (which is the
3
Rm field for the post-indexed case). Bit 31 must also be zero
4
(a check we got right in ldst_multiple but not here). Correctly
5
UNDEF these unallocated encodings.
6
2
7
Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com>
3
This is more descriptive than 'unsigned long'.
4
No functional change, since these match on all linux+bsd hosts.
5
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Message-id: 20210212184902.1251044-4-richard.henderson@linaro.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com>
10
Message-id: 20190125182626.9221-5-peter.maydell@linaro.org
11
---
11
---
12
target/arm/translate-a64.c | 11 ++++++++++-
12
include/exec/cpu-all.h | 2 +-
13
1 file changed, 10 insertions(+), 1 deletion(-)
13
bsd-user/main.c | 4 ++--
14
linux-user/elfload.c | 4 ++--
15
linux-user/main.c | 4 ++--
16
4 files changed, 7 insertions(+), 7 deletions(-)
14
17
15
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
18
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
16
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/translate-a64.c
20
--- a/include/exec/cpu-all.h
18
+++ b/target/arm/translate-a64.c
21
+++ b/include/exec/cpu-all.h
19
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn)
22
@@ -XXX,XX +XXX,XX @@ static inline void tswap64s(uint64_t *s)
20
{
23
/* On some host systems the guest address space is reserved on the host.
21
int rt = extract32(insn, 0, 5);
24
* This allows the guest address space to be offset to a convenient location.
22
int rn = extract32(insn, 5, 5);
25
*/
23
+ int rm = extract32(insn, 16, 5);
26
-extern unsigned long guest_base;
24
int size = extract32(insn, 10, 2);
27
+extern uintptr_t guest_base;
25
int S = extract32(insn, 12, 1);
28
extern bool have_guest_base;
26
int opc = extract32(insn, 13, 3);
29
extern unsigned long reserved_va;
27
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn)
30
28
int ebytes, xs;
31
diff --git a/bsd-user/main.c b/bsd-user/main.c
29
TCGv_i64 tcg_addr, tcg_rn, tcg_ebytes;
32
index XXXXXXX..XXXXXXX 100644
30
33
--- a/bsd-user/main.c
31
+ if (extract32(insn, 31, 1)) {
34
+++ b/bsd-user/main.c
32
+ unallocated_encoding(s);
35
@@ -XXX,XX +XXX,XX @@
33
+ return;
36
34
+ }
37
int singlestep;
35
+ if (!is_postidx && rm != 0) {
38
unsigned long mmap_min_addr;
36
+ unallocated_encoding(s);
39
-unsigned long guest_base;
37
+ return;
40
+uintptr_t guest_base;
38
+ }
41
bool have_guest_base;
39
+
42
unsigned long reserved_va;
40
switch (scale) {
43
41
case 3:
44
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
42
if (!is_load || S) {
45
g_free(target_environ);
43
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn)
46
47
if (qemu_loglevel_mask(CPU_LOG_PAGE)) {
48
- qemu_log("guest_base 0x%lx\n", guest_base);
49
+ qemu_log("guest_base %p\n", (void *)guest_base);
50
log_page_dump("binary load");
51
52
qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk);
53
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
54
index XXXXXXX..XXXXXXX 100644
55
--- a/linux-user/elfload.c
56
+++ b/linux-user/elfload.c
57
@@ -XXX,XX +XXX,XX @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr,
58
void *addr, *test;
59
60
if (!QEMU_IS_ALIGNED(guest_base, align)) {
61
- fprintf(stderr, "Requested guest base 0x%lx does not satisfy "
62
+ fprintf(stderr, "Requested guest base %p does not satisfy "
63
"host minimum alignment (0x%lx)\n",
64
- guest_base, align);
65
+ (void *)guest_base, align);
66
exit(EXIT_FAILURE);
44
}
67
}
45
68
46
if (is_postidx) {
69
diff --git a/linux-user/main.c b/linux-user/main.c
47
- int rm = extract32(insn, 16, 5);
70
index XXXXXXX..XXXXXXX 100644
48
if (rm == 31) {
71
--- a/linux-user/main.c
49
tcg_gen_mov_i64(tcg_rn, tcg_addr);
72
+++ b/linux-user/main.c
50
} else {
73
@@ -XXX,XX +XXX,XX @@ static const char *cpu_model;
74
static const char *cpu_type;
75
static const char *seed_optarg;
76
unsigned long mmap_min_addr;
77
-unsigned long guest_base;
78
+uintptr_t guest_base;
79
bool have_guest_base;
80
81
/*
82
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp)
83
g_free(target_environ);
84
85
if (qemu_loglevel_mask(CPU_LOG_PAGE)) {
86
- qemu_log("guest_base 0x%lx\n", guest_base);
87
+ qemu_log("guest_base %p\n", (void *)guest_base);
88
log_page_dump("binary load");
89
90
qemu_log("start_brk 0x" TARGET_ABI_FMT_lx "\n", info->start_brk);
51
--
91
--
52
2.20.1
92
2.20.1
53
93
54
94
diff view generated by jsdifflib
1
The tcg_register_iommu_notifier() code has a GArray of
1
From: Richard Henderson <richard.henderson@linaro.org>
2
TCGIOMMUNotifier structs which it has registered by passing
3
memory_region_register_iommu_notifier() a pointer to the embedded
4
IOMMUNotifier field. Unfortunately, if we need to enlarge the
5
array via g_array_set_size() this can cause a realloc(), which
6
invalidates the pointer that memory_region_register_iommu_notifier()
7
put into the MemoryRegion's iommu_notify list. This can result
8
in segfaults.
9
2
10
Switch the GArray to holding pointers to the TCGIOMMUNotifier
3
This is more descriptive than 'unsigned long'.
11
structs, so that we can individually allocate and free them.
4
No functional change, since these match on all linux+bsd hosts.
12
5
13
Cc: qemu-stable@nongnu.org
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
14
Fixes: 1f871c5e6b0f30644a60a ("exec.c: Handle IOMMUs in address_space_translate_for_iotlb()")
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Message-id: 20210212184902.1251044-5-richard.henderson@linaro.org
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
17
Message-id: 20190128174241.5860-1-peter.maydell@linaro.org
18
---
11
---
19
exec.c | 10 ++++++----
12
include/exec/cpu_ldst.h | 6 +++---
20
1 file changed, 6 insertions(+), 4 deletions(-)
13
1 file changed, 3 insertions(+), 3 deletions(-)
21
14
22
diff --git a/exec.c b/exec.c
15
diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h
23
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
24
--- a/exec.c
17
--- a/include/exec/cpu_ldst.h
25
+++ b/exec.c
18
+++ b/include/exec/cpu_ldst.h
26
@@ -XXX,XX +XXX,XX @@ static void tcg_register_iommu_notifier(CPUState *cpu,
19
@@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr;
27
int i;
20
#endif
28
21
29
for (i = 0; i < cpu->iommu_notifiers->len; i++) {
22
/* All direct uses of g2h and h2g need to go away for usermode softmmu. */
30
- notifier = &g_array_index(cpu->iommu_notifiers, TCGIOMMUNotifier, i);
23
-#define g2h(x) ((void *)((unsigned long)(abi_ptr)(x) + guest_base))
31
+ notifier = g_array_index(cpu->iommu_notifiers, TCGIOMMUNotifier *, i);
24
+#define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base))
32
if (notifier->mr == mr && notifier->iommu_idx == iommu_idx) {
25
33
break;
26
#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
34
}
27
#define guest_addr_valid(x) (1)
35
@@ -XXX,XX +XXX,XX @@ static void tcg_register_iommu_notifier(CPUState *cpu,
28
#else
36
if (i == cpu->iommu_notifiers->len) {
29
#define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX)
37
/* Not found, add a new entry at the end of the array */
30
#endif
38
cpu->iommu_notifiers = g_array_set_size(cpu->iommu_notifiers, i + 1);
31
-#define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base)
39
- notifier = &g_array_index(cpu->iommu_notifiers, TCGIOMMUNotifier, i);
32
+#define h2g_valid(x) guest_addr_valid((uintptr_t)(x) - guest_base)
40
+ notifier = g_new0(TCGIOMMUNotifier, 1);
33
41
+ g_array_index(cpu->iommu_notifiers, TCGIOMMUNotifier *, i) = notifier;
34
static inline int guest_range_valid(unsigned long start, unsigned long len)
42
35
{
43
notifier->mr = mr;
36
@@ -XXX,XX +XXX,XX @@ static inline int guest_range_valid(unsigned long start, unsigned long len)
44
notifier->iommu_idx = iommu_idx;
45
@@ -XXX,XX +XXX,XX @@ static void tcg_iommu_free_notifier_list(CPUState *cpu)
46
TCGIOMMUNotifier *notifier;
47
48
for (i = 0; i < cpu->iommu_notifiers->len; i++) {
49
- notifier = &g_array_index(cpu->iommu_notifiers, TCGIOMMUNotifier, i);
50
+ notifier = g_array_index(cpu->iommu_notifiers, TCGIOMMUNotifier *, i);
51
memory_region_unregister_iommu_notifier(notifier->mr, &notifier->n);
52
+ g_free(notifier);
53
}
54
g_array_free(cpu->iommu_notifiers, true);
55
}
37
}
56
@@ -XXX,XX +XXX,XX @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
38
57
vmstate_register(NULL, cpu->cpu_index, cc->vmsd, cpu);
39
#define h2g_nocheck(x) ({ \
58
}
40
- unsigned long __ret = (unsigned long)(x) - guest_base; \
59
41
+ uintptr_t __ret = (uintptr_t)(x) - guest_base; \
60
- cpu->iommu_notifiers = g_array_new(false, true, sizeof(TCGIOMMUNotifier));
42
(abi_ptr)__ret; \
61
+ cpu->iommu_notifiers = g_array_new(false, true, sizeof(TCGIOMMUNotifier *));
43
})
62
#endif
63
}
64
44
65
--
45
--
66
2.20.1
46
2.20.1
67
47
68
48
diff view generated by jsdifflib
1
From: Remi Denis-Courmont <remi.denis.courmont@huawei.com>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
A flawed test lead to the instructions always being treated as
3
Return bool not int; pass abi_ulong not 'unsigned long'.
4
unallocated encodings.
4
All callers use abi_ulong already, so the change in type
5
has no effect.
5
6
6
Fixes: https://bugs.launchpad.net/bugs/1813460
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Remi Denis-Courmont <remi.denis.courmont@huawei.com>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Message-id: 20210212184902.1251044-6-richard.henderson@linaro.org
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
12
---
11
target/arm/translate-a64.c | 2 +-
13
include/exec/cpu_ldst.h | 2 +-
12
1 file changed, 1 insertion(+), 1 deletion(-)
14
1 file changed, 1 insertion(+), 1 deletion(-)
13
15
14
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
16
diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h
15
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/translate-a64.c
18
--- a/include/exec/cpu_ldst.h
17
+++ b/target/arm/translate-a64.c
19
+++ b/include/exec/cpu_ldst.h
18
@@ -XXX,XX +XXX,XX @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)
20
@@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr;
19
if (!dc_isar_feature(aa64_pauth, s)) {
21
#endif
20
goto do_unallocated;
22
#define h2g_valid(x) guest_addr_valid((uintptr_t)(x) - guest_base)
21
}
23
22
- if (op3 != 2 || op3 != 3) {
24
-static inline int guest_range_valid(unsigned long start, unsigned long len)
23
+ if ((op3 & ~1) != 2) {
25
+static inline bool guest_range_valid(abi_ulong start, abi_ulong len)
24
goto do_unallocated;
26
{
25
}
27
return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1;
26
if (s->pauth_active) {
28
}
27
--
29
--
28
2.20.1
30
2.20.1
29
31
30
32
diff view generated by jsdifflib
1
In disas_simd_indexed(), for the case of "complex fp", each indexable
1
From: Richard Henderson <richard.henderson@linaro.org>
2
element is a complex pair, so the total size is twice that indicated
3
in the 'size' field in the encoding. We were trying to do this
4
"double the size" operation with a left shift by 1, but this is
5
incorrect because the 'size' field is a MO_8/MO_16/MO_32/MO_64
6
value, and doubling the size should be done by a simple increment.
7
2
8
This meant we were mishandling FCMLA (by element) of values where
3
Verify that addr + size - 1 does not wrap around.
9
the real and imaginary parts are 32-bit floats, and would incorrectly
10
UNDEF this encoding. (No other insns take this code path, and for
11
16-bit floats it happens that 1 << 1 and 1 + 1 are both the same).
12
4
13
Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com>
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20210212184902.1251044-7-richard.henderson@linaro.org
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com>
16
Message-id: 20190129140411.682-3-peter.maydell@linaro.org
17
---
9
---
18
target/arm/translate-a64.c | 2 +-
10
linux-user/qemu.h | 17 ++++++++++++-----
19
1 file changed, 1 insertion(+), 1 deletion(-)
11
1 file changed, 12 insertions(+), 5 deletions(-)
20
12
21
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
13
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
22
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
23
--- a/target/arm/translate-a64.c
15
--- a/linux-user/qemu.h
24
+++ b/target/arm/translate-a64.c
16
+++ b/linux-user/qemu.h
25
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
17
@@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size;
26
18
#define VERIFY_READ 0
27
case 2: /* complex fp */
19
#define VERIFY_WRITE 1 /* implies read access */
28
/* Each indexable element is a complex pair. */
20
29
- size <<= 1;
21
-static inline int access_ok(int type, abi_ulong addr, abi_ulong size)
30
+ size += 1;
22
+static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
31
switch (size) {
23
{
32
case MO_32:
24
- return guest_addr_valid(addr) &&
33
if (h && !is_q) {
25
- (size == 0 || guest_addr_valid(addr + size - 1)) &&
26
- page_check_range((target_ulong)addr, size,
27
- (type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0;
28
+ if (!guest_addr_valid(addr)) {
29
+ return false;
30
+ }
31
+ if (size != 0 &&
32
+ (addr + size - 1 < addr ||
33
+ !guest_addr_valid(addr + size - 1))) {
34
+ return false;
35
+ }
36
+ return page_check_range((target_ulong)addr, size,
37
+ (type == VERIFY_READ) ? PAGE_READ :
38
+ (PAGE_READ | PAGE_WRITE)) == 0;
39
}
40
41
/* NOTE __get_user and __put_user use host pointers and don't check access.
34
--
42
--
35
2.20.1
43
2.20.1
36
44
37
45
diff view generated by jsdifflib
1
The FCMLA (by element) instruction exists in the
1
From: Richard Henderson <richard.henderson@linaro.org>
2
"vector x indexed element" encoding group, but not in
3
the "scalar x indexed element" group. Correctly UNDEF
4
the unallocated encodings.
5
2
6
Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com>
3
These constants are only ever used with access_ok, and friends.
4
Rather than translating them to PAGE_* bits, let them equal
5
the PAGE_* bits to begin.
6
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20210212184902.1251044-8-richard.henderson@linaro.org
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com>
9
Message-id: 20190129140411.682-2-peter.maydell@linaro.org
10
---
11
---
11
target/arm/translate-a64.c | 2 +-
12
linux-user/qemu.h | 8 +++-----
12
1 file changed, 1 insertion(+), 1 deletion(-)
13
1 file changed, 3 insertions(+), 5 deletions(-)
13
14
14
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
15
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/translate-a64.c
17
--- a/linux-user/qemu.h
17
+++ b/target/arm/translate-a64.c
18
+++ b/linux-user/qemu.h
18
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
19
@@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size;
19
case 0x13: /* FCMLA #90 */
20
20
case 0x15: /* FCMLA #180 */
21
/* user access */
21
case 0x17: /* FCMLA #270 */
22
22
- if (!dc_isar_feature(aa64_fcma, s)) {
23
-#define VERIFY_READ 0
23
+ if (is_scalar || !dc_isar_feature(aa64_fcma, s)) {
24
-#define VERIFY_WRITE 1 /* implies read access */
24
unallocated_encoding(s);
25
+#define VERIFY_READ PAGE_READ
25
return;
26
+#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE)
26
}
27
28
static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
29
{
30
@@ -XXX,XX +XXX,XX @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
31
!guest_addr_valid(addr + size - 1))) {
32
return false;
33
}
34
- return page_check_range((target_ulong)addr, size,
35
- (type == VERIFY_READ) ? PAGE_READ :
36
- (PAGE_READ | PAGE_WRITE)) == 0;
37
+ return page_check_range((target_ulong)addr, size, type) == 0;
38
}
39
40
/* NOTE __get_user and __put_user use host pointers and don't check access.
27
--
41
--
28
2.20.1
42
2.20.1
29
43
30
44
diff view generated by jsdifflib
1
The Arm SSE-200 Subsystem for Embedded is a revised and
1
From: Richard Henderson <richard.henderson@linaro.org>
2
extended version of the older IoTKit SoC. Prepare for
3
adding a model of it by refactoring the IoTKit code into
4
an abstract base class which contains the functionality,
5
driven by a class data block specific to each subclass.
6
(This is the same approach used by the existing bcm283x
7
SoC family implementation.)
8
2
3
These constants are only ever used with access_ok, and friends.
4
Rather than translating them to PAGE_* bits, let them equal
5
the PAGE_* bits to begin.
6
7
Reviewed-by: Warner Losh <imp@bsdimp.com>
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20210212184902.1251044-9-richard.henderson@linaro.org
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20190121185118.18550-6-peter.maydell@linaro.org
13
---
12
---
14
include/hw/arm/iotkit.h | 22 +++++++++++++++++-----
13
bsd-user/qemu.h | 9 ++++-----
15
hw/arm/iotkit.c | 34 +++++++++++++++++++++++++++++-----
14
1 file changed, 4 insertions(+), 5 deletions(-)
16
2 files changed, 46 insertions(+), 10 deletions(-)
17
15
18
diff --git a/include/hw/arm/iotkit.h b/include/hw/arm/iotkit.h
16
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
19
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
20
--- a/include/hw/arm/iotkit.h
18
--- a/bsd-user/qemu.h
21
+++ b/include/hw/arm/iotkit.h
19
+++ b/bsd-user/qemu.h
22
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@ extern unsigned long x86_stack_size;
23
#include "hw/or-irq.h"
21
24
#include "hw/core/split-irq.h"
22
/* user access */
25
23
26
-#define TYPE_ARMSSE "iotkit"
24
-#define VERIFY_READ 0
27
+#define TYPE_ARMSSE "arm-sse"
25
-#define VERIFY_WRITE 1 /* implies read access */
28
#define ARMSSE(obj) OBJECT_CHECK(ARMSSE, (obj), TYPE_ARMSSE)
26
+#define VERIFY_READ PAGE_READ
29
27
+#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE)
30
/*
28
31
- * For the moment TYPE_IOTKIT is a synonym for TYPE_ARMSSE (and the
29
-static inline int access_ok(int type, abi_ulong addr, abi_ulong size)
32
- * latter's underlying name is left as "iotkit"); in a later
30
+static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
33
- * commit it will become a subclass of TYPE_ARMSSE.
34
+ * These type names are for specific IoTKit subsystems; other than
35
+ * instantiating them, code using these devices should always handle
36
+ * them via the ARMSSE base class, so they have no IOTKIT() etc macros.
37
*/
38
-#define TYPE_IOTKIT TYPE_ARMSSE
39
+#define TYPE_IOTKIT "iotkit"
40
41
/* We have an IRQ splitter and an OR gate input for each external PPC
42
* and the 2 internal PPCs
43
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
44
uint32_t mainclk_frq;
45
} ARMSSE;
46
47
+typedef struct ARMSSEInfo ARMSSEInfo;
48
+
49
+typedef struct ARMSSEClass {
50
+ DeviceClass parent_class;
51
+ const ARMSSEInfo *info;
52
+} ARMSSEClass;
53
+
54
+#define ARMSSE_CLASS(klass) \
55
+ OBJECT_CLASS_CHECK(ARMSSEClass, (klass), TYPE_ARMSSE)
56
+#define ARMSSE_GET_CLASS(obj) \
57
+ OBJECT_GET_CLASS(ARMSSEClass, (obj), TYPE_ARMSSE)
58
+
59
#endif
60
diff --git a/hw/arm/iotkit.c b/hw/arm/iotkit.c
61
index XXXXXXX..XXXXXXX 100644
62
--- a/hw/arm/iotkit.c
63
+++ b/hw/arm/iotkit.c
64
@@ -XXX,XX +XXX,XX @@
65
#include "hw/arm/iotkit.h"
66
#include "hw/arm/arm.h"
67
68
+struct ARMSSEInfo {
69
+ const char *name;
70
+};
71
+
72
+static const ARMSSEInfo armsse_variants[] = {
73
+ {
74
+ .name = TYPE_IOTKIT,
75
+ },
76
+};
77
+
78
/* Clock frequency in HZ of the 32KHz "slow clock" */
79
#define S32KCLK (32 * 1000)
80
81
@@ -XXX,XX +XXX,XX @@ static void iotkit_class_init(ObjectClass *klass, void *data)
82
{
31
{
83
DeviceClass *dc = DEVICE_CLASS(klass);
32
- return page_check_range((target_ulong)addr, size,
84
IDAUInterfaceClass *iic = IDAU_INTERFACE_CLASS(klass);
33
- (type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0;
85
+ ARMSSEClass *asc = ARMSSE_CLASS(klass);
34
+ return page_check_range((target_ulong)addr, size, type) == 0;
86
87
dc->realize = iotkit_realize;
88
dc->vmsd = &iotkit_vmstate;
89
dc->props = iotkit_properties;
90
dc->reset = iotkit_reset;
91
iic->check = iotkit_idau_check;
92
+ asc->info = data;
93
}
35
}
94
36
95
-static const TypeInfo iotkit_info = {
37
/* NOTE __get_user and __put_user use host pointers and don't check access. */
96
+static const TypeInfo armsse_info = {
97
.name = TYPE_ARMSSE,
98
.parent = TYPE_SYS_BUS_DEVICE,
99
.instance_size = sizeof(ARMSSE),
100
.instance_init = iotkit_init,
101
- .class_init = iotkit_class_init,
102
+ .abstract = true,
103
.interfaces = (InterfaceInfo[]) {
104
{ TYPE_IDAU_INTERFACE },
105
{ }
106
}
107
};
108
109
-static void iotkit_register_types(void)
110
+static void armsse_register_types(void)
111
{
112
- type_register_static(&iotkit_info);
113
+ int i;
114
+
115
+ type_register_static(&armsse_info);
116
+
117
+ for (i = 0; i < ARRAY_SIZE(armsse_variants); i++) {
118
+ TypeInfo ti = {
119
+ .name = armsse_variants[i].name,
120
+ .parent = TYPE_ARMSSE,
121
+ .class_init = iotkit_class_init,
122
+ .class_data = (void *)&armsse_variants[i],
123
+ };
124
+ type_register(&ti);
125
+ }
126
}
127
128
-type_init(iotkit_register_types);
129
+type_init(armsse_register_types);
130
--
38
--
131
2.20.1
39
2.20.1
132
40
133
41
diff view generated by jsdifflib
1
The SSE-200 has 4 banks of SRAM, each with its own internal
1
From: Richard Henderson <richard.henderson@linaro.org>
2
Memory Protection Controller. The interrupt status for these
3
extra MPCs appears in the same security controller SECMPCINTSTATUS
4
register as the MPC for the IoTKit's single SRAM bank. Enhance the
5
iotkit-secctl device to allow 4 MPCs. (If the particular IoTKit/SSE
6
variant in use does not have all 4 MPCs then the unused inputs will
7
simply result in the SECMPCINTSTATUS bits being zero as required.)
8
2
9
The hardcoded constant "1"s in armsse.c indicate the actual number
3
This is the only use of guest_addr_valid that does not begin
10
of SRAM MPCs the IoTKit has, and will be replaced in the following
4
with a guest address, but a host address being transformed to
11
commit.
5
a guest address.
12
6
7
We will shortly adjust guest_addr_valid to handle guest memory
8
tags, and the host address should not be subjected to that.
9
10
Move h2g_valid adjacent to the other h2g macros.
11
12
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
14
Message-id: 20210212184902.1251044-10-richard.henderson@linaro.org
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
15
Message-id: 20190121185118.18550-9-peter.maydell@linaro.org
16
---
16
---
17
include/hw/misc/iotkit-secctl.h | 6 +++---
17
include/exec/cpu_ldst.h | 5 ++++-
18
hw/arm/armsse.c | 6 +++---
18
1 file changed, 4 insertions(+), 1 deletion(-)
19
hw/misc/iotkit-secctl.c | 5 +++--
20
3 files changed, 9 insertions(+), 8 deletions(-)
21
19
22
diff --git a/include/hw/misc/iotkit-secctl.h b/include/hw/misc/iotkit-secctl.h
20
diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h
23
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
24
--- a/include/hw/misc/iotkit-secctl.h
22
--- a/include/exec/cpu_ldst.h
25
+++ b/include/hw/misc/iotkit-secctl.h
23
+++ b/include/exec/cpu_ldst.h
26
@@ -XXX,XX +XXX,XX @@
24
@@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr;
27
* + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_enable
25
#else
28
* + named GPIO outputs ahb_ppcexp{0,1,2,3}_irq_clear
26
#define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX)
29
* + named GPIO inputs ahb_ppcexp{0,1,2,3}_irq_status
27
#endif
30
- * Controlling the MPC in the IoTKit:
28
-#define h2g_valid(x) guest_addr_valid((uintptr_t)(x) - guest_base)
31
- * + named GPIO input mpc_status
29
32
+ * Controlling the (up to) 4 MPCs in the IoTKit/SSE:
30
static inline bool guest_range_valid(abi_ulong start, abi_ulong len)
33
+ * + named GPIO inputs mpc_status[0..3]
34
* Controlling each of the 16 expansion MPCs which a system using the IoTKit
35
* might provide:
36
* + named GPIO inputs mpcexp_status[0..15]
37
@@ -XXX,XX +XXX,XX @@
38
#define IOTS_NUM_APB_EXP_PPC 4
39
#define IOTS_NUM_AHB_EXP_PPC 4
40
#define IOTS_NUM_EXP_MPC 16
41
-#define IOTS_NUM_MPC 1
42
+#define IOTS_NUM_MPC 4
43
#define IOTS_NUM_EXP_MSC 16
44
45
typedef struct IoTKitSecCtl IoTKitSecCtl;
46
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
47
index XXXXXXX..XXXXXXX 100644
48
--- a/hw/arm/armsse.c
49
+++ b/hw/arm/armsse.c
50
@@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj)
51
sizeof(s->mpc_irq_orgate), TYPE_OR_IRQ,
52
&error_abort, NULL);
53
54
- for (i = 0; i < ARRAY_SIZE(s->mpc_irq_splitter); i++) {
55
+ for (i = 0; i < IOTS_NUM_EXP_MPC + 1; i++) {
56
char *name = g_strdup_printf("mpc-irq-splitter-%d", i);
57
SplitIRQ *splitter = &s->mpc_irq_splitter[i];
58
59
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
60
61
/* We must OR together lines from the MPC splitters to go to the NVIC */
62
object_property_set_int(OBJECT(&s->mpc_irq_orgate),
63
- IOTS_NUM_EXP_MPC + IOTS_NUM_MPC, "num-lines", &err);
64
+ IOTS_NUM_EXP_MPC + 1, "num-lines", &err);
65
if (err) {
66
error_propagate(errp, err);
67
return;
68
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
69
}
70
71
/* Wire up the splitters for the MPC IRQs */
72
- for (i = 0; i < IOTS_NUM_EXP_MPC + IOTS_NUM_MPC; i++) {
73
+ for (i = 0; i < IOTS_NUM_EXP_MPC + 1; i++) {
74
SplitIRQ *splitter = &s->mpc_irq_splitter[i];
75
DeviceState *dev_splitter = DEVICE(splitter);
76
77
diff --git a/hw/misc/iotkit-secctl.c b/hw/misc/iotkit-secctl.c
78
index XXXXXXX..XXXXXXX 100644
79
--- a/hw/misc/iotkit-secctl.c
80
+++ b/hw/misc/iotkit-secctl.c
81
@@ -XXX,XX +XXX,XX @@ static void iotkit_secctl_mpc_status(void *opaque, int n, int level)
82
{
31
{
83
IoTKitSecCtl *s = IOTKIT_SECCTL(opaque);
32
return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1;
84
85
- s->mpcintstatus = deposit32(s->mpcintstatus, 0, 1, !!level);
86
+ s->mpcintstatus = deposit32(s->mpcintstatus, n, 1, !!level);
87
}
33
}
88
34
89
static void iotkit_secctl_mpcexp_status(void *opaque, int n, int level)
35
+#define h2g_valid(x) \
90
@@ -XXX,XX +XXX,XX @@ static void iotkit_secctl_init(Object *obj)
36
+ (HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS || \
91
qdev_init_gpio_out_named(dev, &s->sec_resp_cfg, "sec_resp_cfg", 1);
37
+ (uintptr_t)(x) - guest_base <= GUEST_ADDR_MAX)
92
qdev_init_gpio_out_named(dev, &s->nsc_cfg_irq, "nsc_cfg", 1);
38
+
93
39
#define h2g_nocheck(x) ({ \
94
- qdev_init_gpio_in_named(dev, iotkit_secctl_mpc_status, "mpc_status", 1);
40
uintptr_t __ret = (uintptr_t)(x) - guest_base; \
95
+ qdev_init_gpio_in_named(dev, iotkit_secctl_mpc_status, "mpc_status",
41
(abi_ptr)__ret; \
96
+ IOTS_NUM_MPC);
97
qdev_init_gpio_in_named(dev, iotkit_secctl_mpcexp_status,
98
"mpcexp_status", IOTS_NUM_EXP_MPC);
99
100
--
42
--
101
2.20.1
43
2.20.1
102
44
103
45
diff view generated by jsdifflib
1
In the AdvSIMD scalar x indexed element and vector x indexed element
1
From: Richard Henderson <richard.henderson@linaro.org>
2
encoding group, the SDOT and UDOT instructions are vector only,
3
and their opcode is unallocated in the scalar group. Correctly
4
UNDEF this unallocated encoding.
5
2
6
Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com>
3
We must always use GUEST_ADDR_MAX, because even 32-bit hosts can
4
use -R <reserved_va> to restrict the memory address of the guest.
5
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210212184902.1251044-11-richard.henderson@linaro.org
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com>
9
Message-id: 20190125182626.9221-8-peter.maydell@linaro.org
10
---
10
---
11
target/arm/translate-a64.c | 2 +-
11
include/exec/cpu_ldst.h | 9 ++++-----
12
1 file changed, 1 insertion(+), 1 deletion(-)
12
1 file changed, 4 insertions(+), 5 deletions(-)
13
13
14
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
14
diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h
15
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/translate-a64.c
16
--- a/include/exec/cpu_ldst.h
17
+++ b/target/arm/translate-a64.c
17
+++ b/include/exec/cpu_ldst.h
18
@@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn)
18
@@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr;
19
break;
19
/* All direct uses of g2h and h2g need to go away for usermode softmmu. */
20
case 0x0e: /* SDOT */
20
#define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base))
21
case 0x1e: /* UDOT */
21
22
- if (size != MO_32 || !dc_isar_feature(aa64_dp, s)) {
22
-#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
23
+ if (is_scalar || size != MO_32 || !dc_isar_feature(aa64_dp, s)) {
23
-#define guest_addr_valid(x) (1)
24
unallocated_encoding(s);
24
-#else
25
return;
25
-#define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX)
26
}
26
-#endif
27
+static inline bool guest_addr_valid(abi_ulong x)
28
+{
29
+ return x <= GUEST_ADDR_MAX;
30
+}
31
32
static inline bool guest_range_valid(abi_ulong start, abi_ulong len)
33
{
27
--
34
--
28
2.20.1
35
2.20.1
29
36
30
37
diff view generated by jsdifflib
1
The SSE-200 has four banks of SRAM, each with its own
1
From: Richard Henderson <richard.henderson@linaro.org>
2
Memory Protection Controller, where the IoTKit has only one.
3
Make the number of SRAM banks a field in ARMSSEInfo.
4
2
3
Provide an identity fallback for target that do not
4
use tagged addresses.
5
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210212184902.1251044-12-richard.henderson@linaro.org
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20190121185118.18550-10-peter.maydell@linaro.org
8
---
10
---
9
include/hw/arm/armsse.h | 9 +++--
11
include/exec/cpu_ldst.h | 7 +++++++
10
hw/arm/armsse.c | 78 ++++++++++++++++++++++++++---------------
12
1 file changed, 7 insertions(+)
11
2 files changed, 56 insertions(+), 31 deletions(-)
12
13
13
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
14
diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h
14
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/arm/armsse.h
16
--- a/include/exec/cpu_ldst.h
16
+++ b/include/hw/arm/armsse.h
17
+++ b/include/exec/cpu_ldst.h
17
@@ -XXX,XX +XXX,XX @@
18
@@ -XXX,XX +XXX,XX @@ typedef uint64_t abi_ptr;
18
#define NUM_EXTERNAL_PPCS (IOTS_NUM_AHB_EXP_PPC + IOTS_NUM_APB_EXP_PPC)
19
#define TARGET_ABI_FMT_ptr "%"PRIx64
19
#define NUM_PPCS (NUM_EXTERNAL_PPCS + 2)
20
#endif
20
21
21
+#define MAX_SRAM_BANKS 4
22
+#ifndef TARGET_TAGGED_ADDRESSES
22
+#if MAX_SRAM_BANKS > IOTS_NUM_MPC
23
+static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x)
23
+#error Too many SRAM banks
24
+{
25
+ return x;
26
+}
24
+#endif
27
+#endif
25
+
28
+
26
typedef struct ARMSSE {
29
/* All direct uses of g2h and h2g need to go away for usermode softmmu. */
27
/*< private >*/
30
#define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base))
28
SysBusDevice parent_obj;
31
29
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
30
IoTKitSecCtl secctl;
31
TZPPC apb_ppc0;
32
TZPPC apb_ppc1;
33
- TZMPC mpc;
34
+ TZMPC mpc[IOTS_NUM_MPC];
35
CMSDKAPBTIMER timer0;
36
CMSDKAPBTIMER timer1;
37
CMSDKAPBTIMER s32ktimer;
38
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
39
MemoryRegion alias1;
40
MemoryRegion alias2;
41
MemoryRegion alias3;
42
- MemoryRegion sram0;
43
+ MemoryRegion sram[MAX_SRAM_BANKS];
44
45
qemu_irq *exp_irqs;
46
qemu_irq ppc0_irq;
47
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/hw/arm/armsse.c
50
+++ b/hw/arm/armsse.c
51
@@ -XXX,XX +XXX,XX @@
52
53
struct ARMSSEInfo {
54
const char *name;
55
+ int sram_banks;
56
};
57
58
static const ARMSSEInfo armsse_variants[] = {
59
{
60
.name = TYPE_IOTKIT,
61
+ .sram_banks = 1,
62
},
63
};
64
65
@@ -XXX,XX +XXX,XX @@ static void armsse_forward_sec_resp_cfg(ARMSSE *s)
66
static void armsse_init(Object *obj)
67
{
68
ARMSSE *s = ARMSSE(obj);
69
+ ARMSSEClass *asc = ARMSSE_GET_CLASS(obj);
70
+ const ARMSSEInfo *info = asc->info;
71
int i;
72
73
+ assert(info->sram_banks <= MAX_SRAM_BANKS);
74
+
75
memory_region_init(&s->container, obj, "armsse-container", UINT64_MAX);
76
77
sysbus_init_child_obj(obj, "armv7m", &s->armv7m, sizeof(s->armv7m),
78
@@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj)
79
TYPE_TZ_PPC);
80
sysbus_init_child_obj(obj, "apb-ppc1", &s->apb_ppc1, sizeof(s->apb_ppc1),
81
TYPE_TZ_PPC);
82
- sysbus_init_child_obj(obj, "mpc", &s->mpc, sizeof(s->mpc), TYPE_TZ_MPC);
83
+ for (i = 0; i < info->sram_banks; i++) {
84
+ char *name = g_strdup_printf("mpc%d", i);
85
+ sysbus_init_child_obj(obj, name, &s->mpc[i],
86
+ sizeof(s->mpc[i]), TYPE_TZ_MPC);
87
+ g_free(name);
88
+ }
89
object_initialize_child(obj, "mpc-irq-orgate", &s->mpc_irq_orgate,
90
sizeof(s->mpc_irq_orgate), TYPE_OR_IRQ,
91
&error_abort, NULL);
92
93
- for (i = 0; i < IOTS_NUM_EXP_MPC + 1; i++) {
94
+ for (i = 0; i < IOTS_NUM_EXP_MPC + info->sram_banks; i++) {
95
char *name = g_strdup_printf("mpc-irq-splitter-%d", i);
96
SplitIRQ *splitter = &s->mpc_irq_splitter[i];
97
98
@@ -XXX,XX +XXX,XX @@ static void armsse_mpcexp_status(void *opaque, int n, int level)
99
static void armsse_realize(DeviceState *dev, Error **errp)
100
{
101
ARMSSE *s = ARMSSE(dev);
102
+ ARMSSEClass *asc = ARMSSE_GET_CLASS(dev);
103
+ const ARMSSEInfo *info = asc->info;
104
int i;
105
MemoryRegion *mr;
106
Error *err = NULL;
107
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
108
qdev_connect_gpio_out_named(dev_secctl, "sec_resp_cfg", 0,
109
qdev_get_gpio_in(dev_splitter, 0));
110
111
- /* This RAM lives behind the Memory Protection Controller */
112
- memory_region_init_ram(&s->sram0, NULL, "armsse.sram0", 0x00008000, &err);
113
- if (err) {
114
- error_propagate(errp, err);
115
- return;
116
+ /* Each SRAM bank lives behind its own Memory Protection Controller */
117
+ for (i = 0; i < info->sram_banks; i++) {
118
+ char *ramname = g_strdup_printf("armsse.sram%d", i);
119
+ SysBusDevice *sbd_mpc;
120
+
121
+ memory_region_init_ram(&s->sram[i], NULL, ramname, 0x00008000, &err);
122
+ g_free(ramname);
123
+ if (err) {
124
+ error_propagate(errp, err);
125
+ return;
126
+ }
127
+ object_property_set_link(OBJECT(&s->mpc[i]), OBJECT(&s->sram[i]),
128
+ "downstream", &err);
129
+ if (err) {
130
+ error_propagate(errp, err);
131
+ return;
132
+ }
133
+ object_property_set_bool(OBJECT(&s->mpc[i]), true, "realized", &err);
134
+ if (err) {
135
+ error_propagate(errp, err);
136
+ return;
137
+ }
138
+ /* Map the upstream end of the MPC into the right place... */
139
+ sbd_mpc = SYS_BUS_DEVICE(&s->mpc[i]);
140
+ memory_region_add_subregion(&s->container, 0x20000000 + i * 0x8000,
141
+ sysbus_mmio_get_region(sbd_mpc, 1));
142
+ /* ...and its register interface */
143
+ memory_region_add_subregion(&s->container, 0x50083000 + i * 0x1000,
144
+ sysbus_mmio_get_region(sbd_mpc, 0));
145
}
146
- object_property_set_link(OBJECT(&s->mpc), OBJECT(&s->sram0),
147
- "downstream", &err);
148
- if (err) {
149
- error_propagate(errp, err);
150
- return;
151
- }
152
- object_property_set_bool(OBJECT(&s->mpc), true, "realized", &err);
153
- if (err) {
154
- error_propagate(errp, err);
155
- return;
156
- }
157
- /* Map the upstream end of the MPC into the right place... */
158
- memory_region_add_subregion(&s->container, 0x20000000,
159
- sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->mpc),
160
- 1));
161
- /* ...and its register interface */
162
- memory_region_add_subregion(&s->container, 0x50083000,
163
- sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->mpc),
164
- 0));
165
166
/* We must OR together lines from the MPC splitters to go to the NVIC */
167
object_property_set_int(OBJECT(&s->mpc_irq_orgate),
168
- IOTS_NUM_EXP_MPC + 1, "num-lines", &err);
169
+ IOTS_NUM_EXP_MPC + info->sram_banks,
170
+ "num-lines", &err);
171
if (err) {
172
error_propagate(errp, err);
173
return;
174
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
175
}
176
177
/* Wire up the splitters for the MPC IRQs */
178
- for (i = 0; i < IOTS_NUM_EXP_MPC + 1; i++) {
179
+ for (i = 0; i < IOTS_NUM_EXP_MPC + info->sram_banks; i++) {
180
SplitIRQ *splitter = &s->mpc_irq_splitter[i];
181
DeviceState *dev_splitter = DEVICE(splitter);
182
183
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
184
"mpcexp_status", i));
185
} else {
186
/* Splitter input is from our own MPC */
187
- qdev_connect_gpio_out_named(DEVICE(&s->mpc), "irq", 0,
188
+ qdev_connect_gpio_out_named(DEVICE(&s->mpc[i - IOTS_NUM_EXP_MPC]),
189
+ "irq", 0,
190
qdev_get_gpio_in(dev_splitter, 0));
191
qdev_connect_gpio_out(dev_splitter, 0,
192
qdev_get_gpio_in_named(dev_secctl,
193
--
32
--
194
2.20.1
33
2.20.1
195
34
196
35
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Use g2h_untagged in contexts that have no cpu, e.g. the binary
4
loaders that operate before the primary cpu is created. As a
5
colollary, target_mmap and friends must use untagged addresses,
6
since they are used by the loaders.
7
8
Use g2h_untagged on values returned from target_mmap, as the
9
kernel never applies a tag itself.
10
11
Use g2h_untagged on all pc values. The only current user of
12
tags, aarch64, removes tags from code addresses upon branch,
13
so "pc" is always untagged.
14
15
Use g2h with the cpu context on hand wherever possible.
16
17
Use g2h_untagged in lock_user, which will be updated soon.
18
19
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
20
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
21
Message-id: 20210212184902.1251044-13-richard.henderson@linaro.org
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
---
23
---
7
linux-user/elfload.c | 9 +++++++++
24
bsd-user/qemu.h | 8 ++--
8
1 file changed, 9 insertions(+)
25
include/exec/cpu_ldst.h | 12 +++++-
26
include/exec/exec-all.h | 2 +-
27
linux-user/qemu.h | 6 +--
28
accel/tcg/translate-all.c | 4 +-
29
accel/tcg/user-exec.c | 48 ++++++++++++------------
30
bsd-user/elfload.c | 2 +-
31
bsd-user/main.c | 4 +-
32
bsd-user/mmap.c | 23 ++++++------
33
linux-user/elfload.c | 12 +++---
34
linux-user/flatload.c | 2 +-
35
linux-user/hppa/cpu_loop.c | 31 ++++++++--------
36
linux-user/i386/cpu_loop.c | 4 +-
37
linux-user/mmap.c | 45 +++++++++++-----------
38
linux-user/ppc/signal.c | 4 +-
39
linux-user/syscall.c | 72 +++++++++++++++++++-----------------
40
target/arm/helper-a64.c | 4 +-
41
target/hppa/op_helper.c | 2 +-
42
target/i386/tcg/mem_helper.c | 2 +-
43
target/s390x/mem_helper.c | 4 +-
44
20 files changed, 154 insertions(+), 137 deletions(-)
9
45
46
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
47
index XXXXXXX..XXXXXXX 100644
48
--- a/bsd-user/qemu.h
49
+++ b/bsd-user/qemu.h
50
@@ -XXX,XX +XXX,XX @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
51
void *addr;
52
addr = g_malloc(len);
53
if (copy)
54
- memcpy(addr, g2h(guest_addr), len);
55
+ memcpy(addr, g2h_untagged(guest_addr), len);
56
else
57
memset(addr, 0, len);
58
return addr;
59
}
60
#else
61
- return g2h(guest_addr);
62
+ return g2h_untagged(guest_addr);
63
#endif
64
}
65
66
@@ -XXX,XX +XXX,XX @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
67
#ifdef DEBUG_REMAP
68
if (!host_ptr)
69
return;
70
- if (host_ptr == g2h(guest_addr))
71
+ if (host_ptr == g2h_untagged(guest_addr))
72
return;
73
if (len > 0)
74
- memcpy(g2h(guest_addr), host_ptr, len);
75
+ memcpy(g2h_untagged(guest_addr), host_ptr, len);
76
g_free(host_ptr);
77
#endif
78
}
79
diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h
80
index XXXXXXX..XXXXXXX 100644
81
--- a/include/exec/cpu_ldst.h
82
+++ b/include/exec/cpu_ldst.h
83
@@ -XXX,XX +XXX,XX @@ static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x)
84
#endif
85
86
/* All direct uses of g2h and h2g need to go away for usermode softmmu. */
87
-#define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base))
88
+static inline void *g2h_untagged(abi_ptr x)
89
+{
90
+ return (void *)((uintptr_t)(x) + guest_base);
91
+}
92
+
93
+static inline void *g2h(CPUState *cs, abi_ptr x)
94
+{
95
+ return g2h_untagged(cpu_untagged_addr(cs, x));
96
+}
97
98
static inline bool guest_addr_valid(abi_ulong x)
99
{
100
@@ -XXX,XX +XXX,XX @@ static inline int cpu_ldsw_code(CPUArchState *env, abi_ptr addr)
101
static inline void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr,
102
MMUAccessType access_type, int mmu_idx)
103
{
104
- return g2h(addr);
105
+ return g2h(env_cpu(env), addr);
106
}
107
#else
108
void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr,
109
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
110
index XXXXXXX..XXXXXXX 100644
111
--- a/include/exec/exec-all.h
112
+++ b/include/exec/exec-all.h
113
@@ -XXX,XX +XXX,XX @@ static inline tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env,
114
void **hostp)
115
{
116
if (hostp) {
117
- *hostp = g2h(addr);
118
+ *hostp = g2h_untagged(addr);
119
}
120
return addr;
121
}
122
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
123
index XXXXXXX..XXXXXXX 100644
124
--- a/linux-user/qemu.h
125
+++ b/linux-user/qemu.h
126
@@ -XXX,XX +XXX,XX @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy
127
return addr;
128
}
129
#else
130
- return g2h(guest_addr);
131
+ return g2h_untagged(guest_addr);
132
#endif
133
}
134
135
@@ -XXX,XX +XXX,XX @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
136
#ifdef DEBUG_REMAP
137
if (!host_ptr)
138
return;
139
- if (host_ptr == g2h(guest_addr))
140
+ if (host_ptr == g2h_untagged(guest_addr))
141
return;
142
if (len > 0)
143
- memcpy(g2h(guest_addr), host_ptr, len);
144
+ memcpy(g2h_untagged(guest_addr), host_ptr, len);
145
g_free(host_ptr);
146
#endif
147
}
148
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
149
index XXXXXXX..XXXXXXX 100644
150
--- a/accel/tcg/translate-all.c
151
+++ b/accel/tcg/translate-all.c
152
@@ -XXX,XX +XXX,XX @@ static inline void tb_page_add(PageDesc *p, TranslationBlock *tb,
153
prot |= p2->flags;
154
p2->flags &= ~PAGE_WRITE;
155
}
156
- mprotect(g2h(page_addr), qemu_host_page_size,
157
+ mprotect(g2h_untagged(page_addr), qemu_host_page_size,
158
(prot & PAGE_BITS) & ~PAGE_WRITE);
159
if (DEBUG_TB_INVALIDATE_GATE) {
160
printf("protecting code page: 0x" TB_PAGE_ADDR_FMT "\n", page_addr);
161
@@ -XXX,XX +XXX,XX @@ int page_unprotect(target_ulong address, uintptr_t pc)
162
}
163
#endif
164
}
165
- mprotect((void *)g2h(host_start), qemu_host_page_size,
166
+ mprotect((void *)g2h_untagged(host_start), qemu_host_page_size,
167
prot & PAGE_BITS);
168
}
169
mmap_unlock();
170
diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c
171
index XXXXXXX..XXXXXXX 100644
172
--- a/accel/tcg/user-exec.c
173
+++ b/accel/tcg/user-exec.c
174
@@ -XXX,XX +XXX,XX @@ int probe_access_flags(CPUArchState *env, target_ulong addr,
175
int flags;
176
177
flags = probe_access_internal(env, addr, 0, access_type, nonfault, ra);
178
- *phost = flags ? NULL : g2h(addr);
179
+ *phost = flags ? NULL : g2h(env_cpu(env), addr);
180
return flags;
181
}
182
183
@@ -XXX,XX +XXX,XX @@ void *probe_access(CPUArchState *env, target_ulong addr, int size,
184
flags = probe_access_internal(env, addr, size, access_type, false, ra);
185
g_assert(flags == 0);
186
187
- return size ? g2h(addr) : NULL;
188
+ return size ? g2h(env_cpu(env), addr) : NULL;
189
}
190
191
#if defined(__i386__)
192
@@ -XXX,XX +XXX,XX @@ uint32_t cpu_ldub_data(CPUArchState *env, abi_ptr ptr)
193
uint16_t meminfo = trace_mem_get_info(MO_UB, MMU_USER_IDX, false);
194
195
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
196
- ret = ldub_p(g2h(ptr));
197
+ ret = ldub_p(g2h(env_cpu(env), ptr));
198
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
199
return ret;
200
}
201
@@ -XXX,XX +XXX,XX @@ int cpu_ldsb_data(CPUArchState *env, abi_ptr ptr)
202
uint16_t meminfo = trace_mem_get_info(MO_SB, MMU_USER_IDX, false);
203
204
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
205
- ret = ldsb_p(g2h(ptr));
206
+ ret = ldsb_p(g2h(env_cpu(env), ptr));
207
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
208
return ret;
209
}
210
@@ -XXX,XX +XXX,XX @@ uint32_t cpu_lduw_be_data(CPUArchState *env, abi_ptr ptr)
211
uint16_t meminfo = trace_mem_get_info(MO_BEUW, MMU_USER_IDX, false);
212
213
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
214
- ret = lduw_be_p(g2h(ptr));
215
+ ret = lduw_be_p(g2h(env_cpu(env), ptr));
216
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
217
return ret;
218
}
219
@@ -XXX,XX +XXX,XX @@ int cpu_ldsw_be_data(CPUArchState *env, abi_ptr ptr)
220
uint16_t meminfo = trace_mem_get_info(MO_BESW, MMU_USER_IDX, false);
221
222
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
223
- ret = ldsw_be_p(g2h(ptr));
224
+ ret = ldsw_be_p(g2h(env_cpu(env), ptr));
225
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
226
return ret;
227
}
228
@@ -XXX,XX +XXX,XX @@ uint32_t cpu_ldl_be_data(CPUArchState *env, abi_ptr ptr)
229
uint16_t meminfo = trace_mem_get_info(MO_BEUL, MMU_USER_IDX, false);
230
231
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
232
- ret = ldl_be_p(g2h(ptr));
233
+ ret = ldl_be_p(g2h(env_cpu(env), ptr));
234
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
235
return ret;
236
}
237
@@ -XXX,XX +XXX,XX @@ uint64_t cpu_ldq_be_data(CPUArchState *env, abi_ptr ptr)
238
uint16_t meminfo = trace_mem_get_info(MO_BEQ, MMU_USER_IDX, false);
239
240
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
241
- ret = ldq_be_p(g2h(ptr));
242
+ ret = ldq_be_p(g2h(env_cpu(env), ptr));
243
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
244
return ret;
245
}
246
@@ -XXX,XX +XXX,XX @@ uint32_t cpu_lduw_le_data(CPUArchState *env, abi_ptr ptr)
247
uint16_t meminfo = trace_mem_get_info(MO_LEUW, MMU_USER_IDX, false);
248
249
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
250
- ret = lduw_le_p(g2h(ptr));
251
+ ret = lduw_le_p(g2h(env_cpu(env), ptr));
252
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
253
return ret;
254
}
255
@@ -XXX,XX +XXX,XX @@ int cpu_ldsw_le_data(CPUArchState *env, abi_ptr ptr)
256
uint16_t meminfo = trace_mem_get_info(MO_LESW, MMU_USER_IDX, false);
257
258
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
259
- ret = ldsw_le_p(g2h(ptr));
260
+ ret = ldsw_le_p(g2h(env_cpu(env), ptr));
261
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
262
return ret;
263
}
264
@@ -XXX,XX +XXX,XX @@ uint32_t cpu_ldl_le_data(CPUArchState *env, abi_ptr ptr)
265
uint16_t meminfo = trace_mem_get_info(MO_LEUL, MMU_USER_IDX, false);
266
267
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
268
- ret = ldl_le_p(g2h(ptr));
269
+ ret = ldl_le_p(g2h(env_cpu(env), ptr));
270
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
271
return ret;
272
}
273
@@ -XXX,XX +XXX,XX @@ uint64_t cpu_ldq_le_data(CPUArchState *env, abi_ptr ptr)
274
uint16_t meminfo = trace_mem_get_info(MO_LEQ, MMU_USER_IDX, false);
275
276
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
277
- ret = ldq_le_p(g2h(ptr));
278
+ ret = ldq_le_p(g2h(env_cpu(env), ptr));
279
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
280
return ret;
281
}
282
@@ -XXX,XX +XXX,XX @@ void cpu_stb_data(CPUArchState *env, abi_ptr ptr, uint32_t val)
283
uint16_t meminfo = trace_mem_get_info(MO_UB, MMU_USER_IDX, true);
284
285
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
286
- stb_p(g2h(ptr), val);
287
+ stb_p(g2h(env_cpu(env), ptr), val);
288
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
289
}
290
291
@@ -XXX,XX +XXX,XX @@ void cpu_stw_be_data(CPUArchState *env, abi_ptr ptr, uint32_t val)
292
uint16_t meminfo = trace_mem_get_info(MO_BEUW, MMU_USER_IDX, true);
293
294
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
295
- stw_be_p(g2h(ptr), val);
296
+ stw_be_p(g2h(env_cpu(env), ptr), val);
297
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
298
}
299
300
@@ -XXX,XX +XXX,XX @@ void cpu_stl_be_data(CPUArchState *env, abi_ptr ptr, uint32_t val)
301
uint16_t meminfo = trace_mem_get_info(MO_BEUL, MMU_USER_IDX, true);
302
303
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
304
- stl_be_p(g2h(ptr), val);
305
+ stl_be_p(g2h(env_cpu(env), ptr), val);
306
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
307
}
308
309
@@ -XXX,XX +XXX,XX @@ void cpu_stq_be_data(CPUArchState *env, abi_ptr ptr, uint64_t val)
310
uint16_t meminfo = trace_mem_get_info(MO_BEQ, MMU_USER_IDX, true);
311
312
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
313
- stq_be_p(g2h(ptr), val);
314
+ stq_be_p(g2h(env_cpu(env), ptr), val);
315
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
316
}
317
318
@@ -XXX,XX +XXX,XX @@ void cpu_stw_le_data(CPUArchState *env, abi_ptr ptr, uint32_t val)
319
uint16_t meminfo = trace_mem_get_info(MO_LEUW, MMU_USER_IDX, true);
320
321
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
322
- stw_le_p(g2h(ptr), val);
323
+ stw_le_p(g2h(env_cpu(env), ptr), val);
324
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
325
}
326
327
@@ -XXX,XX +XXX,XX @@ void cpu_stl_le_data(CPUArchState *env, abi_ptr ptr, uint32_t val)
328
uint16_t meminfo = trace_mem_get_info(MO_LEUL, MMU_USER_IDX, true);
329
330
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
331
- stl_le_p(g2h(ptr), val);
332
+ stl_le_p(g2h(env_cpu(env), ptr), val);
333
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
334
}
335
336
@@ -XXX,XX +XXX,XX @@ void cpu_stq_le_data(CPUArchState *env, abi_ptr ptr, uint64_t val)
337
uint16_t meminfo = trace_mem_get_info(MO_LEQ, MMU_USER_IDX, true);
338
339
trace_guest_mem_before_exec(env_cpu(env), ptr, meminfo);
340
- stq_le_p(g2h(ptr), val);
341
+ stq_le_p(g2h(env_cpu(env), ptr), val);
342
qemu_plugin_vcpu_mem_cb(env_cpu(env), ptr, meminfo);
343
}
344
345
@@ -XXX,XX +XXX,XX @@ uint32_t cpu_ldub_code(CPUArchState *env, abi_ptr ptr)
346
uint32_t ret;
347
348
set_helper_retaddr(1);
349
- ret = ldub_p(g2h(ptr));
350
+ ret = ldub_p(g2h_untagged(ptr));
351
clear_helper_retaddr();
352
return ret;
353
}
354
@@ -XXX,XX +XXX,XX @@ uint32_t cpu_lduw_code(CPUArchState *env, abi_ptr ptr)
355
uint32_t ret;
356
357
set_helper_retaddr(1);
358
- ret = lduw_p(g2h(ptr));
359
+ ret = lduw_p(g2h_untagged(ptr));
360
clear_helper_retaddr();
361
return ret;
362
}
363
@@ -XXX,XX +XXX,XX @@ uint32_t cpu_ldl_code(CPUArchState *env, abi_ptr ptr)
364
uint32_t ret;
365
366
set_helper_retaddr(1);
367
- ret = ldl_p(g2h(ptr));
368
+ ret = ldl_p(g2h_untagged(ptr));
369
clear_helper_retaddr();
370
return ret;
371
}
372
@@ -XXX,XX +XXX,XX @@ uint64_t cpu_ldq_code(CPUArchState *env, abi_ptr ptr)
373
uint64_t ret;
374
375
set_helper_retaddr(1);
376
- ret = ldq_p(g2h(ptr));
377
+ ret = ldq_p(g2h_untagged(ptr));
378
clear_helper_retaddr();
379
return ret;
380
}
381
@@ -XXX,XX +XXX,XX @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
382
if (unlikely(addr & (size - 1))) {
383
cpu_loop_exit_atomic(env_cpu(env), retaddr);
384
}
385
- void *ret = g2h(addr);
386
+ void *ret = g2h(env_cpu(env), addr);
387
set_helper_retaddr(retaddr);
388
return ret;
389
}
390
diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c
391
index XXXXXXX..XXXXXXX 100644
392
--- a/bsd-user/elfload.c
393
+++ b/bsd-user/elfload.c
394
@@ -XXX,XX +XXX,XX @@ static void padzero(abi_ulong elf_bss, abi_ulong last_bss)
395
end_addr1 = REAL_HOST_PAGE_ALIGN(elf_bss);
396
end_addr = HOST_PAGE_ALIGN(elf_bss);
397
if (end_addr1 < end_addr) {
398
- mmap((void *)g2h(end_addr1), end_addr - end_addr1,
399
+ mmap((void *)g2h_untagged(end_addr1), end_addr - end_addr1,
400
PROT_READ|PROT_WRITE|PROT_EXEC,
401
MAP_FIXED|MAP_PRIVATE|MAP_ANON, -1, 0);
402
}
403
diff --git a/bsd-user/main.c b/bsd-user/main.c
404
index XXXXXXX..XXXXXXX 100644
405
--- a/bsd-user/main.c
406
+++ b/bsd-user/main.c
407
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
408
env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1),
409
PROT_READ|PROT_WRITE,
410
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
411
- idt_table = g2h(env->idt.base);
412
+ idt_table = g2h_untagged(env->idt.base);
413
set_idt(0, 0);
414
set_idt(1, 0);
415
set_idt(2, 0);
416
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
417
PROT_READ|PROT_WRITE,
418
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
419
env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1;
420
- gdt_table = g2h(env->gdt.base);
421
+ gdt_table = g2h_untagged(env->gdt.base);
422
#ifdef TARGET_ABI32
423
write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff,
424
DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK |
425
diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
426
index XXXXXXX..XXXXXXX 100644
427
--- a/bsd-user/mmap.c
428
+++ b/bsd-user/mmap.c
429
@@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
430
}
431
end = host_end;
432
}
433
- ret = mprotect(g2h(host_start), qemu_host_page_size, prot1 & PAGE_BITS);
434
+ ret = mprotect(g2h_untagged(host_start),
435
+ qemu_host_page_size, prot1 & PAGE_BITS);
436
if (ret != 0)
437
goto error;
438
host_start += qemu_host_page_size;
439
@@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
440
for(addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
441
prot1 |= page_get_flags(addr);
442
}
443
- ret = mprotect(g2h(host_end - qemu_host_page_size), qemu_host_page_size,
444
- prot1 & PAGE_BITS);
445
+ ret = mprotect(g2h_untagged(host_end - qemu_host_page_size),
446
+ qemu_host_page_size, prot1 & PAGE_BITS);
447
if (ret != 0)
448
goto error;
449
host_end -= qemu_host_page_size;
450
@@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)
451
452
/* handle the pages in the middle */
453
if (host_start < host_end) {
454
- ret = mprotect(g2h(host_start), host_end - host_start, prot);
455
+ ret = mprotect(g2h_untagged(host_start), host_end - host_start, prot);
456
if (ret != 0)
457
goto error;
458
}
459
@@ -XXX,XX +XXX,XX @@ static int mmap_frag(abi_ulong real_start,
460
int prot1, prot_new;
461
462
real_end = real_start + qemu_host_page_size;
463
- host_start = g2h(real_start);
464
+ host_start = g2h_untagged(real_start);
465
466
/* get the protection of the target pages outside the mapping */
467
prot1 = 0;
468
@@ -XXX,XX +XXX,XX @@ static int mmap_frag(abi_ulong real_start,
469
mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE);
470
471
/* read the corresponding file data */
472
- pread(fd, g2h(start), end - start, offset);
473
+ pread(fd, g2h_untagged(start), end - start, offset);
474
475
/* put final protection */
476
if (prot_new != (prot1 | PROT_WRITE))
477
@@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
478
/* Note: we prefer to control the mapping address. It is
479
especially important if qemu_host_page_size >
480
qemu_real_host_page_size */
481
- p = mmap(g2h(mmap_start),
482
+ p = mmap(g2h_untagged(mmap_start),
483
host_len, prot, flags | MAP_FIXED, fd, host_offset);
484
if (p == MAP_FAILED)
485
goto fail;
486
@@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
487
-1, 0);
488
if (retaddr == -1)
489
goto fail;
490
- pread(fd, g2h(start), len, offset);
491
+ pread(fd, g2h_untagged(start), len, offset);
492
if (!(prot & PROT_WRITE)) {
493
ret = target_mprotect(start, len, prot);
494
if (ret != 0) {
495
@@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
496
offset1 = 0;
497
else
498
offset1 = offset + real_start - start;
499
- p = mmap(g2h(real_start), real_end - real_start,
500
+ p = mmap(g2h_untagged(real_start), real_end - real_start,
501
prot, flags, fd, offset1);
502
if (p == MAP_FAILED)
503
goto fail;
504
@@ -XXX,XX +XXX,XX @@ int target_munmap(abi_ulong start, abi_ulong len)
505
ret = 0;
506
/* unmap what we can */
507
if (real_start < real_end) {
508
- ret = munmap(g2h(real_start), real_end - real_start);
509
+ ret = munmap(g2h_untagged(real_start), real_end - real_start);
510
}
511
512
if (ret == 0)
513
@@ -XXX,XX +XXX,XX @@ int target_msync(abi_ulong start, abi_ulong len, int flags)
514
return 0;
515
516
start &= qemu_host_page_mask;
517
- return msync(g2h(start), end - start, flags);
518
+ return msync(g2h_untagged(start), end - start, flags);
519
}
10
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
520
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
11
index XXXXXXX..XXXXXXX 100644
521
index XXXXXXX..XXXXXXX 100644
12
--- a/linux-user/elfload.c
522
--- a/linux-user/elfload.c
13
+++ b/linux-user/elfload.c
523
+++ b/linux-user/elfload.c
14
@@ -XXX,XX +XXX,XX @@ enum {
524
@@ -XXX,XX +XXX,XX @@ enum {
15
ARM_HWCAP_A64_ASIMDDP = 1 << 20,
525
16
ARM_HWCAP_A64_SHA512 = 1 << 21,
526
static bool init_guest_commpage(void)
17
ARM_HWCAP_A64_SVE = 1 << 22,
527
{
18
+ ARM_HWCAP_A64_ASIMDFHM = 1 << 23,
528
- void *want = g2h(ARM_COMMPAGE & -qemu_host_page_size);
19
+ ARM_HWCAP_A64_DIT = 1 << 24,
529
+ void *want = g2h_untagged(ARM_COMMPAGE & -qemu_host_page_size);
20
+ ARM_HWCAP_A64_USCAT = 1 << 25,
530
void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE,
21
+ ARM_HWCAP_A64_ILRCPC = 1 << 26,
531
MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
22
+ ARM_HWCAP_A64_FLAGM = 1 << 27,
532
23
+ ARM_HWCAP_A64_SSBS = 1 << 28,
533
@@ -XXX,XX +XXX,XX @@ static bool init_guest_commpage(void)
24
+ ARM_HWCAP_A64_SB = 1 << 29,
534
}
25
+ ARM_HWCAP_A64_PACA = 1 << 30,
535
26
+ ARM_HWCAP_A64_PACG = 1UL << 31,
536
/* Set kernel helper versions; rest of page is 0. */
27
};
537
- __put_user(5, (uint32_t *)g2h(0xffff0ffcu));
28
538
+ __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu));
29
#define ELF_HWCAP get_elf_hwcap()
539
540
if (mprotect(addr, qemu_host_page_size, PROT_READ)) {
541
perror("Protecting guest commpage");
542
@@ -XXX,XX +XXX,XX @@ static void zero_bss(abi_ulong elf_bss, abi_ulong last_bss, int prot)
543
here is still actually needed. For now, continue with it,
544
but merge it with the "normal" mmap that would allocate the bss. */
545
546
- host_start = (uintptr_t) g2h(elf_bss);
547
- host_end = (uintptr_t) g2h(last_bss);
548
+ host_start = (uintptr_t) g2h_untagged(elf_bss);
549
+ host_end = (uintptr_t) g2h_untagged(last_bss);
550
host_map_start = REAL_HOST_PAGE_ALIGN(host_start);
551
552
if (host_map_start < host_end) {
553
@@ -XXX,XX +XXX,XX @@ static void pgb_have_guest_base(const char *image_name, abi_ulong guest_loaddr,
554
}
555
556
/* Reserve the address space for the binary, or reserved_va. */
557
- test = g2h(guest_loaddr);
558
+ test = g2h_untagged(guest_loaddr);
559
addr = mmap(test, guest_hiaddr - guest_loaddr, PROT_NONE, flags, -1, 0);
560
if (test != addr) {
561
pgb_fail_in_use(image_name);
562
@@ -XXX,XX +XXX,XX @@ static void pgb_reserved_va(const char *image_name, abi_ulong guest_loaddr,
563
564
/* Reserve the memory on the host. */
565
assert(guest_base != 0);
566
- test = g2h(0);
567
+ test = g2h_untagged(0);
568
addr = mmap(test, reserved_va, PROT_NONE, flags, -1, 0);
569
if (addr == MAP_FAILED || addr != test) {
570
error_report("Unable to reserve 0x%lx bytes of virtual address "
571
diff --git a/linux-user/flatload.c b/linux-user/flatload.c
572
index XXXXXXX..XXXXXXX 100644
573
--- a/linux-user/flatload.c
574
+++ b/linux-user/flatload.c
575
@@ -XXX,XX +XXX,XX @@ static int load_flat_file(struct linux_binprm * bprm,
576
}
577
578
/* zero the BSS. */
579
- memset(g2h(datapos + data_len), 0, bss_len);
580
+ memset(g2h_untagged(datapos + data_len), 0, bss_len);
581
582
return 0;
583
}
584
diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c
585
index XXXXXXX..XXXXXXX 100644
586
--- a/linux-user/hppa/cpu_loop.c
587
+++ b/linux-user/hppa/cpu_loop.c
588
@@ -XXX,XX +XXX,XX @@
589
590
static abi_ulong hppa_lws(CPUHPPAState *env)
591
{
592
+ CPUState *cs = env_cpu(env);
593
uint32_t which = env->gr[20];
594
abi_ulong addr = env->gr[26];
595
abi_ulong old = env->gr[25];
596
@@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env)
597
}
598
old = tswap32(old);
599
new = tswap32(new);
600
- ret = qatomic_cmpxchg((uint32_t *)g2h(addr), old, new);
601
+ ret = qatomic_cmpxchg((uint32_t *)g2h(cs, addr), old, new);
602
ret = tswap32(ret);
603
break;
604
605
@@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env)
606
can be host-endian as well. */
607
switch (size) {
608
case 0:
609
- old = *(uint8_t *)g2h(old);
610
- new = *(uint8_t *)g2h(new);
611
- ret = qatomic_cmpxchg((uint8_t *)g2h(addr), old, new);
612
+ old = *(uint8_t *)g2h(cs, old);
613
+ new = *(uint8_t *)g2h(cs, new);
614
+ ret = qatomic_cmpxchg((uint8_t *)g2h(cs, addr), old, new);
615
ret = ret != old;
616
break;
617
case 1:
618
- old = *(uint16_t *)g2h(old);
619
- new = *(uint16_t *)g2h(new);
620
- ret = qatomic_cmpxchg((uint16_t *)g2h(addr), old, new);
621
+ old = *(uint16_t *)g2h(cs, old);
622
+ new = *(uint16_t *)g2h(cs, new);
623
+ ret = qatomic_cmpxchg((uint16_t *)g2h(cs, addr), old, new);
624
ret = ret != old;
625
break;
626
case 2:
627
- old = *(uint32_t *)g2h(old);
628
- new = *(uint32_t *)g2h(new);
629
- ret = qatomic_cmpxchg((uint32_t *)g2h(addr), old, new);
630
+ old = *(uint32_t *)g2h(cs, old);
631
+ new = *(uint32_t *)g2h(cs, new);
632
+ ret = qatomic_cmpxchg((uint32_t *)g2h(cs, addr), old, new);
633
ret = ret != old;
634
break;
635
case 3:
636
{
637
uint64_t o64, n64, r64;
638
- o64 = *(uint64_t *)g2h(old);
639
- n64 = *(uint64_t *)g2h(new);
640
+ o64 = *(uint64_t *)g2h(cs, old);
641
+ n64 = *(uint64_t *)g2h(cs, new);
642
#ifdef CONFIG_ATOMIC64
643
- r64 = qatomic_cmpxchg__nocheck((uint64_t *)g2h(addr),
644
+ r64 = qatomic_cmpxchg__nocheck((uint64_t *)g2h(cs, addr),
645
o64, n64);
646
ret = r64 != o64;
647
#else
648
start_exclusive();
649
- r64 = *(uint64_t *)g2h(addr);
650
+ r64 = *(uint64_t *)g2h(cs, addr);
651
ret = 1;
652
if (r64 == o64) {
653
- *(uint64_t *)g2h(addr) = n64;
654
+ *(uint64_t *)g2h(cs, addr) = n64;
655
ret = 0;
656
}
657
end_exclusive();
658
diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
659
index XXXXXXX..XXXXXXX 100644
660
--- a/linux-user/i386/cpu_loop.c
661
+++ b/linux-user/i386/cpu_loop.c
662
@@ -XXX,XX +XXX,XX @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
663
env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1),
664
PROT_READ|PROT_WRITE,
665
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
666
- idt_table = g2h(env->idt.base);
667
+ idt_table = g2h_untagged(env->idt.base);
668
set_idt(0, 0);
669
set_idt(1, 0);
670
set_idt(2, 0);
671
@@ -XXX,XX +XXX,XX @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
672
PROT_READ|PROT_WRITE,
673
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
674
env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1;
675
- gdt_table = g2h(env->gdt.base);
676
+ gdt_table = g2h_untagged(env->gdt.base);
677
#ifdef TARGET_ABI32
678
write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff,
679
DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK |
680
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
681
index XXXXXXX..XXXXXXX 100644
682
--- a/linux-user/mmap.c
683
+++ b/linux-user/mmap.c
684
@@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot)
685
}
686
end = host_end;
687
}
688
- ret = mprotect(g2h(host_start), qemu_host_page_size,
689
+ ret = mprotect(g2h_untagged(host_start), qemu_host_page_size,
690
prot1 & PAGE_BITS);
691
if (ret != 0) {
692
goto error;
693
@@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot)
694
for (addr = end; addr < host_end; addr += TARGET_PAGE_SIZE) {
695
prot1 |= page_get_flags(addr);
696
}
697
- ret = mprotect(g2h(host_end - qemu_host_page_size),
698
+ ret = mprotect(g2h_untagged(host_end - qemu_host_page_size),
699
qemu_host_page_size, prot1 & PAGE_BITS);
700
if (ret != 0) {
701
goto error;
702
@@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot)
703
704
/* handle the pages in the middle */
705
if (host_start < host_end) {
706
- ret = mprotect(g2h(host_start), host_end - host_start, host_prot);
707
+ ret = mprotect(g2h_untagged(host_start),
708
+ host_end - host_start, host_prot);
709
if (ret != 0) {
710
goto error;
711
}
712
@@ -XXX,XX +XXX,XX @@ static int mmap_frag(abi_ulong real_start,
713
int prot1, prot_new;
714
715
real_end = real_start + qemu_host_page_size;
716
- host_start = g2h(real_start);
717
+ host_start = g2h_untagged(real_start);
718
719
/* get the protection of the target pages outside the mapping */
720
prot1 = 0;
721
@@ -XXX,XX +XXX,XX @@ static int mmap_frag(abi_ulong real_start,
722
mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE);
723
724
/* read the corresponding file data */
725
- if (pread(fd, g2h(start), end - start, offset) == -1)
726
+ if (pread(fd, g2h_untagged(start), end - start, offset) == -1)
727
return -1;
728
729
/* put final protection */
730
@@ -XXX,XX +XXX,XX @@ static int mmap_frag(abi_ulong real_start,
731
mprotect(host_start, qemu_host_page_size, prot_new);
732
}
733
if (prot_new & PROT_WRITE) {
734
- memset(g2h(start), 0, end - start);
735
+ memset(g2h_untagged(start), 0, end - start);
736
}
737
}
738
return 0;
739
@@ -XXX,XX +XXX,XX @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align)
740
* - mremap() with MREMAP_FIXED flag
741
* - shmat() with SHM_REMAP flag
742
*/
743
- ptr = mmap(g2h(addr), size, PROT_NONE,
744
+ ptr = mmap(g2h_untagged(addr), size, PROT_NONE,
745
MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
746
747
/* ENOMEM, if host address space has no memory */
748
@@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
749
/* Note: we prefer to control the mapping address. It is
750
especially important if qemu_host_page_size >
751
qemu_real_host_page_size */
752
- p = mmap(g2h(start), host_len, host_prot,
753
+ p = mmap(g2h_untagged(start), host_len, host_prot,
754
flags | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
755
if (p == MAP_FAILED) {
756
goto fail;
757
@@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
758
/* update start so that it points to the file position at 'offset' */
759
host_start = (unsigned long)p;
760
if (!(flags & MAP_ANONYMOUS)) {
761
- p = mmap(g2h(start), len, host_prot,
762
+ p = mmap(g2h_untagged(start), len, host_prot,
763
flags | MAP_FIXED, fd, host_offset);
764
if (p == MAP_FAILED) {
765
- munmap(g2h(start), host_len);
766
+ munmap(g2h_untagged(start), host_len);
767
goto fail;
768
}
769
host_start += offset - host_offset;
770
@@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
771
-1, 0);
772
if (retaddr == -1)
773
goto fail;
774
- if (pread(fd, g2h(start), len, offset) == -1)
775
+ if (pread(fd, g2h_untagged(start), len, offset) == -1)
776
goto fail;
777
if (!(host_prot & PROT_WRITE)) {
778
ret = target_mprotect(start, len, target_prot);
779
@@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
780
offset1 = 0;
781
else
782
offset1 = offset + real_start - start;
783
- p = mmap(g2h(real_start), real_end - real_start,
784
+ p = mmap(g2h_untagged(real_start), real_end - real_start,
785
host_prot, flags, fd, offset1);
786
if (p == MAP_FAILED)
787
goto fail;
788
@@ -XXX,XX +XXX,XX @@ static void mmap_reserve(abi_ulong start, abi_ulong size)
789
real_end -= qemu_host_page_size;
790
}
791
if (real_start != real_end) {
792
- mmap(g2h(real_start), real_end - real_start, PROT_NONE,
793
+ mmap(g2h_untagged(real_start), real_end - real_start, PROT_NONE,
794
MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE,
795
-1, 0);
796
}
797
@@ -XXX,XX +XXX,XX @@ int target_munmap(abi_ulong start, abi_ulong len)
798
if (reserved_va) {
799
mmap_reserve(real_start, real_end - real_start);
800
} else {
801
- ret = munmap(g2h(real_start), real_end - real_start);
802
+ ret = munmap(g2h_untagged(real_start), real_end - real_start);
803
}
804
}
805
806
@@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
807
mmap_lock();
808
809
if (flags & MREMAP_FIXED) {
810
- host_addr = mremap(g2h(old_addr), old_size, new_size,
811
- flags, g2h(new_addr));
812
+ host_addr = mremap(g2h_untagged(old_addr), old_size, new_size,
813
+ flags, g2h_untagged(new_addr));
814
815
if (reserved_va && host_addr != MAP_FAILED) {
816
/* If new and old addresses overlap then the above mremap will
817
@@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
818
errno = ENOMEM;
819
host_addr = MAP_FAILED;
820
} else {
821
- host_addr = mremap(g2h(old_addr), old_size, new_size,
822
- flags | MREMAP_FIXED, g2h(mmap_start));
823
+ host_addr = mremap(g2h_untagged(old_addr), old_size, new_size,
824
+ flags | MREMAP_FIXED,
825
+ g2h_untagged(mmap_start));
826
if (reserved_va) {
827
mmap_reserve(old_addr, old_size);
828
}
829
@@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
830
}
831
}
832
if (prot == 0) {
833
- host_addr = mremap(g2h(old_addr), old_size, new_size, flags);
834
+ host_addr = mremap(g2h_untagged(old_addr),
835
+ old_size, new_size, flags);
836
837
if (host_addr != MAP_FAILED) {
838
/* Check if address fits target address space */
839
if (!guest_range_valid(h2g(host_addr), new_size)) {
840
/* Revert mremap() changes */
841
- host_addr = mremap(g2h(old_addr), new_size, old_size,
842
- flags);
843
+ host_addr = mremap(g2h_untagged(old_addr),
844
+ new_size, old_size, flags);
845
errno = ENOMEM;
846
host_addr = MAP_FAILED;
847
} else if (reserved_va && old_size > new_size) {
848
diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c
849
index XXXXXXX..XXXXXXX 100644
850
--- a/linux-user/ppc/signal.c
851
+++ b/linux-user/ppc/signal.c
852
@@ -XXX,XX +XXX,XX @@ static void restore_user_regs(CPUPPCState *env,
853
uint64_t v_addr;
854
/* 64-bit needs to recover the pointer to the vectors from the frame */
855
__get_user(v_addr, &frame->v_regs);
856
- v_regs = g2h(v_addr);
857
+ v_regs = g2h(env_cpu(env), v_addr);
858
#else
859
v_regs = (ppc_avr_t *)frame->mc_vregs.altivec;
860
#endif
861
@@ -XXX,XX +XXX,XX @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
862
if (get_ppc64_abi(image) < 2) {
863
/* ELFv1 PPC64 function pointers are pointers to OPD entries. */
864
struct target_func_ptr *handler =
865
- (struct target_func_ptr *)g2h(ka->_sa_handler);
866
+ (struct target_func_ptr *)g2h(env_cpu(env), ka->_sa_handler);
867
env->nip = tswapl(handler->entry);
868
env->gpr[2] = tswapl(handler->toc);
869
} else {
870
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
871
index XXXXXXX..XXXXXXX 100644
872
--- a/linux-user/syscall.c
873
+++ b/linux-user/syscall.c
874
@@ -XXX,XX +XXX,XX @@ abi_long do_brk(abi_ulong new_brk)
875
/* Heap contents are initialized to zero, as for anonymous
876
* mapped pages. */
877
if (new_brk > target_brk) {
878
- memset(g2h(target_brk), 0, new_brk - target_brk);
879
+ memset(g2h_untagged(target_brk), 0, new_brk - target_brk);
880
}
881
    target_brk = new_brk;
882
DEBUGF_BRK(TARGET_ABI_FMT_lx " (new_brk <= brk_page)\n", target_brk);
883
@@ -XXX,XX +XXX,XX @@ abi_long do_brk(abi_ulong new_brk)
884
* come from the remaining part of the previous page: it may
885
* contains garbage data due to a previous heap usage (grown
886
* then shrunken). */
887
- memset(g2h(target_brk), 0, brk_page - target_brk);
888
+ memset(g2h_untagged(target_brk), 0, brk_page - target_brk);
889
890
target_brk = new_brk;
891
brk_page = HOST_PAGE_ALIGN(target_brk);
892
@@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,
893
mmap_lock();
894
895
if (shmaddr)
896
- host_raddr = shmat(shmid, (void *)g2h(shmaddr), shmflg);
897
+ host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr), shmflg);
898
else {
899
abi_ulong mmap_start;
900
901
@@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,
902
errno = ENOMEM;
903
host_raddr = (void *)-1;
904
} else
905
- host_raddr = shmat(shmid, g2h(mmap_start), shmflg | SHM_REMAP);
906
+ host_raddr = shmat(shmid, g2h_untagged(mmap_start),
907
+ shmflg | SHM_REMAP);
908
}
909
910
if (host_raddr == (void *)-1) {
911
@@ -XXX,XX +XXX,XX @@ static inline abi_long do_shmdt(abi_ulong shmaddr)
912
break;
913
}
914
}
915
- rv = get_errno(shmdt(g2h(shmaddr)));
916
+ rv = get_errno(shmdt(g2h_untagged(shmaddr)));
917
918
mmap_unlock();
919
920
@@ -XXX,XX +XXX,XX @@ static abi_long write_ldt(CPUX86State *env,
921
MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
922
if (env->ldt.base == -1)
923
return -TARGET_ENOMEM;
924
- memset(g2h(env->ldt.base), 0,
925
+ memset(g2h_untagged(env->ldt.base), 0,
926
TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZE);
927
env->ldt.limit = 0xffff;
928
- ldt_table = g2h(env->ldt.base);
929
+ ldt_table = g2h_untagged(env->ldt.base);
930
}
931
932
/* NOTE: same code as Linux kernel */
933
@@ -XXX,XX +XXX,XX @@ static abi_long do_modify_ldt(CPUX86State *env, int func, abi_ulong ptr,
934
#if defined(TARGET_ABI32)
935
abi_long do_set_thread_area(CPUX86State *env, abi_ulong ptr)
936
{
937
- uint64_t *gdt_table = g2h(env->gdt.base);
938
+ uint64_t *gdt_table = g2h_untagged(env->gdt.base);
939
struct target_modify_ldt_ldt_s ldt_info;
940
struct target_modify_ldt_ldt_s *target_ldt_info;
941
int seg_32bit, contents, read_exec_only, limit_in_pages;
942
@@ -XXX,XX +XXX,XX @@ install:
943
static abi_long do_get_thread_area(CPUX86State *env, abi_ulong ptr)
944
{
945
struct target_modify_ldt_ldt_s *target_ldt_info;
946
- uint64_t *gdt_table = g2h(env->gdt.base);
947
+ uint64_t *gdt_table = g2h_untagged(env->gdt.base);
948
uint32_t base_addr, limit, flags;
949
int seg_32bit, contents, read_exec_only, limit_in_pages, idx;
950
int seg_not_present, useable, lm;
951
@@ -XXX,XX +XXX,XX @@ static int do_safe_futex(int *uaddr, int op, int val,
952
tricky. However they're probably useless because guest atomic
953
operations won't work either. */
954
#if defined(TARGET_NR_futex)
955
-static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout,
956
- target_ulong uaddr2, int val3)
957
+static int do_futex(CPUState *cpu, target_ulong uaddr, int op, int val,
958
+ target_ulong timeout, target_ulong uaddr2, int val3)
959
{
960
struct timespec ts, *pts;
961
int base_op;
962
@@ -XXX,XX +XXX,XX @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout,
963
} else {
964
pts = NULL;
965
}
966
- return do_safe_futex(g2h(uaddr), op, tswap32(val), pts, NULL, val3);
967
+ return do_safe_futex(g2h(cpu, uaddr),
968
+ op, tswap32(val), pts, NULL, val3);
969
case FUTEX_WAKE:
970
- return do_safe_futex(g2h(uaddr), op, val, NULL, NULL, 0);
971
+ return do_safe_futex(g2h(cpu, uaddr),
972
+ op, val, NULL, NULL, 0);
973
case FUTEX_FD:
974
- return do_safe_futex(g2h(uaddr), op, val, NULL, NULL, 0);
975
+ return do_safe_futex(g2h(cpu, uaddr),
976
+ op, val, NULL, NULL, 0);
977
case FUTEX_REQUEUE:
978
case FUTEX_CMP_REQUEUE:
979
case FUTEX_WAKE_OP:
980
@@ -XXX,XX +XXX,XX @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout,
981
to satisfy the compiler. We do not need to tswap TIMEOUT
982
since it's not compared to guest memory. */
983
pts = (struct timespec *)(uintptr_t) timeout;
984
- return do_safe_futex(g2h(uaddr), op, val, pts, g2h(uaddr2),
985
+ return do_safe_futex(g2h(cpu, uaddr), op, val, pts, g2h(cpu, uaddr2),
986
(base_op == FUTEX_CMP_REQUEUE
987
- ? tswap32(val3)
988
- : val3));
989
+ ? tswap32(val3) : val3));
990
default:
991
return -TARGET_ENOSYS;
992
}
993
@@ -XXX,XX +XXX,XX @@ static int do_futex(target_ulong uaddr, int op, int val, target_ulong timeout,
994
#endif
995
996
#if defined(TARGET_NR_futex_time64)
997
-static int do_futex_time64(target_ulong uaddr, int op, int val, target_ulong timeout,
998
+static int do_futex_time64(CPUState *cpu, target_ulong uaddr, int op,
999
+ int val, target_ulong timeout,
1000
target_ulong uaddr2, int val3)
1001
{
1002
struct timespec ts, *pts;
1003
@@ -XXX,XX +XXX,XX @@ static int do_futex_time64(target_ulong uaddr, int op, int val, target_ulong tim
1004
} else {
1005
pts = NULL;
1006
}
1007
- return do_safe_futex(g2h(uaddr), op, tswap32(val), pts, NULL, val3);
1008
+ return do_safe_futex(g2h(cpu, uaddr), op,
1009
+ tswap32(val), pts, NULL, val3);
1010
case FUTEX_WAKE:
1011
- return do_safe_futex(g2h(uaddr), op, val, NULL, NULL, 0);
1012
+ return do_safe_futex(g2h(cpu, uaddr), op, val, NULL, NULL, 0);
1013
case FUTEX_FD:
1014
- return do_safe_futex(g2h(uaddr), op, val, NULL, NULL, 0);
1015
+ return do_safe_futex(g2h(cpu, uaddr), op, val, NULL, NULL, 0);
1016
case FUTEX_REQUEUE:
1017
case FUTEX_CMP_REQUEUE:
1018
case FUTEX_WAKE_OP:
1019
@@ -XXX,XX +XXX,XX @@ static int do_futex_time64(target_ulong uaddr, int op, int val, target_ulong tim
1020
to satisfy the compiler. We do not need to tswap TIMEOUT
1021
since it's not compared to guest memory. */
1022
pts = (struct timespec *)(uintptr_t) timeout;
1023
- return do_safe_futex(g2h(uaddr), op, val, pts, g2h(uaddr2),
1024
+ return do_safe_futex(g2h(cpu, uaddr), op, val, pts, g2h(cpu, uaddr2),
1025
(base_op == FUTEX_CMP_REQUEUE
1026
- ? tswap32(val3)
1027
- : val3));
1028
+ ? tswap32(val3) : val3));
1029
default:
1030
return -TARGET_ENOSYS;
1031
}
1032
@@ -XXX,XX +XXX,XX @@ static int open_self_maps(void *cpu_env, int fd)
1033
const char *path;
1034
1035
max = h2g_valid(max - 1) ?
1036
- max : (uintptr_t) g2h(GUEST_ADDR_MAX) + 1;
1037
+ max : (uintptr_t) g2h_untagged(GUEST_ADDR_MAX) + 1;
1038
1039
if (page_check_range(h2g(min), max - min, flags) == -1) {
1040
continue;
1041
@@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
1042
1043
if (ts->child_tidptr) {
1044
put_user_u32(0, ts->child_tidptr);
1045
- do_sys_futex(g2h(ts->child_tidptr), FUTEX_WAKE, INT_MAX,
1046
- NULL, NULL, 0);
1047
+ do_sys_futex(g2h(cpu, ts->child_tidptr),
1048
+ FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
1049
}
1050
thread_cpu = NULL;
1051
g_free(ts);
1052
@@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
1053
if (!arg5) {
1054
ret = mount(p, p2, p3, (unsigned long)arg4, NULL);
1055
} else {
1056
- ret = mount(p, p2, p3, (unsigned long)arg4, g2h(arg5));
1057
+ ret = mount(p, p2, p3, (unsigned long)arg4, g2h(cpu, arg5));
1058
}
1059
ret = get_errno(ret);
1060
1061
@@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
1062
/* ??? msync/mlock/munlock are broken for softmmu. */
1063
#ifdef TARGET_NR_msync
1064
case TARGET_NR_msync:
1065
- return get_errno(msync(g2h(arg1), arg2, arg3));
1066
+ return get_errno(msync(g2h(cpu, arg1), arg2, arg3));
1067
#endif
1068
#ifdef TARGET_NR_mlock
1069
case TARGET_NR_mlock:
1070
- return get_errno(mlock(g2h(arg1), arg2));
1071
+ return get_errno(mlock(g2h(cpu, arg1), arg2));
1072
#endif
1073
#ifdef TARGET_NR_munlock
1074
case TARGET_NR_munlock:
1075
- return get_errno(munlock(g2h(arg1), arg2));
1076
+ return get_errno(munlock(g2h(cpu, arg1), arg2));
1077
#endif
1078
#ifdef TARGET_NR_mlockall
1079
case TARGET_NR_mlockall:
1080
@@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
1081
1082
#if defined(TARGET_NR_set_tid_address) && defined(__NR_set_tid_address)
1083
case TARGET_NR_set_tid_address:
1084
- return get_errno(set_tid_address((int *)g2h(arg1)));
1085
+ return get_errno(set_tid_address((int *)g2h(cpu, arg1)));
1086
#endif
1087
1088
case TARGET_NR_tkill:
1089
@@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
1090
#endif
1091
#ifdef TARGET_NR_futex
1092
case TARGET_NR_futex:
1093
- return do_futex(arg1, arg2, arg3, arg4, arg5, arg6);
1094
+ return do_futex(cpu, arg1, arg2, arg3, arg4, arg5, arg6);
1095
#endif
1096
#ifdef TARGET_NR_futex_time64
1097
case TARGET_NR_futex_time64:
1098
- return do_futex_time64(arg1, arg2, arg3, arg4, arg5, arg6);
1099
+ return do_futex_time64(cpu, arg1, arg2, arg3, arg4, arg5, arg6);
1100
#endif
1101
#if defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)
1102
case TARGET_NR_inotify_init:
1103
diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c
1104
index XXXXXXX..XXXXXXX 100644
1105
--- a/target/arm/helper-a64.c
1106
+++ b/target/arm/helper-a64.c
1107
@@ -XXX,XX +XXX,XX @@ uint64_t HELPER(paired_cmpxchg64_le)(CPUARMState *env, uint64_t addr,
1108
1109
#ifdef CONFIG_USER_ONLY
1110
/* ??? Enforce alignment. */
1111
- uint64_t *haddr = g2h(addr);
1112
+ uint64_t *haddr = g2h(env_cpu(env), addr);
1113
1114
set_helper_retaddr(ra);
1115
o0 = ldq_le_p(haddr + 0);
1116
@@ -XXX,XX +XXX,XX @@ uint64_t HELPER(paired_cmpxchg64_be)(CPUARMState *env, uint64_t addr,
1117
1118
#ifdef CONFIG_USER_ONLY
1119
/* ??? Enforce alignment. */
1120
- uint64_t *haddr = g2h(addr);
1121
+ uint64_t *haddr = g2h(env_cpu(env), addr);
1122
1123
set_helper_retaddr(ra);
1124
o1 = ldq_be_p(haddr + 0);
1125
diff --git a/target/hppa/op_helper.c b/target/hppa/op_helper.c
1126
index XXXXXXX..XXXXXXX 100644
1127
--- a/target/hppa/op_helper.c
1128
+++ b/target/hppa/op_helper.c
1129
@@ -XXX,XX +XXX,XX @@ static void atomic_store_3(CPUHPPAState *env, target_ulong addr, uint32_t val,
1130
#ifdef CONFIG_USER_ONLY
1131
uint32_t old, new, cmp;
1132
1133
- uint32_t *haddr = g2h(addr - 1);
1134
+ uint32_t *haddr = g2h(env_cpu(env), addr - 1);
1135
old = *haddr;
1136
while (1) {
1137
new = (old & ~mask) | (val & mask);
1138
diff --git a/target/i386/tcg/mem_helper.c b/target/i386/tcg/mem_helper.c
1139
index XXXXXXX..XXXXXXX 100644
1140
--- a/target/i386/tcg/mem_helper.c
1141
+++ b/target/i386/tcg/mem_helper.c
1142
@@ -XXX,XX +XXX,XX @@ void helper_cmpxchg8b(CPUX86State *env, target_ulong a0)
1143
1144
#ifdef CONFIG_USER_ONLY
1145
{
1146
- uint64_t *haddr = g2h(a0);
1147
+ uint64_t *haddr = g2h(env_cpu(env), a0);
1148
cmpv = cpu_to_le64(cmpv);
1149
newv = cpu_to_le64(newv);
1150
oldv = qatomic_cmpxchg__nocheck(haddr, cmpv, newv);
1151
diff --git a/target/s390x/mem_helper.c b/target/s390x/mem_helper.c
1152
index XXXXXXX..XXXXXXX 100644
1153
--- a/target/s390x/mem_helper.c
1154
+++ b/target/s390x/mem_helper.c
1155
@@ -XXX,XX +XXX,XX @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,
1156
1157
if (parallel) {
1158
#ifdef CONFIG_USER_ONLY
1159
- uint32_t *haddr = g2h(a1);
1160
+ uint32_t *haddr = g2h(env_cpu(env), a1);
1161
ov = qatomic_cmpxchg__nocheck(haddr, cv, nv);
1162
#else
1163
TCGMemOpIdx oi = make_memop_idx(MO_TEUL | MO_ALIGN, mem_idx);
1164
@@ -XXX,XX +XXX,XX @@ static uint32_t do_csst(CPUS390XState *env, uint32_t r3, uint64_t a1,
1165
if (parallel) {
1166
#ifdef CONFIG_ATOMIC64
1167
# ifdef CONFIG_USER_ONLY
1168
- uint64_t *haddr = g2h(a1);
1169
+ uint64_t *haddr = g2h(env_cpu(env), a1);
1170
ov = qatomic_cmpxchg__nocheck(haddr, cv, nv);
1171
# else
1172
TCGMemOpIdx oi = make_memop_idx(MO_TEQ | MO_ALIGN, mem_idx);
30
--
1173
--
31
2.20.1
1174
2.20.1
32
1175
33
1176
diff view generated by jsdifflib
1
In the "add/subtract (extended register)" encoding group, the "opt"
1
From: Richard Henderson <richard.henderson@linaro.org>
2
field in bits [23:22] must be zero. Correctly UNDEF the unallocated
3
encodings where this field is not zero.
4
2
5
Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com>
3
We define target_mmap et al as untagged, so that they can be
4
used from the binary loaders. Explicitly call cpu_untagged_addr
5
for munmap, mprotect, mremap syscall entry points.
6
7
Add a few comments for the syscalls that are exempted by the
8
kernel's tagged-address-abi.rst.
9
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20210212184902.1251044-14-richard.henderson@linaro.org
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com>
8
Message-id: 20190125182626.9221-6-peter.maydell@linaro.org
9
---
14
---
10
target/arm/translate-a64.c | 3 ++-
15
linux-user/syscall.c | 11 +++++++++++
11
1 file changed, 2 insertions(+), 1 deletion(-)
16
1 file changed, 11 insertions(+)
12
17
13
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
18
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
14
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/translate-a64.c
20
--- a/linux-user/syscall.c
16
+++ b/target/arm/translate-a64.c
21
+++ b/linux-user/syscall.c
17
@@ -XXX,XX +XXX,XX @@ static void disas_add_sub_ext_reg(DisasContext *s, uint32_t insn)
22
@@ -XXX,XX +XXX,XX @@ abi_long do_brk(abi_ulong new_brk)
18
int imm3 = extract32(insn, 10, 3);
23
abi_long mapped_addr;
19
int option = extract32(insn, 13, 3);
24
abi_ulong new_alloc_size;
20
int rm = extract32(insn, 16, 5);
25
21
+ int opt = extract32(insn, 22, 2);
26
+ /* brk pointers are always untagged */
22
bool setflags = extract32(insn, 29, 1);
27
+
23
bool sub_op = extract32(insn, 30, 1);
28
DEBUGF_BRK("do_brk(" TARGET_ABI_FMT_lx ") -> ", new_brk);
24
bool sf = extract32(insn, 31, 1);
29
25
@@ -XXX,XX +XXX,XX @@ static void disas_add_sub_ext_reg(DisasContext *s, uint32_t insn)
30
if (!new_brk) {
26
TCGv_i64 tcg_rd;
31
@@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,
27
TCGv_i64 tcg_result;
32
int i,ret;
28
33
abi_ulong shmlba;
29
- if (imm3 > 4) {
34
30
+ if (imm3 > 4 || opt != 0) {
35
+ /* shmat pointers are always untagged */
31
unallocated_encoding(s);
36
+
32
return;
37
/* find out the length of the shared memory segment */
33
}
38
ret = get_errno(shmctl(shmid, IPC_STAT, &shm_info));
39
if (is_error(ret)) {
40
@@ -XXX,XX +XXX,XX @@ static inline abi_long do_shmdt(abi_ulong shmaddr)
41
int i;
42
abi_long rv;
43
44
+ /* shmdt pointers are always untagged */
45
+
46
mmap_lock();
47
48
for (i = 0; i < N_SHM_REGIONS; ++i) {
49
@@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
50
v5, v6));
51
}
52
#else
53
+ /* mmap pointers are always untagged */
54
ret = get_errno(target_mmap(arg1, arg2, arg3,
55
target_to_host_bitmask(arg4, mmap_flags_tbl),
56
arg5,
57
@@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
58
return get_errno(ret);
59
#endif
60
case TARGET_NR_munmap:
61
+ arg1 = cpu_untagged_addr(cpu, arg1);
62
return get_errno(target_munmap(arg1, arg2));
63
case TARGET_NR_mprotect:
64
+ arg1 = cpu_untagged_addr(cpu, arg1);
65
{
66
TaskState *ts = cpu->opaque;
67
/* Special hack to detect libc making the stack executable. */
68
@@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
69
return get_errno(target_mprotect(arg1, arg2, arg3));
70
#ifdef TARGET_NR_mremap
71
case TARGET_NR_mremap:
72
+ arg1 = cpu_untagged_addr(cpu, arg1);
73
+ /* mremap new_addr (arg5) is always untagged */
74
return get_errno(target_mremap(arg1, arg2, arg3, arg4, arg5));
75
#endif
76
/* ??? msync/mlock/munlock are broken for softmmu. */
34
--
77
--
35
2.20.1
78
2.20.1
36
79
37
80
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
These bits become writable with the ARMv8.3-PAuth extension.
3
We're currently open-coding the range check in access_ok;
4
use guest_range_valid when size != 0.
4
5
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20190129143511.12311-1-richard.henderson@linaro.org
8
Message-id: 20210212184902.1251044-15-richard.henderson@linaro.org
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
10
---
10
target/arm/helper.c | 6 ++++++
11
linux-user/qemu.h | 9 +++------
11
1 file changed, 6 insertions(+)
12
1 file changed, 3 insertions(+), 6 deletions(-)
12
13
13
diff --git a/target/arm/helper.c b/target/arm/helper.c
14
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
14
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/helper.c
16
--- a/linux-user/qemu.h
16
+++ b/target/arm/helper.c
17
+++ b/linux-user/qemu.h
17
@@ -XXX,XX +XXX,XX @@ static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
18
@@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size;
18
if (cpu_isar_feature(aa64_lor, cpu)) {
19
19
valid_mask |= SCR_TLOR;
20
static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
21
{
22
- if (!guest_addr_valid(addr)) {
23
- return false;
24
- }
25
- if (size != 0 &&
26
- (addr + size - 1 < addr ||
27
- !guest_addr_valid(addr + size - 1))) {
28
+ if (size == 0
29
+ ? !guest_addr_valid(addr)
30
+ : !guest_range_valid(addr, size)) {
31
return false;
20
}
32
}
21
+ if (cpu_isar_feature(aa64_pauth, cpu)) {
33
return page_check_range((target_ulong)addr, size, type) == 0;
22
+ valid_mask |= SCR_API | SCR_APK;
23
+ }
24
25
/* Clear all-context RES0 bits. */
26
value &= valid_mask;
27
@@ -XXX,XX +XXX,XX @@ static void hcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
28
if (cpu_isar_feature(aa64_lor, cpu)) {
29
valid_mask |= HCR_TLOR;
30
}
31
+ if (cpu_isar_feature(aa64_pauth, cpu)) {
32
+ valid_mask |= HCR_API | HCR_APK;
33
+ }
34
35
/* Clear RES0 bits. */
36
value &= valid_mask;
37
--
34
--
38
2.20.1
35
2.20.1
39
36
40
37
diff view generated by jsdifflib
1
Expose "start-powered-off" as a property of the ARMv7M container,
1
From: Richard Henderson <richard.henderson@linaro.org>
2
which we just pass through to the CPU object in the same way that we
3
do for "init-svtor" and "idau". (We want this for the SSE-200, which
4
powers up only the first CPU at reset and leaves the second powered
5
down.)
6
2
7
As with the other CPU properties here, we can't just use alias
3
The places that use these are better off using untagged
8
properties, because the CPU QOM object is not created until armv7m
4
addresses, so do not provide a tagged versions. Rename
9
realize time.
5
to make it clear about the address type.
10
6
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20210212184902.1251044-16-richard.henderson@linaro.org
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Message-id: 20190121185118.18550-4-peter.maydell@linaro.org
14
---
11
---
15
include/hw/arm/armv7m.h | 1 +
12
include/exec/cpu_ldst.h | 4 ++--
16
hw/arm/armv7m.c | 10 ++++++++++
13
linux-user/qemu.h | 4 ++--
17
2 files changed, 11 insertions(+)
14
accel/tcg/user-exec.c | 3 ++-
15
linux-user/mmap.c | 14 +++++++-------
16
linux-user/syscall.c | 2 +-
17
5 files changed, 14 insertions(+), 13 deletions(-)
18
18
19
diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h
19
diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h
20
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/arm/armv7m.h
21
--- a/include/exec/cpu_ldst.h
22
+++ b/include/hw/arm/armv7m.h
22
+++ b/include/exec/cpu_ldst.h
23
@@ -XXX,XX +XXX,XX @@ typedef struct ARMv7MState {
23
@@ -XXX,XX +XXX,XX @@ static inline void *g2h(CPUState *cs, abi_ptr x)
24
Object *idau;
24
return g2h_untagged(cpu_untagged_addr(cs, x));
25
uint32_t init_svtor;
25
}
26
bool enable_bitband;
26
27
+ bool start_powered_off;
27
-static inline bool guest_addr_valid(abi_ulong x)
28
} ARMv7MState;
28
+static inline bool guest_addr_valid_untagged(abi_ulong x)
29
29
{
30
#endif
30
return x <= GUEST_ADDR_MAX;
31
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
31
}
32
33
-static inline bool guest_range_valid(abi_ulong start, abi_ulong len)
34
+static inline bool guest_range_valid_untagged(abi_ulong start, abi_ulong len)
35
{
36
return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1;
37
}
38
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
32
index XXXXXXX..XXXXXXX 100644
39
index XXXXXXX..XXXXXXX 100644
33
--- a/hw/arm/armv7m.c
40
--- a/linux-user/qemu.h
34
+++ b/hw/arm/armv7m.c
41
+++ b/linux-user/qemu.h
35
@@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp)
42
@@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size;
36
return;
43
static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
44
{
45
if (size == 0
46
- ? !guest_addr_valid(addr)
47
- : !guest_range_valid(addr, size)) {
48
+ ? !guest_addr_valid_untagged(addr)
49
+ : !guest_range_valid_untagged(addr, size)) {
50
return false;
51
}
52
return page_check_range((target_ulong)addr, size, type) == 0;
53
diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c
54
index XXXXXXX..XXXXXXX 100644
55
--- a/accel/tcg/user-exec.c
56
+++ b/accel/tcg/user-exec.c
57
@@ -XXX,XX +XXX,XX @@ static int probe_access_internal(CPUArchState *env, target_ulong addr,
58
g_assert_not_reached();
59
}
60
61
- if (!guest_addr_valid(addr) || page_check_range(addr, 1, flags) < 0) {
62
+ if (!guest_addr_valid_untagged(addr) ||
63
+ page_check_range(addr, 1, flags) < 0) {
64
if (nonfault) {
65
return TLB_INVALID_MASK;
66
} else {
67
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
68
index XXXXXXX..XXXXXXX 100644
69
--- a/linux-user/mmap.c
70
+++ b/linux-user/mmap.c
71
@@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot)
72
}
73
len = TARGET_PAGE_ALIGN(len);
74
end = start + len;
75
- if (!guest_range_valid(start, len)) {
76
+ if (!guest_range_valid_untagged(start, len)) {
77
return -TARGET_ENOMEM;
78
}
79
if (len == 0) {
80
@@ -XXX,XX +XXX,XX @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot,
81
* It can fail only on 64-bit host with 32-bit target.
82
* On any other target/host host mmap() handles this error correctly.
83
*/
84
- if (end < start || !guest_range_valid(start, len)) {
85
+ if (end < start || !guest_range_valid_untagged(start, len)) {
86
errno = ENOMEM;
87
goto fail;
88
}
89
@@ -XXX,XX +XXX,XX @@ int target_munmap(abi_ulong start, abi_ulong len)
90
if (start & ~TARGET_PAGE_MASK)
91
return -TARGET_EINVAL;
92
len = TARGET_PAGE_ALIGN(len);
93
- if (len == 0 || !guest_range_valid(start, len)) {
94
+ if (len == 0 || !guest_range_valid_untagged(start, len)) {
95
return -TARGET_EINVAL;
96
}
97
98
@@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
99
int prot;
100
void *host_addr;
101
102
- if (!guest_range_valid(old_addr, old_size) ||
103
+ if (!guest_range_valid_untagged(old_addr, old_size) ||
104
((flags & MREMAP_FIXED) &&
105
- !guest_range_valid(new_addr, new_size)) ||
106
+ !guest_range_valid_untagged(new_addr, new_size)) ||
107
((flags & MREMAP_MAYMOVE) == 0 &&
108
- !guest_range_valid(old_addr, new_size))) {
109
+ !guest_range_valid_untagged(old_addr, new_size))) {
110
errno = ENOMEM;
111
return -1;
112
}
113
@@ -XXX,XX +XXX,XX @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
114
115
if (host_addr != MAP_FAILED) {
116
/* Check if address fits target address space */
117
- if (!guest_range_valid(h2g(host_addr), new_size)) {
118
+ if (!guest_range_valid_untagged(h2g(host_addr), new_size)) {
119
/* Revert mremap() changes */
120
host_addr = mremap(g2h_untagged(old_addr),
121
new_size, old_size, flags);
122
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
123
index XXXXXXX..XXXXXXX 100644
124
--- a/linux-user/syscall.c
125
+++ b/linux-user/syscall.c
126
@@ -XXX,XX +XXX,XX @@ static inline abi_ulong do_shmat(CPUArchState *cpu_env,
127
return -TARGET_EINVAL;
37
}
128
}
38
}
129
}
39
+ if (object_property_find(OBJECT(s->cpu), "start-powered-off", NULL)) {
130
- if (!guest_range_valid(shmaddr, shm_info.shm_segsz)) {
40
+ object_property_set_bool(OBJECT(s->cpu), s->start_powered_off,
131
+ if (!guest_range_valid_untagged(shmaddr, shm_info.shm_segsz)) {
41
+ "start-powered-off", &err);
132
return -TARGET_EINVAL;
42
+ if (err != NULL) {
133
}
43
+ error_propagate(errp, err);
44
+ return;
45
+ }
46
+ }
47
48
/*
49
* Tell the CPU where the NVIC is; it will fail realize if it doesn't
50
@@ -XXX,XX +XXX,XX @@ static Property armv7m_properties[] = {
51
DEFINE_PROP_LINK("idau", ARMv7MState, idau, TYPE_IDAU_INTERFACE, Object *),
52
DEFINE_PROP_UINT32("init-svtor", ARMv7MState, init_svtor, 0),
53
DEFINE_PROP_BOOL("enable-bitband", ARMv7MState, enable_bitband, false),
54
+ DEFINE_PROP_BOOL("start-powered-off", ARMv7MState, start_powered_off,
55
+ false),
56
DEFINE_PROP_END_OF_LIST(),
57
};
58
134
59
--
135
--
60
2.20.1
136
2.20.1
61
137
62
138
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Provide both tagged and untagged versions of access_ok.
4
In a few places use thread_cpu, as the user is several
5
callees removed from do_syscall1.
6
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Message-id: 20210212184902.1251044-17-richard.henderson@linaro.org
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
---
11
---
7
linux-user/elfload.c | 1 +
12
linux-user/qemu.h | 11 +++++++++--
8
1 file changed, 1 insertion(+)
13
linux-user/elfload.c | 2 +-
14
linux-user/hppa/cpu_loop.c | 8 ++++----
15
linux-user/i386/cpu_loop.c | 2 +-
16
linux-user/i386/signal.c | 5 +++--
17
linux-user/syscall.c | 9 ++++++---
18
6 files changed, 24 insertions(+), 13 deletions(-)
9
19
20
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
21
index XXXXXXX..XXXXXXX 100644
22
--- a/linux-user/qemu.h
23
+++ b/linux-user/qemu.h
24
@@ -XXX,XX +XXX,XX @@ extern unsigned long guest_stack_size;
25
#define VERIFY_READ PAGE_READ
26
#define VERIFY_WRITE (PAGE_READ | PAGE_WRITE)
27
28
-static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
29
+static inline bool access_ok_untagged(int type, abi_ulong addr, abi_ulong size)
30
{
31
if (size == 0
32
? !guest_addr_valid_untagged(addr)
33
@@ -XXX,XX +XXX,XX @@ static inline bool access_ok(int type, abi_ulong addr, abi_ulong size)
34
return page_check_range((target_ulong)addr, size, type) == 0;
35
}
36
37
+static inline bool access_ok(CPUState *cpu, int type,
38
+ abi_ulong addr, abi_ulong size)
39
+{
40
+ return access_ok_untagged(type, cpu_untagged_addr(cpu, addr), size);
41
+}
42
+
43
/* NOTE __get_user and __put_user use host pointers and don't check access.
44
These are usually used to access struct data members once the struct has
45
been locked - usually with lock_user_struct. */
46
@@ -XXX,XX +XXX,XX @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len);
47
host area will have the same contents as the guest. */
48
static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy)
49
{
50
- if (!access_ok(type, guest_addr, len))
51
+ if (!access_ok_untagged(type, guest_addr, len)) {
52
return NULL;
53
+ }
54
#ifdef DEBUG_REMAP
55
{
56
void *addr;
10
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
57
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
11
index XXXXXXX..XXXXXXX 100644
58
index XXXXXXX..XXXXXXX 100644
12
--- a/linux-user/elfload.c
59
--- a/linux-user/elfload.c
13
+++ b/linux-user/elfload.c
60
+++ b/linux-user/elfload.c
14
@@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void)
61
@@ -XXX,XX +XXX,XX @@ static int vma_get_mapping_count(const struct mm_struct *mm)
15
GET_FEATURE_ID(aa64_dp, ARM_HWCAP_A64_ASIMDDP);
62
static abi_ulong vma_dump_size(const struct vm_area_struct *vma)
16
GET_FEATURE_ID(aa64_fcma, ARM_HWCAP_A64_FCMA);
63
{
17
GET_FEATURE_ID(aa64_sve, ARM_HWCAP_A64_SVE);
64
/* if we cannot even read the first page, skip it */
18
+ GET_FEATURE_ID(aa64_pauth, ARM_HWCAP_A64_PACA | ARM_HWCAP_A64_PACG);
65
- if (!access_ok(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE))
19
66
+ if (!access_ok_untagged(VERIFY_READ, vma->vma_start, TARGET_PAGE_SIZE))
20
#undef GET_FEATURE_ID
67
return (0);
68
69
/*
70
diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c
71
index XXXXXXX..XXXXXXX 100644
72
--- a/linux-user/hppa/cpu_loop.c
73
+++ b/linux-user/hppa/cpu_loop.c
74
@@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env)
75
return -TARGET_ENOSYS;
76
77
case 0: /* elf32 atomic 32bit cmpxchg */
78
- if ((addr & 3) || !access_ok(VERIFY_WRITE, addr, 4)) {
79
+ if ((addr & 3) || !access_ok(cs, VERIFY_WRITE, addr, 4)) {
80
return -TARGET_EFAULT;
81
}
82
old = tswap32(old);
83
@@ -XXX,XX +XXX,XX @@ static abi_ulong hppa_lws(CPUHPPAState *env)
84
return -TARGET_ENOSYS;
85
}
86
if (((addr | old | new) & ((1 << size) - 1))
87
- || !access_ok(VERIFY_WRITE, addr, 1 << size)
88
- || !access_ok(VERIFY_READ, old, 1 << size)
89
- || !access_ok(VERIFY_READ, new, 1 << size)) {
90
+ || !access_ok(cs, VERIFY_WRITE, addr, 1 << size)
91
+ || !access_ok(cs, VERIFY_READ, old, 1 << size)
92
+ || !access_ok(cs, VERIFY_READ, new, 1 << size)) {
93
return -TARGET_EFAULT;
94
}
95
/* Note that below we use host-endian loads so that the cmpxchg
96
diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
97
index XXXXXXX..XXXXXXX 100644
98
--- a/linux-user/i386/cpu_loop.c
99
+++ b/linux-user/i386/cpu_loop.c
100
@@ -XXX,XX +XXX,XX @@ static bool write_ok_or_segv(CPUX86State *env, abi_ptr addr, size_t len)
101
* For all the vsyscalls, NULL means "don't write anything" not
102
* "write it at address 0".
103
*/
104
- if (addr == 0 || access_ok(VERIFY_WRITE, addr, len)) {
105
+ if (addr == 0 || access_ok(env_cpu(env), VERIFY_WRITE, addr, len)) {
106
return true;
107
}
108
109
diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c
110
index XXXXXXX..XXXXXXX 100644
111
--- a/linux-user/i386/signal.c
112
+++ b/linux-user/i386/signal.c
113
@@ -XXX,XX +XXX,XX @@ restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc)
114
115
fpstate_addr = tswapl(sc->fpstate);
116
if (fpstate_addr != 0) {
117
- if (!access_ok(VERIFY_READ, fpstate_addr,
118
- sizeof(struct target_fpstate)))
119
+ if (!access_ok(env_cpu(env), VERIFY_READ, fpstate_addr,
120
+ sizeof(struct target_fpstate))) {
121
goto badframe;
122
+ }
123
#ifndef TARGET_X86_64
124
cpu_x86_frstor(env, fpstate_addr, 1);
125
#else
126
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
127
index XXXXXXX..XXXXXXX 100644
128
--- a/linux-user/syscall.c
129
+++ b/linux-user/syscall.c
130
@@ -XXX,XX +XXX,XX @@ static abi_long do_accept4(int fd, abi_ulong target_addr,
131
return -TARGET_EINVAL;
132
}
133
134
- if (!access_ok(VERIFY_WRITE, target_addr, addrlen))
135
+ if (!access_ok(thread_cpu, VERIFY_WRITE, target_addr, addrlen)) {
136
return -TARGET_EFAULT;
137
+ }
138
139
addr = alloca(addrlen);
140
141
@@ -XXX,XX +XXX,XX @@ static abi_long do_getpeername(int fd, abi_ulong target_addr,
142
return -TARGET_EINVAL;
143
}
144
145
- if (!access_ok(VERIFY_WRITE, target_addr, addrlen))
146
+ if (!access_ok(thread_cpu, VERIFY_WRITE, target_addr, addrlen)) {
147
return -TARGET_EFAULT;
148
+ }
149
150
addr = alloca(addrlen);
151
152
@@ -XXX,XX +XXX,XX @@ static abi_long do_getsockname(int fd, abi_ulong target_addr,
153
return -TARGET_EINVAL;
154
}
155
156
- if (!access_ok(VERIFY_WRITE, target_addr, addrlen))
157
+ if (!access_ok(thread_cpu, VERIFY_WRITE, target_addr, addrlen)) {
158
return -TARGET_EFAULT;
159
+ }
160
161
addr = alloca(addrlen);
21
162
22
--
163
--
23
2.20.1
164
2.20.1
24
165
25
166
diff view generated by jsdifflib
1
The SYS_VERSION and SYS_CONFIG register values differ between the
1
From: Richard Henderson <richard.henderson@linaro.org>
2
IoTKit and SSE-200. Make them configurable via QOM properties rather
3
than hard-coded, and set them appropriately in the ARMSSE code that
4
instantiates the IOTKIT_SYSINFO device.
5
2
3
These functions are not small, except for unlock_user
4
without debugging enabled. Move them out of line, and
5
add missing braces on the way.
6
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Message-id: 20210212184902.1251044-18-richard.henderson@linaro.org
11
[PMM: fixed the sense of an ifdef test in qemu.h]
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20190121185118.18550-15-peter.maydell@linaro.org
9
---
13
---
10
include/hw/misc/iotkit-sysinfo.h | 6 ++++
14
linux-user/qemu.h | 47 +++++++-------------------------------------
11
hw/arm/armsse.c | 51 ++++++++++++++++++++++++++++++++
15
linux-user/uaccess.c | 46 +++++++++++++++++++++++++++++++++++++++++++
12
hw/misc/iotkit-sysinfo.c | 15 ++++++++--
16
2 files changed, 53 insertions(+), 40 deletions(-)
13
3 files changed, 70 insertions(+), 2 deletions(-)
14
17
15
diff --git a/include/hw/misc/iotkit-sysinfo.h b/include/hw/misc/iotkit-sysinfo.h
18
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
16
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
17
--- a/include/hw/misc/iotkit-sysinfo.h
20
--- a/linux-user/qemu.h
18
+++ b/include/hw/misc/iotkit-sysinfo.h
21
+++ b/linux-user/qemu.h
22
@@ -XXX,XX +XXX,XX @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len);
23
24
/* Lock an area of guest memory into the host. If copy is true then the
25
host area will have the same contents as the guest. */
26
-static inline void *lock_user(int type, abi_ulong guest_addr, long len, int copy)
27
-{
28
- if (!access_ok_untagged(type, guest_addr, len)) {
29
- return NULL;
30
- }
31
-#ifdef DEBUG_REMAP
32
- {
33
- void *addr;
34
- addr = g_malloc(len);
35
- if (copy)
36
- memcpy(addr, g2h(guest_addr), len);
37
- else
38
- memset(addr, 0, len);
39
- return addr;
40
- }
41
-#else
42
- return g2h_untagged(guest_addr);
43
-#endif
44
-}
45
+void *lock_user(int type, abi_ulong guest_addr, long len, int copy);
46
47
/* Unlock an area of guest memory. The first LEN bytes must be
48
flushed back to guest memory. host_ptr = NULL is explicitly
49
allowed and does nothing. */
50
-static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
51
- long len)
52
-{
53
-
54
-#ifdef DEBUG_REMAP
55
- if (!host_ptr)
56
- return;
57
- if (host_ptr == g2h_untagged(guest_addr))
58
- return;
59
- if (len > 0)
60
- memcpy(g2h_untagged(guest_addr), host_ptr, len);
61
- g_free(host_ptr);
62
+#ifndef DEBUG_REMAP
63
+static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, long len)
64
+{ }
65
+#else
66
+void unlock_user(void *host_ptr, abi_ulong guest_addr, long len);
67
#endif
68
-}
69
70
/* Return the length of a string in target memory or -TARGET_EFAULT if
71
access error. */
72
abi_long target_strlen(abi_ulong gaddr);
73
74
/* Like lock_user but for null terminated strings. */
75
-static inline void *lock_user_string(abi_ulong guest_addr)
76
-{
77
- abi_long len;
78
- len = target_strlen(guest_addr);
79
- if (len < 0)
80
- return NULL;
81
- return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1);
82
-}
83
+void *lock_user_string(abi_ulong guest_addr);
84
85
/* Helper macros for locking/unlocking a target struct. */
86
#define lock_user_struct(type, host_ptr, guest_addr, copy)    \
87
diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c
88
index XXXXXXX..XXXXXXX 100644
89
--- a/linux-user/uaccess.c
90
+++ b/linux-user/uaccess.c
19
@@ -XXX,XX +XXX,XX @@
91
@@ -XXX,XX +XXX,XX @@
20
* Arm IoTKit and documented in
92
21
* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
93
#include "qemu.h"
22
* QEMU interface:
94
23
+ * + QOM property "SYS_VERSION": value to use for SYS_VERSION register
95
+void *lock_user(int type, abi_ulong guest_addr, long len, int copy)
24
+ * + QOM property "SYS_CONFIG": value to use for SYS_CONFIG register
25
* + sysbus MMIO region 0: the system information register bank
26
*/
27
28
@@ -XXX,XX +XXX,XX @@ typedef struct IoTKitSysInfo {
29
30
/*< public >*/
31
MemoryRegion iomem;
32
+
33
+ /* Properties */
34
+ uint32_t sys_version;
35
+ uint32_t sys_config;
36
} IoTKitSysInfo;
37
38
#endif
39
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
40
index XXXXXXX..XXXXXXX 100644
41
--- a/hw/arm/armsse.c
42
+++ b/hw/arm/armsse.c
43
@@ -XXX,XX +XXX,XX @@
44
#include "hw/arm/armsse.h"
45
#include "hw/arm/arm.h"
46
47
+/* Format of the System Information block SYS_CONFIG register */
48
+typedef enum SysConfigFormat {
49
+ IoTKitFormat,
50
+ SSE200Format,
51
+} SysConfigFormat;
52
+
53
struct ARMSSEInfo {
54
const char *name;
55
int sram_banks;
56
int num_cpus;
57
+ uint32_t sys_version;
58
+ SysConfigFormat sys_config_format;
59
};
60
61
static const ARMSSEInfo armsse_variants[] = {
62
@@ -XXX,XX +XXX,XX @@ static const ARMSSEInfo armsse_variants[] = {
63
.name = TYPE_IOTKIT,
64
.sram_banks = 1,
65
.num_cpus = 1,
66
+ .sys_version = 0x41743,
67
+ .sys_config_format = IoTKitFormat,
68
},
69
};
70
71
+static uint32_t armsse_sys_config_value(ARMSSE *s, const ARMSSEInfo *info)
72
+{
96
+{
73
+ /* Return the SYS_CONFIG value for this SSE */
97
+ if (!access_ok_untagged(type, guest_addr, len)) {
74
+ uint32_t sys_config;
98
+ return NULL;
75
+
99
+ }
76
+ switch (info->sys_config_format) {
100
+#ifdef DEBUG_REMAP
77
+ case IoTKitFormat:
101
+ {
78
+ sys_config = 0;
102
+ void *addr;
79
+ sys_config = deposit32(sys_config, 0, 4, info->sram_banks);
103
+ addr = g_malloc(len);
80
+ sys_config = deposit32(sys_config, 4, 4, s->sram_addr_width - 12);
104
+ if (copy) {
81
+ break;
105
+ memcpy(addr, g2h(guest_addr), len);
82
+ case SSE200Format:
106
+ } else {
83
+ sys_config = 0;
107
+ memset(addr, 0, len);
84
+ sys_config = deposit32(sys_config, 0, 4, info->sram_banks);
85
+ sys_config = deposit32(sys_config, 4, 5, s->sram_addr_width);
86
+ sys_config = deposit32(sys_config, 24, 4, 2);
87
+ if (info->num_cpus > 1) {
88
+ sys_config = deposit32(sys_config, 10, 1, 1);
89
+ sys_config = deposit32(sys_config, 20, 4, info->sram_banks - 1);
90
+ sys_config = deposit32(sys_config, 28, 4, 2);
91
+ }
108
+ }
92
+ break;
109
+ return addr;
93
+ default:
94
+ g_assert_not_reached();
95
+ }
110
+ }
96
+ return sys_config;
111
+#else
112
+ return g2h_untagged(guest_addr);
113
+#endif
97
+}
114
+}
98
+
115
+
99
/* Clock frequency in HZ of the 32KHz "slow clock" */
116
+#ifdef DEBUG_REMAP
100
#define S32KCLK (32 * 1000)
117
+void unlock_user(void *host_ptr, abi_ulong guest_addr, long len);
101
118
+{
102
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
119
+ if (!host_ptr) {
103
qdev_get_gpio_in_named(dev_apb_ppc1,
104
"cfg_sec_resp", 0));
105
106
+ object_property_set_int(OBJECT(&s->sysinfo), info->sys_version,
107
+ "SYS_VERSION", &err);
108
+ if (err) {
109
+ error_propagate(errp, err);
110
+ return;
120
+ return;
111
+ }
121
+ }
112
+ object_property_set_int(OBJECT(&s->sysinfo),
122
+ if (host_ptr == g2h_untagged(guest_addr)) {
113
+ armsse_sys_config_value(s, info),
114
+ "SYS_CONFIG", &err);
115
+ if (err) {
116
+ error_propagate(errp, err);
117
+ return;
123
+ return;
118
+ }
124
+ }
119
object_property_set_bool(OBJECT(&s->sysinfo), true, "realized", &err);
125
+ if (len > 0) {
120
if (err) {
126
+ memcpy(g2h_untagged(guest_addr), host_ptr, len);
121
error_propagate(errp, err);
127
+ }
122
diff --git a/hw/misc/iotkit-sysinfo.c b/hw/misc/iotkit-sysinfo.c
128
+ g_free(host_ptr);
123
index XXXXXXX..XXXXXXX 100644
129
+}
124
--- a/hw/misc/iotkit-sysinfo.c
130
+#endif
125
+++ b/hw/misc/iotkit-sysinfo.c
126
@@ -XXX,XX +XXX,XX @@ static const int sysinfo_id[] = {
127
static uint64_t iotkit_sysinfo_read(void *opaque, hwaddr offset,
128
unsigned size)
129
{
130
+ IoTKitSysInfo *s = IOTKIT_SYSINFO(opaque);
131
uint64_t r;
132
133
switch (offset) {
134
case A_SYS_VERSION:
135
- r = 0x41743;
136
+ r = s->sys_version;
137
break;
138
139
case A_SYS_CONFIG:
140
- r = 0x31;
141
+ r = s->sys_config;
142
break;
143
case A_PID4 ... A_CID3:
144
r = sysinfo_id[(offset - A_PID4) / 4];
145
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps iotkit_sysinfo_ops = {
146
.valid.max_access_size = 4,
147
};
148
149
+static Property iotkit_sysinfo_props[] = {
150
+ DEFINE_PROP_UINT32("SYS_VERSION", IoTKitSysInfo, sys_version, 0),
151
+ DEFINE_PROP_UINT32("SYS_CONFIG", IoTKitSysInfo, sys_config, 0),
152
+ DEFINE_PROP_END_OF_LIST()
153
+};
154
+
131
+
155
static void iotkit_sysinfo_init(Object *obj)
132
+void *lock_user_string(abi_ulong guest_addr)
156
{
133
+{
157
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
134
+ abi_long len = target_strlen(guest_addr);
158
@@ -XXX,XX +XXX,XX @@ static void iotkit_sysinfo_init(Object *obj)
135
+ if (len < 0) {
159
136
+ return NULL;
160
static void iotkit_sysinfo_class_init(ObjectClass *klass, void *data)
137
+ }
161
{
138
+ return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1);
162
+ DeviceClass *dc = DEVICE_CLASS(klass);
139
+}
163
+
140
+
164
/*
141
/* copy_from_user() and copy_to_user() are usually used to copy data
165
* This device has no guest-modifiable state and so it
142
* buffers between the target and host. These internally perform
166
* does not need a reset function or VMState.
143
* locking/unlocking of the memory.
167
*/
168
+
169
+ dc->props = iotkit_sysinfo_props;
170
}
171
172
static const TypeInfo iotkit_sysinfo_info = {
173
--
144
--
174
2.20.1
145
2.20.1
175
146
176
147
diff view generated by jsdifflib
1
Rename various internal uses of 'iotkit' in hw/arm/iotkit.c to
1
From: Richard Henderson <richard.henderson@linaro.org>
2
'armsse', for consistency. The remaining occurences are:
3
* related to the devices TYPE_IOTKIT_SYSCTL, TYPE_IOTKIT_SYSINFO,
4
etc, which this refactor is not touching
5
* references that apply specifically to the IoTKit (like
6
the lack of a private CPU region)
7
* the vmstate, which keeps its old "iotkit" name for
8
migration compatibility reasons
9
2
3
For copy_*_user, only 0 and -TARGET_EFAULT are returned; no need
4
to involve abi_long. Use size_t for lengths. Use bool for the
5
lock_user copy argument. Use ssize_t for target_strlen, because
6
we can't overflow the host memory space.
7
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Message-id: 20210212184902.1251044-19-richard.henderson@linaro.org
12
[PMM: moved fix for ifdef error to previous commit]
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Message-id: 20190121185118.18550-7-peter.maydell@linaro.org
14
---
14
---
15
hw/arm/iotkit.c | 68 ++++++++++++++++++++++++-------------------------
15
linux-user/qemu.h | 12 +++++-------
16
1 file changed, 34 insertions(+), 34 deletions(-)
16
linux-user/uaccess.c | 45 ++++++++++++++++++++++----------------------
17
2 files changed, 28 insertions(+), 29 deletions(-)
17
18
18
diff --git a/hw/arm/iotkit.c b/hw/arm/iotkit.c
19
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
19
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/arm/iotkit.c
21
--- a/linux-user/qemu.h
21
+++ b/hw/arm/iotkit.c
22
+++ b/linux-user/qemu.h
22
@@ -XXX,XX +XXX,XX @@ static void nsccfg_handler(void *opaque, int n, int level)
23
@@ -XXX,XX +XXX,XX @@
23
s->nsccfg = level;
24
#include "exec/cpu_ldst.h"
25
26
#undef DEBUG_REMAP
27
-#ifdef DEBUG_REMAP
28
-#endif /* DEBUG_REMAP */
29
30
#include "exec/user/abitypes.h"
31
32
@@ -XXX,XX +XXX,XX @@ static inline bool access_ok(CPUState *cpu, int type,
33
* buffers between the target and host. These internally perform
34
* locking/unlocking of the memory.
35
*/
36
-abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len);
37
-abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len);
38
+int copy_from_user(void *hptr, abi_ulong gaddr, size_t len);
39
+int copy_to_user(abi_ulong gaddr, void *hptr, size_t len);
40
41
/* Functions for accessing guest memory. The tget and tput functions
42
read/write single values, byteswapping as necessary. The lock_user function
43
@@ -XXX,XX +XXX,XX @@ abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len);
44
45
/* Lock an area of guest memory into the host. If copy is true then the
46
host area will have the same contents as the guest. */
47
-void *lock_user(int type, abi_ulong guest_addr, long len, int copy);
48
+void *lock_user(int type, abi_ulong guest_addr, size_t len, bool copy);
49
50
/* Unlock an area of guest memory. The first LEN bytes must be
51
flushed back to guest memory. host_ptr = NULL is explicitly
52
allowed and does nothing. */
53
#ifndef DEBUG_REMAP
54
-static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, long len)
55
+static inline void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len)
56
{ }
57
#else
58
void unlock_user(void *host_ptr, abi_ulong guest_addr, long len);
59
@@ -XXX,XX +XXX,XX @@ void unlock_user(void *host_ptr, abi_ulong guest_addr, long len);
60
61
/* Return the length of a string in target memory or -TARGET_EFAULT if
62
access error. */
63
-abi_long target_strlen(abi_ulong gaddr);
64
+ssize_t target_strlen(abi_ulong gaddr);
65
66
/* Like lock_user but for null terminated strings. */
67
void *lock_user_string(abi_ulong guest_addr);
68
diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c
69
index XXXXXXX..XXXXXXX 100644
70
--- a/linux-user/uaccess.c
71
+++ b/linux-user/uaccess.c
72
@@ -XXX,XX +XXX,XX @@
73
74
#include "qemu.h"
75
76
-void *lock_user(int type, abi_ulong guest_addr, long len, int copy)
77
+void *lock_user(int type, abi_ulong guest_addr, size_t len, bool copy)
78
{
79
if (!access_ok_untagged(type, guest_addr, len)) {
80
return NULL;
81
@@ -XXX,XX +XXX,XX @@ void *lock_user(int type, abi_ulong guest_addr, long len, int copy)
24
}
82
}
25
83
26
-static void iotkit_forward_ppc(ARMSSE *s, const char *ppcname, int ppcnum)
84
#ifdef DEBUG_REMAP
27
+static void armsse_forward_ppc(ARMSSE *s, const char *ppcname, int ppcnum)
85
-void unlock_user(void *host_ptr, abi_ulong guest_addr, long len);
86
+void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len);
28
{
87
{
29
/* Each of the 4 AHB and 4 APB PPCs that might be present in a
88
if (!host_ptr) {
30
* system using the ARMSSE has a collection of control lines which
89
return;
31
@@ -XXX,XX +XXX,XX @@ static void iotkit_forward_ppc(ARMSSE *s, const char *ppcname, int ppcnum)
90
@@ -XXX,XX +XXX,XX @@ void unlock_user(void *host_ptr, abi_ulong guest_addr, long len);
32
* code using the ARMSSE can wire them up to the PPCs.
91
if (host_ptr == g2h_untagged(guest_addr)) {
33
*/
92
return;
34
SplitIRQ *splitter = &s->ppc_irq_splitter[ppcnum];
93
}
35
- DeviceState *iotkitdev = DEVICE(s);
94
- if (len > 0) {
36
+ DeviceState *armssedev = DEVICE(s);
95
+ if (len != 0) {
37
DeviceState *dev_secctl = DEVICE(&s->secctl);
96
memcpy(g2h_untagged(guest_addr), host_ptr, len);
38
DeviceState *dev_splitter = DEVICE(splitter);
97
}
39
char *name;
98
g_free(host_ptr);
40
99
@@ -XXX,XX +XXX,XX @@ void unlock_user(void *host_ptr, abi_ulong guest_addr, long len);
41
name = g_strdup_printf("%s_nonsec", ppcname);
100
42
- qdev_pass_gpios(dev_secctl, iotkitdev, name);
101
void *lock_user_string(abi_ulong guest_addr)
43
+ qdev_pass_gpios(dev_secctl, armssedev, name);
102
{
44
g_free(name);
103
- abi_long len = target_strlen(guest_addr);
45
name = g_strdup_printf("%s_ap", ppcname);
104
+ ssize_t len = target_strlen(guest_addr);
46
- qdev_pass_gpios(dev_secctl, iotkitdev, name);
105
if (len < 0) {
47
+ qdev_pass_gpios(dev_secctl, armssedev, name);
106
return NULL;
48
g_free(name);
107
}
49
name = g_strdup_printf("%s_irq_enable", ppcname);
108
- return lock_user(VERIFY_READ, guest_addr, (long)(len + 1), 1);
50
- qdev_pass_gpios(dev_secctl, iotkitdev, name);
109
+ return lock_user(VERIFY_READ, guest_addr, (size_t)len + 1, 1);
51
+ qdev_pass_gpios(dev_secctl, armssedev, name);
52
g_free(name);
53
name = g_strdup_printf("%s_irq_clear", ppcname);
54
- qdev_pass_gpios(dev_secctl, iotkitdev, name);
55
+ qdev_pass_gpios(dev_secctl, armssedev, name);
56
g_free(name);
57
58
/* irq_status is a little more tricky, because we need to
59
@@ -XXX,XX +XXX,XX @@ static void iotkit_forward_ppc(ARMSSE *s, const char *ppcname, int ppcnum)
60
qdev_connect_gpio_out(dev_splitter, 1,
61
qdev_get_gpio_in(DEVICE(&s->ppc_irq_orgate), ppcnum));
62
s->irq_status_in[ppcnum] = qdev_get_gpio_in(dev_splitter, 0);
63
- qdev_init_gpio_in_named_with_opaque(iotkitdev, irq_status_forwarder,
64
+ qdev_init_gpio_in_named_with_opaque(armssedev, irq_status_forwarder,
65
s->irq_status_in[ppcnum], name, 1);
66
g_free(name);
67
}
110
}
68
111
69
-static void iotkit_forward_sec_resp_cfg(ARMSSE *s)
112
/* copy_from_user() and copy_to_user() are usually used to copy data
70
+static void armsse_forward_sec_resp_cfg(ARMSSE *s)
113
* buffers between the target and host. These internally perform
114
* locking/unlocking of the memory.
115
*/
116
-abi_long copy_from_user(void *hptr, abi_ulong gaddr, size_t len)
117
+int copy_from_user(void *hptr, abi_ulong gaddr, size_t len)
71
{
118
{
72
/* Forward the 3rd output from the splitter device as a
119
- abi_long ret = 0;
73
- * named GPIO output of the iotkit object.
120
- void *ghptr;
74
+ * named GPIO output of the armsse object.
121
+ int ret = 0;
75
*/
122
+ void *ghptr = lock_user(VERIFY_READ, gaddr, len, 1);
76
DeviceState *dev = DEVICE(s);
123
77
DeviceState *dev_splitter = DEVICE(&s->sec_resp_splitter);
124
- if ((ghptr = lock_user(VERIFY_READ, gaddr, len, 1))) {
78
@@ -XXX,XX +XXX,XX @@ static void iotkit_forward_sec_resp_cfg(ARMSSE *s)
125
+ if (ghptr) {
79
qdev_connect_gpio_out(dev_splitter, 2, s->sec_resp_cfg_in);
126
memcpy(hptr, ghptr, len);
127
unlock_user(ghptr, gaddr, 0);
128
- } else
129
+ } else {
130
ret = -TARGET_EFAULT;
131
-
132
+ }
133
return ret;
80
}
134
}
81
135
82
-static void iotkit_init(Object *obj)
136
-
83
+static void armsse_init(Object *obj)
137
-abi_long copy_to_user(abi_ulong gaddr, void *hptr, size_t len)
138
+int copy_to_user(abi_ulong gaddr, void *hptr, size_t len)
84
{
139
{
85
ARMSSE *s = ARMSSE(obj);
140
- abi_long ret = 0;
86
int i;
141
- void *ghptr;
87
142
+ int ret = 0;
88
- memory_region_init(&s->container, obj, "iotkit-container", UINT64_MAX);
143
+ void *ghptr = lock_user(VERIFY_WRITE, gaddr, len, 0);
89
+ memory_region_init(&s->container, obj, "armsse-container", UINT64_MAX);
144
90
145
- if ((ghptr = lock_user(VERIFY_WRITE, gaddr, len, 0))) {
91
sysbus_init_child_obj(obj, "armv7m", &s->armv7m, sizeof(s->armv7m),
146
+ if (ghptr) {
92
TYPE_ARMV7M);
147
memcpy(ghptr, hptr, len);
93
@@ -XXX,XX +XXX,XX @@ static void iotkit_init(Object *obj)
148
unlock_user(ghptr, gaddr, len);
94
sizeof(s->nswatchdog), TYPE_CMSDK_APB_WATCHDOG);
149
- } else
95
sysbus_init_child_obj(obj, "swatchdog", &s->swatchdog,
150
+ } else {
96
sizeof(s->swatchdog), TYPE_CMSDK_APB_WATCHDOG);
151
ret = -TARGET_EFAULT;
97
- sysbus_init_child_obj(obj, "iotkit-sysctl", &s->sysctl,
152
+ }
98
+ sysbus_init_child_obj(obj, "armsse-sysctl", &s->sysctl,
153
99
sizeof(s->sysctl), TYPE_IOTKIT_SYSCTL);
154
return ret;
100
- sysbus_init_child_obj(obj, "iotkit-sysinfo", &s->sysinfo,
155
}
101
+ sysbus_init_child_obj(obj, "armsse-sysinfo", &s->sysinfo,
156
102
sizeof(s->sysinfo), TYPE_IOTKIT_SYSINFO);
157
/* Return the length of a string in target memory or -TARGET_EFAULT if
103
object_initialize_child(obj, "nmi-orgate", &s->nmi_orgate,
158
access error */
104
sizeof(s->nmi_orgate), TYPE_OR_IRQ,
159
-abi_long target_strlen(abi_ulong guest_addr1)
105
@@ -XXX,XX +XXX,XX @@ static void iotkit_init(Object *obj)
160
+ssize_t target_strlen(abi_ulong guest_addr1)
161
{
162
uint8_t *ptr;
163
abi_ulong guest_addr;
164
- int max_len, len;
165
+ size_t max_len, len;
166
167
guest_addr = guest_addr1;
168
for(;;) {
169
@@ -XXX,XX +XXX,XX @@ abi_long target_strlen(abi_ulong guest_addr1)
170
unlock_user(ptr, guest_addr, 0);
171
guest_addr += len;
172
/* we don't allow wrapping or integer overflow */
173
- if (guest_addr == 0 ||
174
- (guest_addr - guest_addr1) > 0x7fffffff)
175
+ if (guest_addr == 0 || (guest_addr - guest_addr1) > 0x7fffffff) {
176
return -TARGET_EFAULT;
177
- if (len != max_len)
178
+ }
179
+ if (len != max_len) {
180
break;
181
+ }
106
}
182
}
183
return guest_addr - guest_addr1;
107
}
184
}
108
109
-static void iotkit_exp_irq(void *opaque, int n, int level)
110
+static void armsse_exp_irq(void *opaque, int n, int level)
111
{
112
ARMSSE *s = ARMSSE(opaque);
113
114
qemu_set_irq(s->exp_irqs[n], level);
115
}
116
117
-static void iotkit_mpcexp_status(void *opaque, int n, int level)
118
+static void armsse_mpcexp_status(void *opaque, int n, int level)
119
{
120
ARMSSE *s = ARMSSE(opaque);
121
qemu_set_irq(s->mpcexp_status_in[n], level);
122
}
123
124
-static void iotkit_realize(DeviceState *dev, Error **errp)
125
+static void armsse_realize(DeviceState *dev, Error **errp)
126
{
127
ARMSSE *s = ARMSSE(dev);
128
int i;
129
@@ -XXX,XX +XXX,XX @@ static void iotkit_realize(DeviceState *dev, Error **errp)
130
for (i = 0; i < s->exp_numirq; i++) {
131
s->exp_irqs[i] = qdev_get_gpio_in(DEVICE(&s->armv7m), i + 32);
132
}
133
- qdev_init_gpio_in_named(dev, iotkit_exp_irq, "EXP_IRQ", s->exp_numirq);
134
+ qdev_init_gpio_in_named(dev, armsse_exp_irq, "EXP_IRQ", s->exp_numirq);
135
136
/* Set up the big aliases first */
137
make_alias(s, &s->alias1, "alias 1", 0x10000000, 0x10000000, 0x00000000);
138
@@ -XXX,XX +XXX,XX @@ static void iotkit_realize(DeviceState *dev, Error **errp)
139
qdev_get_gpio_in(dev_splitter, 0));
140
141
/* This RAM lives behind the Memory Protection Controller */
142
- memory_region_init_ram(&s->sram0, NULL, "iotkit.sram0", 0x00008000, &err);
143
+ memory_region_init_ram(&s->sram0, NULL, "armsse.sram0", 0x00008000, &err);
144
if (err) {
145
error_propagate(errp, err);
146
return;
147
@@ -XXX,XX +XXX,XX @@ static void iotkit_realize(DeviceState *dev, Error **errp)
148
for (i = 0; i < IOTS_NUM_AHB_EXP_PPC; i++) {
149
char *ppcname = g_strdup_printf("ahb_ppcexp%d", i);
150
151
- iotkit_forward_ppc(s, ppcname, i);
152
+ armsse_forward_ppc(s, ppcname, i);
153
g_free(ppcname);
154
}
155
156
for (i = 0; i < IOTS_NUM_APB_EXP_PPC; i++) {
157
char *ppcname = g_strdup_printf("apb_ppcexp%d", i);
158
159
- iotkit_forward_ppc(s, ppcname, i + IOTS_NUM_AHB_EXP_PPC);
160
+ armsse_forward_ppc(s, ppcname, i + IOTS_NUM_AHB_EXP_PPC);
161
g_free(ppcname);
162
}
163
164
@@ -XXX,XX +XXX,XX @@ static void iotkit_realize(DeviceState *dev, Error **errp)
165
/* Create GPIO inputs which will pass the line state for our
166
* mpcexp_irq inputs to the correct splitter devices.
167
*/
168
- qdev_init_gpio_in_named(dev, iotkit_mpcexp_status, "mpcexp_status",
169
+ qdev_init_gpio_in_named(dev, armsse_mpcexp_status, "mpcexp_status",
170
IOTS_NUM_EXP_MPC);
171
172
- iotkit_forward_sec_resp_cfg(s);
173
+ armsse_forward_sec_resp_cfg(s);
174
175
/* Forward the MSC related signals */
176
qdev_pass_gpios(dev_secctl, dev, "mscexp_status");
177
@@ -XXX,XX +XXX,XX @@ static void iotkit_realize(DeviceState *dev, Error **errp)
178
system_clock_scale = NANOSECONDS_PER_SECOND / s->mainclk_frq;
179
}
180
181
-static void iotkit_idau_check(IDAUInterface *ii, uint32_t address,
182
+static void armsse_idau_check(IDAUInterface *ii, uint32_t address,
183
int *iregion, bool *exempt, bool *ns, bool *nsc)
184
{
185
/*
186
@@ -XXX,XX +XXX,XX @@ static void iotkit_idau_check(IDAUInterface *ii, uint32_t address,
187
*iregion = region;
188
}
189
190
-static const VMStateDescription iotkit_vmstate = {
191
+static const VMStateDescription armsse_vmstate = {
192
.name = "iotkit",
193
.version_id = 1,
194
.minimum_version_id = 1,
195
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription iotkit_vmstate = {
196
}
197
};
198
199
-static Property iotkit_properties[] = {
200
+static Property armsse_properties[] = {
201
DEFINE_PROP_LINK("memory", ARMSSE, board_memory, TYPE_MEMORY_REGION,
202
MemoryRegion *),
203
DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE, exp_numirq, 64),
204
@@ -XXX,XX +XXX,XX @@ static Property iotkit_properties[] = {
205
DEFINE_PROP_END_OF_LIST()
206
};
207
208
-static void iotkit_reset(DeviceState *dev)
209
+static void armsse_reset(DeviceState *dev)
210
{
211
ARMSSE *s = ARMSSE(dev);
212
213
s->nsccfg = 0;
214
}
215
216
-static void iotkit_class_init(ObjectClass *klass, void *data)
217
+static void armsse_class_init(ObjectClass *klass, void *data)
218
{
219
DeviceClass *dc = DEVICE_CLASS(klass);
220
IDAUInterfaceClass *iic = IDAU_INTERFACE_CLASS(klass);
221
ARMSSEClass *asc = ARMSSE_CLASS(klass);
222
223
- dc->realize = iotkit_realize;
224
- dc->vmsd = &iotkit_vmstate;
225
- dc->props = iotkit_properties;
226
- dc->reset = iotkit_reset;
227
- iic->check = iotkit_idau_check;
228
+ dc->realize = armsse_realize;
229
+ dc->vmsd = &armsse_vmstate;
230
+ dc->props = armsse_properties;
231
+ dc->reset = armsse_reset;
232
+ iic->check = armsse_idau_check;
233
asc->info = data;
234
}
235
236
@@ -XXX,XX +XXX,XX @@ static const TypeInfo armsse_info = {
237
.name = TYPE_ARMSSE,
238
.parent = TYPE_SYS_BUS_DEVICE,
239
.instance_size = sizeof(ARMSSE),
240
- .instance_init = iotkit_init,
241
+ .instance_init = armsse_init,
242
.abstract = true,
243
.interfaces = (InterfaceInfo[]) {
244
{ TYPE_IDAU_INTERFACE },
245
@@ -XXX,XX +XXX,XX @@ static void armsse_register_types(void)
246
TypeInfo ti = {
247
.name = armsse_variants[i].name,
248
.parent = TYPE_ARMSSE,
249
- .class_init = iotkit_class_init,
250
+ .class_init = armsse_class_init,
251
.class_data = (void *)&armsse_variants[i],
252
};
253
type_register(&ti);
254
--
185
--
255
2.20.1
186
2.20.1
256
187
257
188
diff view generated by jsdifflib
1
In the AdvSIMD load/store multiple structures encodings,
1
From: Richard Henderson <richard.henderson@linaro.org>
2
the non-post-indexed case should have zeroes in [20:16]
3
(which is the Rm field for the post-indexed case).
4
Correctly UNDEF the currently unallocated encodings which
5
have non-zeroes in those bits.
6
2
7
Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com>
3
Resolve the untagged address once, using thread_cpu.
4
Tidy the DEBUG_REMAP code using glib routines.
5
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210212184902.1251044-20-richard.henderson@linaro.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com>
10
Message-id: 20190125182626.9221-4-peter.maydell@linaro.org
11
---
10
---
12
target/arm/translate-a64.c | 7 ++++++-
11
linux-user/uaccess.c | 27 ++++++++++++++-------------
13
1 file changed, 6 insertions(+), 1 deletion(-)
12
1 file changed, 14 insertions(+), 13 deletions(-)
14
13
15
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
14
diff --git a/linux-user/uaccess.c b/linux-user/uaccess.c
16
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/translate-a64.c
16
--- a/linux-user/uaccess.c
18
+++ b/target/arm/translate-a64.c
17
+++ b/linux-user/uaccess.c
19
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)
18
@@ -XXX,XX +XXX,XX @@
19
20
void *lock_user(int type, abi_ulong guest_addr, size_t len, bool copy)
20
{
21
{
21
int rt = extract32(insn, 0, 5);
22
+ void *host_addr;
22
int rn = extract32(insn, 5, 5);
23
+
23
+ int rm = extract32(insn, 16, 5);
24
+ guest_addr = cpu_untagged_addr(thread_cpu, guest_addr);
24
int size = extract32(insn, 10, 2);
25
if (!access_ok_untagged(type, guest_addr, len)) {
25
int opcode = extract32(insn, 12, 4);
26
return NULL;
26
bool is_store = !extract32(insn, 22, 1);
27
}
27
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)
28
+ host_addr = g2h_untagged(guest_addr);
29
#ifdef DEBUG_REMAP
30
- {
31
- void *addr;
32
- addr = g_malloc(len);
33
- if (copy) {
34
- memcpy(addr, g2h(guest_addr), len);
35
- } else {
36
- memset(addr, 0, len);
37
- }
38
- return addr;
39
+ if (copy) {
40
+ host_addr = g_memdup(host_addr, len);
41
+ } else {
42
+ host_addr = g_malloc0(len);
43
}
44
-#else
45
- return g2h_untagged(guest_addr);
46
#endif
47
+ return host_addr;
48
}
49
50
#ifdef DEBUG_REMAP
51
void unlock_user(void *host_ptr, abi_ulong guest_addr, size_t len);
52
{
53
+ void *host_ptr_conv;
54
+
55
if (!host_ptr) {
28
return;
56
return;
29
}
57
}
30
58
- if (host_ptr == g2h_untagged(guest_addr)) {
31
+ if (!is_postidx && rm != 0) {
59
+ host_ptr_conv = g2h(thread_cpu, guest_addr);
32
+ unallocated_encoding(s);
60
+ if (host_ptr == host_ptr_conv) {
33
+ return;
61
return;
34
+ }
35
+
36
/* From the shared decode logic */
37
switch (opcode) {
38
case 0x0:
39
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)
40
}
62
}
41
63
if (len != 0) {
42
if (is_postidx) {
64
- memcpy(g2h_untagged(guest_addr), host_ptr, len);
43
- int rm = extract32(insn, 16, 5);
65
+ memcpy(host_ptr_conv, host_ptr, len);
44
if (rm == 31) {
66
}
45
tcg_gen_mov_i64(tcg_rn, tcg_addr);
67
g_free(host_ptr);
46
} else {
68
}
47
--
69
--
48
2.20.1
70
2.20.1
49
71
50
72
diff view generated by jsdifflib
1
From: Aaron Lindsay OS <aaron@os.amperecomputing.com>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Make PMU overflow interrupts more accurate by using a timer to predict
3
This is the prctl bit that controls whether syscalls accept tagged
4
when they will overflow rather than waiting for an event to occur which
4
addresses. See Documentation/arm64/tagged-address-abi.rst in the
5
allows us to otherwise check them.
5
linux kernel.
6
6
7
Signed-off-by: Aaron Lindsay <aaron@os.amperecomputing.com>
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20190124162401.5111-3-aaron@os.amperecomputing.com
9
Message-id: 20210212184902.1251044-21-richard.henderson@linaro.org
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
11
---
12
target/arm/cpu.h | 10 +++++++
12
linux-user/aarch64/target_syscall.h | 4 ++++
13
target/arm/cpu.c | 12 ++++++++
13
target/arm/cpu-param.h | 3 +++
14
target/arm/helper.c | 72 +++++++++++++++++++++++++++++++++++++++++++--
14
target/arm/cpu.h | 31 +++++++++++++++++++++++++++++
15
3 files changed, 92 insertions(+), 2 deletions(-)
15
linux-user/syscall.c | 24 ++++++++++++++++++++++
16
4 files changed, 62 insertions(+)
16
17
18
diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h
19
index XXXXXXX..XXXXXXX 100644
20
--- a/linux-user/aarch64/target_syscall.h
21
+++ b/linux-user/aarch64/target_syscall.h
22
@@ -XXX,XX +XXX,XX @@ struct target_pt_regs {
23
# define TARGET_PR_PAC_APDBKEY (1 << 3)
24
# define TARGET_PR_PAC_APGAKEY (1 << 4)
25
26
+#define TARGET_PR_SET_TAGGED_ADDR_CTRL 55
27
+#define TARGET_PR_GET_TAGGED_ADDR_CTRL 56
28
+# define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0)
29
+
30
#endif /* AARCH64_TARGET_SYSCALL_H */
31
diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h
32
index XXXXXXX..XXXXXXX 100644
33
--- a/target/arm/cpu-param.h
34
+++ b/target/arm/cpu-param.h
35
@@ -XXX,XX +XXX,XX @@
36
37
#ifdef CONFIG_USER_ONLY
38
#define TARGET_PAGE_BITS 12
39
+# ifdef TARGET_AARCH64
40
+# define TARGET_TAGGED_ADDRESSES
41
+# endif
42
#else
43
/*
44
* ARMv7 and later CPUs have 4K pages minimum, but ARMv5 and v6
17
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
45
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
18
index XXXXXXX..XXXXXXX 100644
46
index XXXXXXX..XXXXXXX 100644
19
--- a/target/arm/cpu.h
47
--- a/target/arm/cpu.h
20
+++ b/target/arm/cpu.h
48
+++ b/target/arm/cpu.h
21
@@ -XXX,XX +XXX,XX @@ struct ARMCPU {
49
@@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState {
22
50
const struct arm_boot_info *boot_info;
23
/* Timers used by the generic (architected) timer */
51
/* Store GICv3CPUState to access from this struct */
24
QEMUTimer *gt_timer[NUM_GTIMERS];
52
void *gicv3state;
25
+ /*
53
+
26
+ * Timer used by the PMU. Its state is restored after migration by
54
+#ifdef TARGET_TAGGED_ADDRESSES
27
+ * pmu_op_finish() - it does not need other handling during migration
55
+ /* Linux syscall tagged address support */
28
+ */
56
+ bool tagged_addr_enable;
29
+ QEMUTimer *pmu_timer;
57
+#endif
30
/* GPIO outputs for generic timer */
58
} CPUARMState;
31
qemu_irq gt_timer_outputs[NUM_GTIMERS];
59
32
/* GPIO output for GICv3 maintenance interrupt signal */
60
static inline void set_feature(CPUARMState *env, int feature)
33
@@ -XXX,XX +XXX,XX @@ void pmccntr_op_finish(CPUARMState *env);
61
@@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x)
34
void pmu_op_start(CPUARMState *env);
62
*/
35
void pmu_op_finish(CPUARMState *env);
63
#define PAGE_BTI PAGE_TARGET_1
36
64
37
+/*
65
+#ifdef TARGET_TAGGED_ADDRESSES
38
+ * Called when a PMU counter is due to overflow
66
+/**
67
+ * cpu_untagged_addr:
68
+ * @cs: CPU context
69
+ * @x: tagged address
70
+ *
71
+ * Remove any address tag from @x. This is explicitly related to the
72
+ * linux syscall TIF_TAGGED_ADDR setting, not TBI in general.
73
+ *
74
+ * There should be a better place to put this, but we need this in
75
+ * include/exec/cpu_ldst.h, and not some place linux-user specific.
39
+ */
76
+ */
40
+void arm_pmu_timer_cb(void *opaque);
77
+static inline target_ulong cpu_untagged_addr(CPUState *cs, target_ulong x)
41
+
78
+{
42
/**
79
+ ARMCPU *cpu = ARM_CPU(cs);
43
* Functions to register as EL change hooks for PMU mode filtering
80
+ if (cpu->env.tagged_addr_enable) {
44
*/
81
+ /*
45
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
82
+ * TBI is enabled for userspace but not kernelspace addresses.
46
index XXXXXXX..XXXXXXX 100644
83
+ * Only clear the tag if bit 55 is clear.
47
--- a/target/arm/cpu.c
84
+ */
48
+++ b/target/arm/cpu.c
85
+ x &= sextract64(x, 0, 56);
49
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_finalizefn(Object *obj)
50
QLIST_REMOVE(hook, node);
51
g_free(hook);
52
}
53
+#ifndef CONFIG_USER_ONLY
54
+ if (cpu->pmu_timer) {
55
+ timer_del(cpu->pmu_timer);
56
+ timer_deinit(cpu->pmu_timer);
57
+ timer_free(cpu->pmu_timer);
58
+ }
86
+ }
87
+ return x;
88
+}
59
+#endif
89
+#endif
60
}
61
62
static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
63
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
64
arm_register_pre_el_change_hook(cpu, &pmu_pre_el_change, 0);
65
arm_register_el_change_hook(cpu, &pmu_post_el_change, 0);
66
}
67
+
68
+#ifndef CONFIG_USER_ONLY
69
+ cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, arm_pmu_timer_cb,
70
+ cpu);
71
+#endif
72
} else {
73
cpu->id_aa64dfr0 &= ~0xf00;
74
cpu->pmceid0 = 0;
75
diff --git a/target/arm/helper.c b/target/arm/helper.c
76
index XXXXXXX..XXXXXXX 100644
77
--- a/target/arm/helper.c
78
+++ b/target/arm/helper.c
79
@@ -XXX,XX +XXX,XX @@ typedef struct pm_event {
80
* counters hold a difference from the return value from this function
81
*/
82
uint64_t (*get_count)(CPUARMState *);
83
+ /*
84
+ * Return how many nanoseconds it will take (at a minimum) for count events
85
+ * to occur. A negative value indicates the counter will never overflow, or
86
+ * that the counter has otherwise arranged for the overflow bit to be set
87
+ * and the PMU interrupt to be raised on overflow.
88
+ */
89
+ int64_t (*ns_per_count)(uint64_t);
90
} pm_event;
91
92
static bool event_always_supported(CPUARMState *env)
93
@@ -XXX,XX +XXX,XX @@ static uint64_t swinc_get_count(CPUARMState *env)
94
return 0;
95
}
96
97
+static int64_t swinc_ns_per(uint64_t ignored)
98
+{
99
+ return -1;
100
+}
101
+
90
+
102
/*
91
/*
103
* Return the underlying cycle count for the PMU cycle counters. If we're in
92
* Naming convention for isar_feature functions:
104
* usermode, simply return 0.
93
* Functions which test 32-bit ID registers should have _aa32_ in
105
@@ -XXX,XX +XXX,XX @@ static uint64_t cycles_get_count(CPUARMState *env)
94
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
106
}
95
index XXXXXXX..XXXXXXX 100644
107
96
--- a/linux-user/syscall.c
108
#ifndef CONFIG_USER_ONLY
97
+++ b/linux-user/syscall.c
109
+static int64_t cycles_ns_per(uint64_t cycles)
98
@@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
110
+{
99
}
111
+ return (ARM_CPU_FREQ / NANOSECONDS_PER_SECOND) * cycles;
100
}
112
+}
101
return -TARGET_EINVAL;
102
+ case TARGET_PR_SET_TAGGED_ADDR_CTRL:
103
+ {
104
+ abi_ulong valid_mask = TARGET_PR_TAGGED_ADDR_ENABLE;
105
+ CPUARMState *env = cpu_env;
113
+
106
+
114
static bool instructions_supported(CPUARMState *env)
107
+ if ((arg2 & ~valid_mask) || arg3 || arg4 || arg5) {
115
{
108
+ return -TARGET_EINVAL;
116
return use_icount == 1 /* Precise instruction counting */;
109
+ }
117
@@ -XXX,XX +XXX,XX @@ static uint64_t instructions_get_count(CPUARMState *env)
110
+ env->tagged_addr_enable = arg2 & TARGET_PR_TAGGED_ADDR_ENABLE;
118
{
111
+ return 0;
119
return (uint64_t)cpu_get_icount_raw();
112
+ }
120
}
113
+ case TARGET_PR_GET_TAGGED_ADDR_CTRL:
114
+ {
115
+ abi_long ret = 0;
116
+ CPUARMState *env = cpu_env;
121
+
117
+
122
+static int64_t instructions_ns_per(uint64_t icount)
118
+ if (arg2 || arg3 || arg4 || arg5) {
123
+{
119
+ return -TARGET_EINVAL;
124
+ return cpu_icount_to_ns((int64_t)icount);
120
+ }
125
+}
121
+ if (env->tagged_addr_enable) {
126
#endif
122
+ ret |= TARGET_PR_TAGGED_ADDR_ENABLE;
127
123
+ }
128
static const pm_event pm_events[] = {
124
+ return ret;
129
{ .number = 0x000, /* SW_INCR */
125
+ }
130
.supported = event_always_supported,
126
#endif /* AARCH64 */
131
.get_count = swinc_get_count,
127
case PR_GET_SECCOMP:
132
+ .ns_per_count = swinc_ns_per,
128
case PR_SET_SECCOMP:
133
},
134
#ifndef CONFIG_USER_ONLY
135
{ .number = 0x008, /* INST_RETIRED, Instruction architecturally executed */
136
.supported = instructions_supported,
137
.get_count = instructions_get_count,
138
+ .ns_per_count = instructions_ns_per,
139
},
140
{ .number = 0x011, /* CPU_CYCLES, Cycle */
141
.supported = event_always_supported,
142
.get_count = cycles_get_count,
143
+ .ns_per_count = cycles_ns_per,
144
}
145
#endif
146
};
147
@@ -XXX,XX +XXX,XX @@ void pmccntr_op_start(CPUARMState *env)
148
void pmccntr_op_finish(CPUARMState *env)
149
{
150
if (pmu_counter_enabled(env, 31)) {
151
- uint64_t prev_cycles = env->cp15.c15_ccnt_delta;
152
+#ifndef CONFIG_USER_ONLY
153
+ /* Calculate when the counter will next overflow */
154
+ uint64_t remaining_cycles = -env->cp15.c15_ccnt;
155
+ if (!(env->cp15.c9_pmcr & PMCRLC)) {
156
+ remaining_cycles = (uint32_t)remaining_cycles;
157
+ }
158
+ int64_t overflow_in = cycles_ns_per(remaining_cycles);
159
160
+ if (overflow_in > 0) {
161
+ int64_t overflow_at = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
162
+ overflow_in;
163
+ ARMCPU *cpu = arm_env_get_cpu(env);
164
+ timer_mod_anticipate_ns(cpu->pmu_timer, overflow_at);
165
+ }
166
+#endif
167
+
168
+ uint64_t prev_cycles = env->cp15.c15_ccnt_delta;
169
if (env->cp15.c9_pmcr & PMCRD) {
170
/* Increment once every 64 processor clock cycles */
171
prev_cycles /= 64;
172
}
173
-
174
env->cp15.c15_ccnt_delta = prev_cycles - env->cp15.c15_ccnt;
175
}
176
}
177
@@ -XXX,XX +XXX,XX @@ static void pmevcntr_op_start(CPUARMState *env, uint8_t counter)
178
static void pmevcntr_op_finish(CPUARMState *env, uint8_t counter)
179
{
180
if (pmu_counter_enabled(env, counter)) {
181
+#ifndef CONFIG_USER_ONLY
182
+ uint16_t event = env->cp15.c14_pmevtyper[counter] & PMXEVTYPER_EVTCOUNT;
183
+ uint16_t event_idx = supported_event_map[event];
184
+ uint64_t delta = UINT32_MAX -
185
+ (uint32_t)env->cp15.c14_pmevcntr[counter] + 1;
186
+ int64_t overflow_in = pm_events[event_idx].ns_per_count(delta);
187
+
188
+ if (overflow_in > 0) {
189
+ int64_t overflow_at = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
190
+ overflow_in;
191
+ ARMCPU *cpu = arm_env_get_cpu(env);
192
+ timer_mod_anticipate_ns(cpu->pmu_timer, overflow_at);
193
+ }
194
+#endif
195
+
196
env->cp15.c14_pmevcntr_delta[counter] -=
197
env->cp15.c14_pmevcntr[counter];
198
}
199
@@ -XXX,XX +XXX,XX @@ void pmu_post_el_change(ARMCPU *cpu, void *ignored)
200
pmu_op_finish(&cpu->env);
201
}
202
203
+void arm_pmu_timer_cb(void *opaque)
204
+{
205
+ ARMCPU *cpu = opaque;
206
+
207
+ /*
208
+ * Update all the counter values based on the current underlying counts,
209
+ * triggering interrupts to be raised, if necessary. pmu_op_finish() also
210
+ * has the effect of setting the cpu->pmu_timer to the next earliest time a
211
+ * counter may expire.
212
+ */
213
+ pmu_op_start(&cpu->env);
214
+ pmu_op_finish(&cpu->env);
215
+}
216
+
217
static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
218
uint64_t value)
219
{
220
--
129
--
221
2.20.1
130
2.20.1
222
131
223
132
diff view generated by jsdifflib
1
The "system instructions" and "system register move" subcategories
1
From: Richard Henderson <richard.henderson@linaro.org>
2
of "branches, exception generating and system instructions" for A64
3
only apply if bits [23:22] are zero; other values are currently
4
unallocated. Correctly UNDEF these unallocated encodings.
5
2
6
Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com>
3
Use simple arithmetic instead of a conditional
4
move when tbi0 != tbi1.
5
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210212184902.1251044-22-richard.henderson@linaro.org
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com>
9
Message-id: 20190125182626.9221-2-peter.maydell@linaro.org
10
---
10
---
11
target/arm/translate-a64.c | 6 +++++-
11
target/arm/translate-a64.c | 25 ++++++++++++++-----------
12
1 file changed, 5 insertions(+), 1 deletion(-)
12
1 file changed, 14 insertions(+), 11 deletions(-)
13
13
14
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
14
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
15
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/translate-a64.c
16
--- a/target/arm/translate-a64.c
17
+++ b/target/arm/translate-a64.c
17
+++ b/target/arm/translate-a64.c
18
@@ -XXX,XX +XXX,XX @@ static void disas_b_exc_sys(DisasContext *s, uint32_t insn)
18
@@ -XXX,XX +XXX,XX @@ static void gen_top_byte_ignore(DisasContext *s, TCGv_i64 dst,
19
break;
19
/* Sign-extend from bit 55. */
20
case 0x6a: /* Exception generation / System */
20
tcg_gen_sextract_i64(dst, src, 0, 56);
21
if (insn & (1 << 24)) {
21
22
- disas_system(s, insn);
22
- if (tbi != 3) {
23
+ if (extract32(insn, 22, 2) == 0) {
23
- TCGv_i64 tcg_zero = tcg_const_i64(0);
24
+ disas_system(s, insn);
24
-
25
+ } else {
25
- /*
26
+ unallocated_encoding(s);
26
- * The two TBI bits differ.
27
+ }
27
- * If tbi0, then !tbi1: only use the extension if positive.
28
} else {
28
- * if !tbi0, then tbi1: only use the extension if negative.
29
disas_exc(s, insn);
29
- */
30
- tcg_gen_movcond_i64(tbi == 1 ? TCG_COND_GE : TCG_COND_LT,
31
- dst, dst, tcg_zero, dst, src);
32
- tcg_temp_free_i64(tcg_zero);
33
+ switch (tbi) {
34
+ case 1:
35
+ /* tbi0 but !tbi1: only use the extension if positive */
36
+ tcg_gen_and_i64(dst, dst, src);
37
+ break;
38
+ case 2:
39
+ /* !tbi0 but tbi1: only use the extension if negative */
40
+ tcg_gen_or_i64(dst, dst, src);
41
+ break;
42
+ case 3:
43
+ /* tbi0 and tbi1: always use the extension */
44
+ break;
45
+ default:
46
+ g_assert_not_reached();
30
}
47
}
48
}
49
}
31
--
50
--
32
2.20.1
51
2.20.1
33
52
34
53
diff view generated by jsdifflib
1
From: Julia Suvorova <jusual@mail.ru>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Until now, the set_pc logic was unclear, which raised questions about
3
We were fudging TBI1 enabled to speed up the generated code.
4
whether it should be used directly, applying a value to PC or adding
4
Now that we've improved the code generation, remove this.
5
additional checks, for example, set the Thumb bit in Arm cpu. Let's set
5
Also, tidy the comment to reflect the current code.
6
the set_pc logic for “Configure the PC, as was done in the ELF file”
7
and implement synchronize_with_tb hook for preserving PC to cpu_tb_exec.
8
6
9
Signed-off-by: Julia Suvorova <jusual@mail.ru>
7
The pauth test was testing a kernel address (-1) and making
10
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
8
incorrect assumptions about TBI1; stick to userland addresses.
11
Message-id: 20190129121817.7109-1-jusual@mail.ru
9
12
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20210212184902.1251044-23-richard.henderson@linaro.org
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
14
---
15
include/qom/cpu.h | 16 ++++++++++++++--
15
target/arm/internals.h | 4 ++--
16
hw/arm/boot.c | 4 ----
16
target/arm/cpu.c | 10 +++-------
17
target/arm/arm-powerctl.c | 3 ---
17
tests/tcg/aarch64/pauth-2.c | 1 -
18
target/arm/cpu.c | 26 +++++++++++++++++++++++++-
18
3 files changed, 5 insertions(+), 10 deletions(-)
19
target/arm/cpu64.c | 15 ---------------
20
5 files changed, 39 insertions(+), 25 deletions(-)
21
19
22
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
20
diff --git a/target/arm/internals.h b/target/arm/internals.h
23
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
24
--- a/include/qom/cpu.h
22
--- a/target/arm/internals.h
25
+++ b/include/qom/cpu.h
23
+++ b/target/arm/internals.h
26
@@ -XXX,XX +XXX,XX @@ struct TranslationBlock;
24
@@ -XXX,XX +XXX,XX @@ static inline bool tcma_check(uint32_t desc, int bit55, int ptr_tag)
27
* @get_arch_id: Callback for getting architecture-dependent CPU ID.
25
*/
28
* @get_paging_enabled: Callback for inquiring whether paging is enabled.
26
static inline uint64_t useronly_clean_ptr(uint64_t ptr)
29
* @get_memory_mapping: Callback for obtaining the memory mappings.
27
{
30
- * @set_pc: Callback for setting the Program Counter register.
28
- /* TBI is known to be enabled. */
31
+ * @set_pc: Callback for setting the Program Counter register. This
29
#ifdef CONFIG_USER_ONLY
32
+ * should have the semantics used by the target architecture when
30
- ptr = sextract64(ptr, 0, 56);
33
+ * setting the PC from a source such as an ELF file entry point;
31
+ /* TBI0 is known to be enabled, while TBI1 is disabled. */
34
+ * for example on Arm it will also set the Thumb mode bit based
32
+ ptr &= sextract64(ptr, 0, 56);
35
+ * on the least significant bit of the new PC value.
33
#endif
36
+ * If the target behaviour here is anything other than "set
34
return ptr;
37
+ * the PC register to the value passed in" then the target must
35
}
38
+ * also implement the synchronize_from_tb hook.
39
* @synchronize_from_tb: Callback for synchronizing state from a TCG
40
- * #TranslationBlock.
41
+ * #TranslationBlock. This is called when we abandon execution
42
+ * of a TB before starting it, and must set all parts of the CPU
43
+ * state which the previous TB in the chain may not have updated.
44
+ * This always includes at least the program counter; some targets
45
+ * will need to do more. If this hook is not implemented then the
46
+ * default is to call @set_pc(tb->pc).
47
* @handle_mmu_fault: Callback for handling an MMU fault.
48
* @get_phys_page_debug: Callback for obtaining a physical address.
49
* @get_phys_page_attrs_debug: Callback for obtaining a physical address and the
50
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
51
index XXXXXXX..XXXXXXX 100644
52
--- a/hw/arm/boot.c
53
+++ b/hw/arm/boot.c
54
@@ -XXX,XX +XXX,XX @@ static void do_cpu_reset(void *opaque)
55
g_assert_not_reached();
56
}
57
58
- if (!env->aarch64) {
59
- env->thumb = info->entry & 1;
60
- entry &= 0xfffffffe;
61
- }
62
cpu_set_pc(cs, entry);
63
} else {
64
/* If we are booting Linux then we need to check whether we are
65
diff --git a/target/arm/arm-powerctl.c b/target/arm/arm-powerctl.c
66
index XXXXXXX..XXXXXXX 100644
67
--- a/target/arm/arm-powerctl.c
68
+++ b/target/arm/arm-powerctl.c
69
@@ -XXX,XX +XXX,XX @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state,
70
71
if (info->target_aa64) {
72
target_cpu->env.xregs[0] = info->context_id;
73
- target_cpu->env.thumb = false;
74
} else {
75
target_cpu->env.regs[0] = info->context_id;
76
- target_cpu->env.thumb = info->entry & 1;
77
- info->entry &= 0xfffffffe;
78
}
79
80
/* Start the new CPU at the requested address */
81
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
36
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
82
index XXXXXXX..XXXXXXX 100644
37
index XXXXXXX..XXXXXXX 100644
83
--- a/target/arm/cpu.c
38
--- a/target/arm/cpu.c
84
+++ b/target/arm/cpu.c
39
+++ b/target/arm/cpu.c
85
@@ -XXX,XX +XXX,XX @@
40
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev)
86
static void arm_cpu_set_pc(CPUState *cs, vaddr value)
41
env->vfp.zcr_el[1] = MIN(cpu->sve_max_vq - 1, 3);
42
}
43
/*
44
- * Enable TBI0 and TBI1. While the real kernel only enables TBI0,
45
- * turning on both here will produce smaller code and otherwise
46
- * make no difference to the user-level emulation.
47
- *
48
- * In sve_probe_page, we assume that this is set.
49
- * Do not modify this without other changes.
50
+ * Enable TBI0 but not TBI1.
51
+ * Note that this must match useronly_clean_ptr.
52
*/
53
- env->cp15.tcr_el[1].raw_tcr = (3ULL << 37);
54
+ env->cp15.tcr_el[1].raw_tcr = (1ULL << 37);
55
#else
56
/* Reset into the highest available EL */
57
if (arm_feature(env, ARM_FEATURE_EL3)) {
58
diff --git a/tests/tcg/aarch64/pauth-2.c b/tests/tcg/aarch64/pauth-2.c
59
index XXXXXXX..XXXXXXX 100644
60
--- a/tests/tcg/aarch64/pauth-2.c
61
+++ b/tests/tcg/aarch64/pauth-2.c
62
@@ -XXX,XX +XXX,XX @@ void do_test(uint64_t value)
63
int main()
87
{
64
{
88
ARMCPU *cpu = ARM_CPU(cs);
65
do_test(0);
89
+ CPUARMState *env = &cpu->env;
66
- do_test(-1);
90
67
do_test(0xda004acedeadbeefull);
91
- cpu->env.regs[15] = value;
68
return 0;
92
+ if (is_a64(env)) {
93
+ env->pc = value;
94
+ env->thumb = 0;
95
+ } else {
96
+ env->regs[15] = value & ~1;
97
+ env->thumb = value & 1;
98
+ }
99
+}
100
+
101
+static void arm_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
102
+{
103
+ ARMCPU *cpu = ARM_CPU(cs);
104
+ CPUARMState *env = &cpu->env;
105
+
106
+ /*
107
+ * It's OK to look at env for the current mode here, because it's
108
+ * never possible for an AArch64 TB to chain to an AArch32 TB.
109
+ */
110
+ if (is_a64(env)) {
111
+ env->pc = tb->pc;
112
+ } else {
113
+ env->regs[15] = tb->pc;
114
+ }
115
}
69
}
116
117
static bool arm_cpu_has_work(CPUState *cs)
118
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
119
cc->cpu_exec_interrupt = arm_cpu_exec_interrupt;
120
cc->dump_state = arm_cpu_dump_state;
121
cc->set_pc = arm_cpu_set_pc;
122
+ cc->synchronize_from_tb = arm_cpu_synchronize_from_tb;
123
cc->gdb_read_register = arm_cpu_gdb_read_register;
124
cc->gdb_write_register = arm_cpu_gdb_write_register;
125
#ifdef CONFIG_USER_ONLY
126
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
127
index XXXXXXX..XXXXXXX 100644
128
--- a/target/arm/cpu64.c
129
+++ b/target/arm/cpu64.c
130
@@ -XXX,XX +XXX,XX @@ static void aarch64_cpu_finalizefn(Object *obj)
131
{
132
}
133
134
-static void aarch64_cpu_set_pc(CPUState *cs, vaddr value)
135
-{
136
- ARMCPU *cpu = ARM_CPU(cs);
137
- /* It's OK to look at env for the current mode here, because it's
138
- * never possible for an AArch64 TB to chain to an AArch32 TB.
139
- * (Otherwise we would need to use synchronize_from_tb instead.)
140
- */
141
- if (is_a64(&cpu->env)) {
142
- cpu->env.pc = value;
143
- } else {
144
- cpu->env.regs[15] = value;
145
- }
146
-}
147
-
148
static gchar *aarch64_gdb_arch_name(CPUState *cs)
149
{
150
return g_strdup("aarch64");
151
@@ -XXX,XX +XXX,XX @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data)
152
CPUClass *cc = CPU_CLASS(oc);
153
154
cc->cpu_exec_interrupt = arm_cpu_exec_interrupt;
155
- cc->set_pc = aarch64_cpu_set_pc;
156
cc->gdb_read_register = aarch64_cpu_gdb_read_register;
157
cc->gdb_write_register = aarch64_cpu_gdb_write_register;
158
cc->gdb_num_core_regs = 34;
159
--
70
--
160
2.20.1
71
2.20.1
161
72
162
73
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Initialize the keys to a non-zero value on process start.
3
These prctl fields are required for the function of MTE.
4
4
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Message-id: 20210212184902.1251044-24-richard.henderson@linaro.org
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
---
9
---
9
linux-user/aarch64/target_syscall.h | 2 ++
10
linux-user/aarch64/target_syscall.h | 9 ++++++
10
linux-user/aarch64/cpu_loop.c | 31 +++++++++++++++++++++++++++--
11
linux-user/syscall.c | 43 +++++++++++++++++++++++++++++
11
2 files changed, 31 insertions(+), 2 deletions(-)
12
2 files changed, 52 insertions(+)
12
13
13
diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h
14
diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h
14
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
15
--- a/linux-user/aarch64/target_syscall.h
16
--- a/linux-user/aarch64/target_syscall.h
16
+++ b/linux-user/aarch64/target_syscall.h
17
+++ b/linux-user/aarch64/target_syscall.h
17
@@ -XXX,XX +XXX,XX @@ struct target_pt_regs {
18
@@ -XXX,XX +XXX,XX @@ struct target_pt_regs {
18
#define TARGET_PR_SVE_SET_VL 50
19
#define TARGET_PR_SET_TAGGED_ADDR_CTRL 55
19
#define TARGET_PR_SVE_GET_VL 51
20
#define TARGET_PR_GET_TAGGED_ADDR_CTRL 56
20
21
# define TARGET_PR_TAGGED_ADDR_ENABLE (1UL << 0)
21
+void arm_init_pauth_key(ARMPACKey *key);
22
+/* MTE tag check fault modes */
23
+# define TARGET_PR_MTE_TCF_SHIFT 1
24
+# define TARGET_PR_MTE_TCF_NONE (0UL << TARGET_PR_MTE_TCF_SHIFT)
25
+# define TARGET_PR_MTE_TCF_SYNC (1UL << TARGET_PR_MTE_TCF_SHIFT)
26
+# define TARGET_PR_MTE_TCF_ASYNC (2UL << TARGET_PR_MTE_TCF_SHIFT)
27
+# define TARGET_PR_MTE_TCF_MASK (3UL << TARGET_PR_MTE_TCF_SHIFT)
28
+/* MTE tag inclusion mask */
29
+# define TARGET_PR_MTE_TAG_SHIFT 3
30
+# define TARGET_PR_MTE_TAG_MASK (0xffffUL << TARGET_PR_MTE_TAG_SHIFT)
31
32
#endif /* AARCH64_TARGET_SYSCALL_H */
33
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
34
index XXXXXXX..XXXXXXX 100644
35
--- a/linux-user/syscall.c
36
+++ b/linux-user/syscall.c
37
@@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
38
{
39
abi_ulong valid_mask = TARGET_PR_TAGGED_ADDR_ENABLE;
40
CPUARMState *env = cpu_env;
41
+ ARMCPU *cpu = env_archcpu(env);
22
+
42
+
23
#endif /* AARCH64_TARGET_SYSCALL_H */
43
+ if (cpu_isar_feature(aa64_mte, cpu)) {
24
diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c
44
+ valid_mask |= TARGET_PR_MTE_TCF_MASK;
25
index XXXXXXX..XXXXXXX 100644
45
+ valid_mask |= TARGET_PR_MTE_TAG_MASK;
26
--- a/linux-user/aarch64/cpu_loop.c
46
+ }
27
+++ b/linux-user/aarch64/cpu_loop.c
47
28
@@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUARMState *env)
48
if ((arg2 & ~valid_mask) || arg3 || arg4 || arg5) {
29
}
49
return -TARGET_EINVAL;
30
}
50
}
31
51
env->tagged_addr_enable = arg2 & TARGET_PR_TAGGED_ADDR_ENABLE;
32
+static uint64_t arm_rand64(void)
33
+{
34
+ int shift = 64 - clz64(RAND_MAX);
35
+ int i, n = 64 / shift + (64 % shift != 0);
36
+ uint64_t ret = 0;
37
+
52
+
38
+ for (i = 0; i < n; i++) {
53
+ if (cpu_isar_feature(aa64_mte, cpu)) {
39
+ ret = (ret << shift) | rand();
54
+ switch (arg2 & TARGET_PR_MTE_TCF_MASK) {
40
+ }
55
+ case TARGET_PR_MTE_TCF_NONE:
41
+ return ret;
56
+ case TARGET_PR_MTE_TCF_SYNC:
42
+}
57
+ case TARGET_PR_MTE_TCF_ASYNC:
58
+ break;
59
+ default:
60
+ return -EINVAL;
61
+ }
43
+
62
+
44
+void arm_init_pauth_key(ARMPACKey *key)
63
+ /*
45
+{
64
+ * Write PR_MTE_TCF to SCTLR_EL1[TCF0].
46
+ key->lo = arm_rand64();
65
+ * Note that the syscall values are consistent with hw.
47
+ key->hi = arm_rand64();
66
+ */
48
+}
67
+ env->cp15.sctlr_el[1] =
68
+ deposit64(env->cp15.sctlr_el[1], 38, 2,
69
+ arg2 >> TARGET_PR_MTE_TCF_SHIFT);
49
+
70
+
50
void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
71
+ /*
51
{
72
+ * Write PR_MTE_TAG to GCR_EL1[Exclude].
52
- CPUState *cpu = ENV_GET_CPU(env);
73
+ * Note that the syscall uses an include mask,
53
- TaskState *ts = cpu->opaque;
74
+ * and hardware uses an exclude mask -- invert.
54
+ ARMCPU *cpu = arm_env_get_cpu(env);
75
+ */
55
+ CPUState *cs = CPU(cpu);
76
+ env->cp15.gcr_el1 =
56
+ TaskState *ts = cs->opaque;
77
+ deposit64(env->cp15.gcr_el1, 0, 16,
57
struct image_info *info = ts->info;
78
+ ~arg2 >> TARGET_PR_MTE_TAG_SHIFT);
58
int i;
79
+ arm_rebuild_hflags(env);
59
80
+ }
60
@@ -XXX,XX +XXX,XX @@ void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
81
return 0;
61
}
82
}
62
#endif
83
case TARGET_PR_GET_TAGGED_ADDR_CTRL:
63
84
{
64
+ if (cpu_isar_feature(aa64_pauth, cpu)) {
85
abi_long ret = 0;
65
+ arm_init_pauth_key(&env->apia_key);
86
CPUARMState *env = cpu_env;
66
+ arm_init_pauth_key(&env->apib_key);
87
+ ARMCPU *cpu = env_archcpu(env);
67
+ arm_init_pauth_key(&env->apda_key);
88
68
+ arm_init_pauth_key(&env->apdb_key);
89
if (arg2 || arg3 || arg4 || arg5) {
69
+ arm_init_pauth_key(&env->apga_key);
90
return -TARGET_EINVAL;
70
+ }
91
@@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
71
+
92
if (env->tagged_addr_enable) {
72
ts->stack_base = info->start_stack;
93
ret |= TARGET_PR_TAGGED_ADDR_ENABLE;
73
ts->heap_base = info->brk;
94
}
74
/* This will be filled in on the first SYS_HEAPINFO call. */
95
+ if (cpu_isar_feature(aa64_mte, cpu)) {
96
+ /* See above. */
97
+ ret |= (extract64(env->cp15.sctlr_el[1], 38, 2)
98
+ << TARGET_PR_MTE_TCF_SHIFT);
99
+ ret = deposit64(ret, TARGET_PR_MTE_TAG_SHIFT, 16,
100
+ ~env->cp15.gcr_el1);
101
+ }
102
return ret;
103
}
104
#endif /* AARCH64 */
75
--
105
--
76
2.20.1
106
2.20.1
77
107
78
108
diff view generated by jsdifflib
1
From: Remi Denis-Courmont <remi.denis.courmont@huawei.com>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Since QEMU does not support the ARMv8.2-LVA, Large Virtual Address,
3
Remember the PROT_MTE bit as PAGE_MTE/PAGE_TARGET_2.
4
extension (yet), the VA address space is 48-bits plus a sign bit. User
4
Otherwise this does not yet have effect.
5
mode can only handle the positive half of the address space, so that
6
makes a limit of 48 bits.
7
5
8
(With LVA, it would be 53 and 52 bits respectively.)
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
10
The incorrectly large address space conflicts with PAuth instructions,
8
Message-id: 20210212184902.1251044-25-richard.henderson@linaro.org
11
which use bits 48-54 and 56-63 for the pointer authentication code. This
12
also conflicts with (as yet unsupported by QEMU) data tagging and with
13
the ARMv8.5-MTE extension.
14
15
Signed-off-by: Remi Denis-Courmont <remi.denis.courmont@huawei.com>
16
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
10
---
19
target/arm/cpu.h | 2 +-
11
include/exec/cpu-all.h | 1 +
20
1 file changed, 1 insertion(+), 1 deletion(-)
12
linux-user/syscall_defs.h | 1 +
13
target/arm/cpu.h | 1 +
14
linux-user/mmap.c | 22 ++++++++++++++--------
15
4 files changed, 17 insertions(+), 8 deletions(-)
21
16
17
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
18
index XXXXXXX..XXXXXXX 100644
19
--- a/include/exec/cpu-all.h
20
+++ b/include/exec/cpu-all.h
21
@@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask;
22
#endif
23
/* Target-specific bits that will be used via page_get_flags(). */
24
#define PAGE_TARGET_1 0x0080
25
+#define PAGE_TARGET_2 0x0200
26
27
#if defined(CONFIG_USER_ONLY)
28
void page_dump(FILE *f);
29
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
30
index XXXXXXX..XXXXXXX 100644
31
--- a/linux-user/syscall_defs.h
32
+++ b/linux-user/syscall_defs.h
33
@@ -XXX,XX +XXX,XX @@ struct target_winsize {
34
35
#ifdef TARGET_AARCH64
36
#define TARGET_PROT_BTI 0x10
37
+#define TARGET_PROT_MTE 0x20
38
#endif
39
40
/* Common */
22
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
41
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
23
index XXXXXXX..XXXXXXX 100644
42
index XXXXXXX..XXXXXXX 100644
24
--- a/target/arm/cpu.h
43
--- a/target/arm/cpu.h
25
+++ b/target/arm/cpu.h
44
+++ b/target/arm/cpu.h
26
@@ -XXX,XX +XXX,XX @@ bool write_cpustate_to_list(ARMCPU *cpu);
45
@@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x)
27
46
* AArch64 usage of the PAGE_TARGET_* bits for linux-user.
28
#if defined(TARGET_AARCH64)
47
*/
29
# define TARGET_PHYS_ADDR_SPACE_BITS 48
48
#define PAGE_BTI PAGE_TARGET_1
30
-# define TARGET_VIRT_ADDR_SPACE_BITS 64
49
+#define PAGE_MTE PAGE_TARGET_2
31
+# define TARGET_VIRT_ADDR_SPACE_BITS 48
50
32
#else
51
#ifdef TARGET_TAGGED_ADDRESSES
33
# define TARGET_PHYS_ADDR_SPACE_BITS 40
52
/**
34
# define TARGET_VIRT_ADDR_SPACE_BITS 32
53
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
54
index XXXXXXX..XXXXXXX 100644
55
--- a/linux-user/mmap.c
56
+++ b/linux-user/mmap.c
57
@@ -XXX,XX +XXX,XX @@ static int validate_prot_to_pageflags(int *host_prot, int prot)
58
| (prot & PROT_EXEC ? PROT_READ : 0);
59
60
#ifdef TARGET_AARCH64
61
- /*
62
- * The PROT_BTI bit is only accepted if the cpu supports the feature.
63
- * Since this is the unusual case, don't bother checking unless
64
- * the bit has been requested. If set and valid, record the bit
65
- * within QEMU's page_flags.
66
- */
67
- if (prot & TARGET_PROT_BTI) {
68
+ {
69
ARMCPU *cpu = ARM_CPU(thread_cpu);
70
- if (cpu_isar_feature(aa64_bti, cpu)) {
71
+
72
+ /*
73
+ * The PROT_BTI bit is only accepted if the cpu supports the feature.
74
+ * Since this is the unusual case, don't bother checking unless
75
+ * the bit has been requested. If set and valid, record the bit
76
+ * within QEMU's page_flags.
77
+ */
78
+ if ((prot & TARGET_PROT_BTI) && cpu_isar_feature(aa64_bti, cpu)) {
79
valid |= TARGET_PROT_BTI;
80
page_flags |= PAGE_BTI;
81
}
82
+ /* Similarly for the PROT_MTE bit. */
83
+ if ((prot & TARGET_PROT_MTE) && cpu_isar_feature(aa64_mte, cpu)) {
84
+ valid |= TARGET_PROT_MTE;
85
+ page_flags |= PAGE_MTE;
86
+ }
87
}
88
#endif
89
35
--
90
--
36
2.20.1
91
2.20.1
37
92
38
93
diff view generated by jsdifflib
1
The Arm IoTKit was effectively the forerunner of a series of
1
From: Richard Henderson <richard.henderson@linaro.org>
2
subsystems for embedded SoCs, named the SSE-050, SSE-100 and SSE-200:
3
https://developer.arm.com/products/system-design/subsystems
4
These are generally quite similar, though later iterations have
5
extra devices that earlier ones do not.
6
2
7
We want to add a model of the SSE-200, which means refactoring the
3
Move everything related to syndromes to a new file,
8
IoTKit code into an abstract base class and subclasses (using the
4
which can be shared with linux-user.
9
same design that the bcm283x SoC and Aspeed SoC family
10
implementations do). As a first step, rename the IoTKit struct and
11
QOM macros to ARMSSE, which is what we're going to name the base
12
class. We temporarily retain TYPE_IOTKIT to avoid changing the
13
code that instantiates a TYPE_IOTKIT device here and then changing
14
it back again when it is re-introduced as a subclass.
15
5
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Message-id: 20210212184902.1251044-26-richard.henderson@linaro.org
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
18
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
19
Message-id: 20190121185118.18550-5-peter.maydell@linaro.org
20
---
11
---
21
include/hw/arm/iotkit.h | 22 ++++++++++-----
12
target/arm/internals.h | 245 +-----------------------------------
22
hw/arm/iotkit.c | 59 +++++++++++++++++++++--------------------
13
target/arm/syndrome.h | 273 +++++++++++++++++++++++++++++++++++++++++
23
hw/arm/mps2-tz.c | 2 +-
14
2 files changed, 274 insertions(+), 244 deletions(-)
24
3 files changed, 47 insertions(+), 36 deletions(-)
15
create mode 100644 target/arm/syndrome.h
25
16
26
diff --git a/include/hw/arm/iotkit.h b/include/hw/arm/iotkit.h
17
diff --git a/target/arm/internals.h b/target/arm/internals.h
27
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
28
--- a/include/hw/arm/iotkit.h
19
--- a/target/arm/internals.h
29
+++ b/include/hw/arm/iotkit.h
20
+++ b/target/arm/internals.h
30
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@
31
/*
22
#define TARGET_ARM_INTERNALS_H
32
- * ARM IoT Kit
23
33
+ * ARM SSE (Subsystems for Embedded): IoTKit
24
#include "hw/registerfields.h"
34
*
25
+#include "syndrome.h"
35
* Copyright (c) 2018 Linaro Limited
26
36
* Written by Peter Maydell
27
/* register banks for CPU modes */
28
#define BANK_USRSYS 0
29
@@ -XXX,XX +XXX,XX @@ static inline bool extended_addresses_enabled(CPUARMState *env)
30
(arm_feature(env, ARM_FEATURE_LPAE) && (tcr->raw_tcr & TTBCR_EAE));
31
}
32
33
-/* Valid Syndrome Register EC field values */
34
-enum arm_exception_class {
35
- EC_UNCATEGORIZED = 0x00,
36
- EC_WFX_TRAP = 0x01,
37
- EC_CP15RTTRAP = 0x03,
38
- EC_CP15RRTTRAP = 0x04,
39
- EC_CP14RTTRAP = 0x05,
40
- EC_CP14DTTRAP = 0x06,
41
- EC_ADVSIMDFPACCESSTRAP = 0x07,
42
- EC_FPIDTRAP = 0x08,
43
- EC_PACTRAP = 0x09,
44
- EC_CP14RRTTRAP = 0x0c,
45
- EC_BTITRAP = 0x0d,
46
- EC_ILLEGALSTATE = 0x0e,
47
- EC_AA32_SVC = 0x11,
48
- EC_AA32_HVC = 0x12,
49
- EC_AA32_SMC = 0x13,
50
- EC_AA64_SVC = 0x15,
51
- EC_AA64_HVC = 0x16,
52
- EC_AA64_SMC = 0x17,
53
- EC_SYSTEMREGISTERTRAP = 0x18,
54
- EC_SVEACCESSTRAP = 0x19,
55
- EC_INSNABORT = 0x20,
56
- EC_INSNABORT_SAME_EL = 0x21,
57
- EC_PCALIGNMENT = 0x22,
58
- EC_DATAABORT = 0x24,
59
- EC_DATAABORT_SAME_EL = 0x25,
60
- EC_SPALIGNMENT = 0x26,
61
- EC_AA32_FPTRAP = 0x28,
62
- EC_AA64_FPTRAP = 0x2c,
63
- EC_SERROR = 0x2f,
64
- EC_BREAKPOINT = 0x30,
65
- EC_BREAKPOINT_SAME_EL = 0x31,
66
- EC_SOFTWARESTEP = 0x32,
67
- EC_SOFTWARESTEP_SAME_EL = 0x33,
68
- EC_WATCHPOINT = 0x34,
69
- EC_WATCHPOINT_SAME_EL = 0x35,
70
- EC_AA32_BKPT = 0x38,
71
- EC_VECTORCATCH = 0x3a,
72
- EC_AA64_BKPT = 0x3c,
73
-};
74
-
75
-#define ARM_EL_EC_SHIFT 26
76
-#define ARM_EL_IL_SHIFT 25
77
-#define ARM_EL_ISV_SHIFT 24
78
-#define ARM_EL_IL (1 << ARM_EL_IL_SHIFT)
79
-#define ARM_EL_ISV (1 << ARM_EL_ISV_SHIFT)
80
-
81
-static inline uint32_t syn_get_ec(uint32_t syn)
82
-{
83
- return syn >> ARM_EL_EC_SHIFT;
84
-}
85
-
86
-/* Utility functions for constructing various kinds of syndrome value.
87
- * Note that in general we follow the AArch64 syndrome values; in a
88
- * few cases the value in HSR for exceptions taken to AArch32 Hyp
89
- * mode differs slightly, and we fix this up when populating HSR in
90
- * arm_cpu_do_interrupt_aarch32_hyp().
91
- * The exception is FP/SIMD access traps -- these report extra information
92
- * when taking an exception to AArch32. For those we include the extra coproc
93
- * and TA fields, and mask them out when taking the exception to AArch64.
94
- */
95
-static inline uint32_t syn_uncategorized(void)
96
-{
97
- return (EC_UNCATEGORIZED << ARM_EL_EC_SHIFT) | ARM_EL_IL;
98
-}
99
-
100
-static inline uint32_t syn_aa64_svc(uint32_t imm16)
101
-{
102
- return (EC_AA64_SVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff);
103
-}
104
-
105
-static inline uint32_t syn_aa64_hvc(uint32_t imm16)
106
-{
107
- return (EC_AA64_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff);
108
-}
109
-
110
-static inline uint32_t syn_aa64_smc(uint32_t imm16)
111
-{
112
- return (EC_AA64_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff);
113
-}
114
-
115
-static inline uint32_t syn_aa32_svc(uint32_t imm16, bool is_16bit)
116
-{
117
- return (EC_AA32_SVC << ARM_EL_EC_SHIFT) | (imm16 & 0xffff)
118
- | (is_16bit ? 0 : ARM_EL_IL);
119
-}
120
-
121
-static inline uint32_t syn_aa32_hvc(uint32_t imm16)
122
-{
123
- return (EC_AA32_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff);
124
-}
125
-
126
-static inline uint32_t syn_aa32_smc(void)
127
-{
128
- return (EC_AA32_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL;
129
-}
130
-
131
-static inline uint32_t syn_aa64_bkpt(uint32_t imm16)
132
-{
133
- return (EC_AA64_BKPT << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff);
134
-}
135
-
136
-static inline uint32_t syn_aa32_bkpt(uint32_t imm16, bool is_16bit)
137
-{
138
- return (EC_AA32_BKPT << ARM_EL_EC_SHIFT) | (imm16 & 0xffff)
139
- | (is_16bit ? 0 : ARM_EL_IL);
140
-}
141
-
142
-static inline uint32_t syn_aa64_sysregtrap(int op0, int op1, int op2,
143
- int crn, int crm, int rt,
144
- int isread)
145
-{
146
- return (EC_SYSTEMREGISTERTRAP << ARM_EL_EC_SHIFT) | ARM_EL_IL
147
- | (op0 << 20) | (op2 << 17) | (op1 << 14) | (crn << 10) | (rt << 5)
148
- | (crm << 1) | isread;
149
-}
150
-
151
-static inline uint32_t syn_cp14_rt_trap(int cv, int cond, int opc1, int opc2,
152
- int crn, int crm, int rt, int isread,
153
- bool is_16bit)
154
-{
155
- return (EC_CP14RTTRAP << ARM_EL_EC_SHIFT)
156
- | (is_16bit ? 0 : ARM_EL_IL)
157
- | (cv << 24) | (cond << 20) | (opc2 << 17) | (opc1 << 14)
158
- | (crn << 10) | (rt << 5) | (crm << 1) | isread;
159
-}
160
-
161
-static inline uint32_t syn_cp15_rt_trap(int cv, int cond, int opc1, int opc2,
162
- int crn, int crm, int rt, int isread,
163
- bool is_16bit)
164
-{
165
- return (EC_CP15RTTRAP << ARM_EL_EC_SHIFT)
166
- | (is_16bit ? 0 : ARM_EL_IL)
167
- | (cv << 24) | (cond << 20) | (opc2 << 17) | (opc1 << 14)
168
- | (crn << 10) | (rt << 5) | (crm << 1) | isread;
169
-}
170
-
171
-static inline uint32_t syn_cp14_rrt_trap(int cv, int cond, int opc1, int crm,
172
- int rt, int rt2, int isread,
173
- bool is_16bit)
174
-{
175
- return (EC_CP14RRTTRAP << ARM_EL_EC_SHIFT)
176
- | (is_16bit ? 0 : ARM_EL_IL)
177
- | (cv << 24) | (cond << 20) | (opc1 << 16)
178
- | (rt2 << 10) | (rt << 5) | (crm << 1) | isread;
179
-}
180
-
181
-static inline uint32_t syn_cp15_rrt_trap(int cv, int cond, int opc1, int crm,
182
- int rt, int rt2, int isread,
183
- bool is_16bit)
184
-{
185
- return (EC_CP15RRTTRAP << ARM_EL_EC_SHIFT)
186
- | (is_16bit ? 0 : ARM_EL_IL)
187
- | (cv << 24) | (cond << 20) | (opc1 << 16)
188
- | (rt2 << 10) | (rt << 5) | (crm << 1) | isread;
189
-}
190
-
191
-static inline uint32_t syn_fp_access_trap(int cv, int cond, bool is_16bit)
192
-{
193
- /* AArch32 FP trap or any AArch64 FP/SIMD trap: TA == 0 coproc == 0xa */
194
- return (EC_ADVSIMDFPACCESSTRAP << ARM_EL_EC_SHIFT)
195
- | (is_16bit ? 0 : ARM_EL_IL)
196
- | (cv << 24) | (cond << 20) | 0xa;
197
-}
198
-
199
-static inline uint32_t syn_simd_access_trap(int cv, int cond, bool is_16bit)
200
-{
201
- /* AArch32 SIMD trap: TA == 1 coproc == 0 */
202
- return (EC_ADVSIMDFPACCESSTRAP << ARM_EL_EC_SHIFT)
203
- | (is_16bit ? 0 : ARM_EL_IL)
204
- | (cv << 24) | (cond << 20) | (1 << 5);
205
-}
206
-
207
-static inline uint32_t syn_sve_access_trap(void)
208
-{
209
- return EC_SVEACCESSTRAP << ARM_EL_EC_SHIFT;
210
-}
211
-
212
-static inline uint32_t syn_pactrap(void)
213
-{
214
- return EC_PACTRAP << ARM_EL_EC_SHIFT;
215
-}
216
-
217
-static inline uint32_t syn_btitrap(int btype)
218
-{
219
- return (EC_BTITRAP << ARM_EL_EC_SHIFT) | btype;
220
-}
221
-
222
-static inline uint32_t syn_insn_abort(int same_el, int ea, int s1ptw, int fsc)
223
-{
224
- return (EC_INSNABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
225
- | ARM_EL_IL | (ea << 9) | (s1ptw << 7) | fsc;
226
-}
227
-
228
-static inline uint32_t syn_data_abort_no_iss(int same_el, int fnv,
229
- int ea, int cm, int s1ptw,
230
- int wnr, int fsc)
231
-{
232
- return (EC_DATAABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
233
- | ARM_EL_IL
234
- | (fnv << 10) | (ea << 9) | (cm << 8) | (s1ptw << 7)
235
- | (wnr << 6) | fsc;
236
-}
237
-
238
-static inline uint32_t syn_data_abort_with_iss(int same_el,
239
- int sas, int sse, int srt,
240
- int sf, int ar,
241
- int ea, int cm, int s1ptw,
242
- int wnr, int fsc,
243
- bool is_16bit)
244
-{
245
- return (EC_DATAABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
246
- | (is_16bit ? 0 : ARM_EL_IL)
247
- | ARM_EL_ISV | (sas << 22) | (sse << 21) | (srt << 16)
248
- | (sf << 15) | (ar << 14)
249
- | (ea << 9) | (cm << 8) | (s1ptw << 7) | (wnr << 6) | fsc;
250
-}
251
-
252
-static inline uint32_t syn_swstep(int same_el, int isv, int ex)
253
-{
254
- return (EC_SOFTWARESTEP << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
255
- | ARM_EL_IL | (isv << 24) | (ex << 6) | 0x22;
256
-}
257
-
258
-static inline uint32_t syn_watchpoint(int same_el, int cm, int wnr)
259
-{
260
- return (EC_WATCHPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
261
- | ARM_EL_IL | (cm << 8) | (wnr << 6) | 0x22;
262
-}
263
-
264
-static inline uint32_t syn_breakpoint(int same_el)
265
-{
266
- return (EC_BREAKPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
267
- | ARM_EL_IL | 0x22;
268
-}
269
-
270
-static inline uint32_t syn_wfx(int cv, int cond, int ti, bool is_16bit)
271
-{
272
- return (EC_WFX_TRAP << ARM_EL_EC_SHIFT) |
273
- (is_16bit ? 0 : (1 << ARM_EL_IL_SHIFT)) |
274
- (cv << 24) | (cond << 20) | ti;
275
-}
276
-
277
/* Update a QEMU watchpoint based on the information the guest has set in the
278
* DBGWCR<n>_EL1 and DBGWVR<n>_EL1 registers.
279
*/
280
diff --git a/target/arm/syndrome.h b/target/arm/syndrome.h
281
new file mode 100644
282
index XXXXXXX..XXXXXXX
283
--- /dev/null
284
+++ b/target/arm/syndrome.h
37
@@ -XXX,XX +XXX,XX @@
285
@@ -XXX,XX +XXX,XX @@
38
* (at your option) any later version.
39
*/
40
41
-/* This is a model of the Arm IoT Kit which is documented in
42
+/*
286
+/*
43
+ * This is a model of the Arm "Subsystems for Embedded" family of
287
+ * QEMU ARM CPU -- syndrome functions and types
44
+ * hardware, which include the IoT Kit and the SSE-050, SSE-100 and
288
+ *
45
+ * SSE-200. Currently we model only the Arm IoT Kit which is documented in
289
+ * Copyright (c) 2014 Linaro Ltd
46
* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
290
+ *
47
* It contains:
291
+ * This program is free software; you can redistribute it and/or
48
* a Cortex-M33
292
+ * modify it under the terms of the GNU General Public License
49
@@ -XXX,XX +XXX,XX @@
293
+ * as published by the Free Software Foundation; either version 2
50
#include "hw/or-irq.h"
294
+ * of the License, or (at your option) any later version.
51
#include "hw/core/split-irq.h"
295
+ *
52
296
+ * This program is distributed in the hope that it will be useful,
53
-#define TYPE_IOTKIT "iotkit"
297
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
54
-#define IOTKIT(obj) OBJECT_CHECK(IoTKit, (obj), TYPE_IOTKIT)
298
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55
+#define TYPE_ARMSSE "iotkit"
299
+ * GNU General Public License for more details.
56
+#define ARMSSE(obj) OBJECT_CHECK(ARMSSE, (obj), TYPE_ARMSSE)
300
+ *
301
+ * You should have received a copy of the GNU General Public License
302
+ * along with this program; if not, see
303
+ * <http://www.gnu.org/licenses/gpl-2.0.html>
304
+ *
305
+ * This header defines functions, types, etc which need to be shared
306
+ * between different source files within target/arm/ but which are
307
+ * private to it and not required by the rest of QEMU.
308
+ */
309
+
310
+#ifndef TARGET_ARM_SYNDROME_H
311
+#define TARGET_ARM_SYNDROME_H
312
+
313
+/* Valid Syndrome Register EC field values */
314
+enum arm_exception_class {
315
+ EC_UNCATEGORIZED = 0x00,
316
+ EC_WFX_TRAP = 0x01,
317
+ EC_CP15RTTRAP = 0x03,
318
+ EC_CP15RRTTRAP = 0x04,
319
+ EC_CP14RTTRAP = 0x05,
320
+ EC_CP14DTTRAP = 0x06,
321
+ EC_ADVSIMDFPACCESSTRAP = 0x07,
322
+ EC_FPIDTRAP = 0x08,
323
+ EC_PACTRAP = 0x09,
324
+ EC_CP14RRTTRAP = 0x0c,
325
+ EC_BTITRAP = 0x0d,
326
+ EC_ILLEGALSTATE = 0x0e,
327
+ EC_AA32_SVC = 0x11,
328
+ EC_AA32_HVC = 0x12,
329
+ EC_AA32_SMC = 0x13,
330
+ EC_AA64_SVC = 0x15,
331
+ EC_AA64_HVC = 0x16,
332
+ EC_AA64_SMC = 0x17,
333
+ EC_SYSTEMREGISTERTRAP = 0x18,
334
+ EC_SVEACCESSTRAP = 0x19,
335
+ EC_INSNABORT = 0x20,
336
+ EC_INSNABORT_SAME_EL = 0x21,
337
+ EC_PCALIGNMENT = 0x22,
338
+ EC_DATAABORT = 0x24,
339
+ EC_DATAABORT_SAME_EL = 0x25,
340
+ EC_SPALIGNMENT = 0x26,
341
+ EC_AA32_FPTRAP = 0x28,
342
+ EC_AA64_FPTRAP = 0x2c,
343
+ EC_SERROR = 0x2f,
344
+ EC_BREAKPOINT = 0x30,
345
+ EC_BREAKPOINT_SAME_EL = 0x31,
346
+ EC_SOFTWARESTEP = 0x32,
347
+ EC_SOFTWARESTEP_SAME_EL = 0x33,
348
+ EC_WATCHPOINT = 0x34,
349
+ EC_WATCHPOINT_SAME_EL = 0x35,
350
+ EC_AA32_BKPT = 0x38,
351
+ EC_VECTORCATCH = 0x3a,
352
+ EC_AA64_BKPT = 0x3c,
353
+};
354
+
355
+#define ARM_EL_EC_SHIFT 26
356
+#define ARM_EL_IL_SHIFT 25
357
+#define ARM_EL_ISV_SHIFT 24
358
+#define ARM_EL_IL (1 << ARM_EL_IL_SHIFT)
359
+#define ARM_EL_ISV (1 << ARM_EL_ISV_SHIFT)
360
+
361
+static inline uint32_t syn_get_ec(uint32_t syn)
362
+{
363
+ return syn >> ARM_EL_EC_SHIFT;
364
+}
57
+
365
+
58
+/*
366
+/*
59
+ * For the moment TYPE_IOTKIT is a synonym for TYPE_ARMSSE (and the
367
+ * Utility functions for constructing various kinds of syndrome value.
60
+ * latter's underlying name is left as "iotkit"); in a later
368
+ * Note that in general we follow the AArch64 syndrome values; in a
61
+ * commit it will become a subclass of TYPE_ARMSSE.
369
+ * few cases the value in HSR for exceptions taken to AArch32 Hyp
370
+ * mode differs slightly, and we fix this up when populating HSR in
371
+ * arm_cpu_do_interrupt_aarch32_hyp().
372
+ * The exception is FP/SIMD access traps -- these report extra information
373
+ * when taking an exception to AArch32. For those we include the extra coproc
374
+ * and TA fields, and mask them out when taking the exception to AArch64.
62
+ */
375
+ */
63
+#define TYPE_IOTKIT TYPE_ARMSSE
376
+static inline uint32_t syn_uncategorized(void)
64
377
+{
65
/* We have an IRQ splitter and an OR gate input for each external PPC
378
+ return (EC_UNCATEGORIZED << ARM_EL_EC_SHIFT) | ARM_EL_IL;
66
* and the 2 internal PPCs
379
+}
67
@@ -XXX,XX +XXX,XX @@
380
+
68
#define NUM_EXTERNAL_PPCS (IOTS_NUM_AHB_EXP_PPC + IOTS_NUM_APB_EXP_PPC)
381
+static inline uint32_t syn_aa64_svc(uint32_t imm16)
69
#define NUM_PPCS (NUM_EXTERNAL_PPCS + 2)
382
+{
70
383
+ return (EC_AA64_SVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff);
71
-typedef struct IoTKit {
384
+}
72
+typedef struct ARMSSE {
385
+
73
/*< private >*/
386
+static inline uint32_t syn_aa64_hvc(uint32_t imm16)
74
SysBusDevice parent_obj;
387
+{
75
388
+ return (EC_AA64_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff);
76
@@ -XXX,XX +XXX,XX @@ typedef struct IoTKit {
389
+}
77
MemoryRegion *board_memory;
390
+
78
uint32_t exp_numirq;
391
+static inline uint32_t syn_aa64_smc(uint32_t imm16)
79
uint32_t mainclk_frq;
392
+{
80
-} IoTKit;
393
+ return (EC_AA64_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff);
81
+} ARMSSE;
394
+}
82
395
+
83
#endif
396
+static inline uint32_t syn_aa32_svc(uint32_t imm16, bool is_16bit)
84
diff --git a/hw/arm/iotkit.c b/hw/arm/iotkit.c
397
+{
85
index XXXXXXX..XXXXXXX 100644
398
+ return (EC_AA32_SVC << ARM_EL_EC_SHIFT) | (imm16 & 0xffff)
86
--- a/hw/arm/iotkit.c
399
+ | (is_16bit ? 0 : ARM_EL_IL);
87
+++ b/hw/arm/iotkit.c
400
+}
88
@@ -XXX,XX +XXX,XX @@
401
+
89
/*
402
+static inline uint32_t syn_aa32_hvc(uint32_t imm16)
90
- * Arm IoT Kit
403
+{
91
+ * Arm SSE (Subsystems for Embedded): IoTKit
404
+ return (EC_AA32_HVC << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff);
92
*
405
+}
93
* Copyright (c) 2018 Linaro Limited
406
+
94
* Written by Peter Maydell
407
+static inline uint32_t syn_aa32_smc(void)
95
@@ -XXX,XX +XXX,XX @@
408
+{
96
/* Create an alias region of @size bytes starting at @base
409
+ return (EC_AA32_SMC << ARM_EL_EC_SHIFT) | ARM_EL_IL;
97
* which mirrors the memory starting at @orig.
410
+}
98
*/
411
+
99
-static void make_alias(IoTKit *s, MemoryRegion *mr, const char *name,
412
+static inline uint32_t syn_aa64_bkpt(uint32_t imm16)
100
+static void make_alias(ARMSSE *s, MemoryRegion *mr, const char *name,
413
+{
101
hwaddr base, hwaddr size, hwaddr orig)
414
+ return (EC_AA64_BKPT << ARM_EL_EC_SHIFT) | ARM_EL_IL | (imm16 & 0xffff);
102
{
415
+}
103
memory_region_init_alias(mr, NULL, name, &s->container, orig, size);
416
+
104
@@ -XXX,XX +XXX,XX @@ static void irq_status_forwarder(void *opaque, int n, int level)
417
+static inline uint32_t syn_aa32_bkpt(uint32_t imm16, bool is_16bit)
105
418
+{
106
static void nsccfg_handler(void *opaque, int n, int level)
419
+ return (EC_AA32_BKPT << ARM_EL_EC_SHIFT) | (imm16 & 0xffff)
107
{
420
+ | (is_16bit ? 0 : ARM_EL_IL);
108
- IoTKit *s = IOTKIT(opaque);
421
+}
109
+ ARMSSE *s = ARMSSE(opaque);
422
+
110
423
+static inline uint32_t syn_aa64_sysregtrap(int op0, int op1, int op2,
111
s->nsccfg = level;
424
+ int crn, int crm, int rt,
112
}
425
+ int isread)
113
426
+{
114
-static void iotkit_forward_ppc(IoTKit *s, const char *ppcname, int ppcnum)
427
+ return (EC_SYSTEMREGISTERTRAP << ARM_EL_EC_SHIFT) | ARM_EL_IL
115
+static void iotkit_forward_ppc(ARMSSE *s, const char *ppcname, int ppcnum)
428
+ | (op0 << 20) | (op2 << 17) | (op1 << 14) | (crn << 10) | (rt << 5)
116
{
429
+ | (crm << 1) | isread;
117
/* Each of the 4 AHB and 4 APB PPCs that might be present in a
430
+}
118
- * system using the IoTKit has a collection of control lines which
431
+
119
+ * system using the ARMSSE has a collection of control lines which
432
+static inline uint32_t syn_cp14_rt_trap(int cv, int cond, int opc1, int opc2,
120
* are provided by the security controller and which we want to
433
+ int crn, int crm, int rt, int isread,
121
- * expose as control lines on the IoTKit device itself, so the
434
+ bool is_16bit)
122
- * code using the IoTKit can wire them up to the PPCs.
435
+{
123
+ * expose as control lines on the ARMSSE device itself, so the
436
+ return (EC_CP14RTTRAP << ARM_EL_EC_SHIFT)
124
+ * code using the ARMSSE can wire them up to the PPCs.
437
+ | (is_16bit ? 0 : ARM_EL_IL)
125
*/
438
+ | (cv << 24) | (cond << 20) | (opc2 << 17) | (opc1 << 14)
126
SplitIRQ *splitter = &s->ppc_irq_splitter[ppcnum];
439
+ | (crn << 10) | (rt << 5) | (crm << 1) | isread;
127
DeviceState *iotkitdev = DEVICE(s);
440
+}
128
@@ -XXX,XX +XXX,XX @@ static void iotkit_forward_ppc(IoTKit *s, const char *ppcname, int ppcnum)
441
+
129
g_free(name);
442
+static inline uint32_t syn_cp15_rt_trap(int cv, int cond, int opc1, int opc2,
130
}
443
+ int crn, int crm, int rt, int isread,
131
444
+ bool is_16bit)
132
-static void iotkit_forward_sec_resp_cfg(IoTKit *s)
445
+{
133
+static void iotkit_forward_sec_resp_cfg(ARMSSE *s)
446
+ return (EC_CP15RTTRAP << ARM_EL_EC_SHIFT)
134
{
447
+ | (is_16bit ? 0 : ARM_EL_IL)
135
/* Forward the 3rd output from the splitter device as a
448
+ | (cv << 24) | (cond << 20) | (opc2 << 17) | (opc1 << 14)
136
* named GPIO output of the iotkit object.
449
+ | (crn << 10) | (rt << 5) | (crm << 1) | isread;
137
@@ -XXX,XX +XXX,XX @@ static void iotkit_forward_sec_resp_cfg(IoTKit *s)
450
+}
138
451
+
139
static void iotkit_init(Object *obj)
452
+static inline uint32_t syn_cp14_rrt_trap(int cv, int cond, int opc1, int crm,
140
{
453
+ int rt, int rt2, int isread,
141
- IoTKit *s = IOTKIT(obj);
454
+ bool is_16bit)
142
+ ARMSSE *s = ARMSSE(obj);
455
+{
143
int i;
456
+ return (EC_CP14RRTTRAP << ARM_EL_EC_SHIFT)
144
457
+ | (is_16bit ? 0 : ARM_EL_IL)
145
memory_region_init(&s->container, obj, "iotkit-container", UINT64_MAX);
458
+ | (cv << 24) | (cond << 20) | (opc1 << 16)
146
@@ -XXX,XX +XXX,XX @@ static void iotkit_init(Object *obj)
459
+ | (rt2 << 10) | (rt << 5) | (crm << 1) | isread;
147
460
+}
148
static void iotkit_exp_irq(void *opaque, int n, int level)
461
+
149
{
462
+static inline uint32_t syn_cp15_rrt_trap(int cv, int cond, int opc1, int crm,
150
- IoTKit *s = IOTKIT(opaque);
463
+ int rt, int rt2, int isread,
151
+ ARMSSE *s = ARMSSE(opaque);
464
+ bool is_16bit)
152
465
+{
153
qemu_set_irq(s->exp_irqs[n], level);
466
+ return (EC_CP15RRTTRAP << ARM_EL_EC_SHIFT)
154
}
467
+ | (is_16bit ? 0 : ARM_EL_IL)
155
468
+ | (cv << 24) | (cond << 20) | (opc1 << 16)
156
static void iotkit_mpcexp_status(void *opaque, int n, int level)
469
+ | (rt2 << 10) | (rt << 5) | (crm << 1) | isread;
157
{
470
+}
158
- IoTKit *s = IOTKIT(opaque);
471
+
159
+ ARMSSE *s = ARMSSE(opaque);
472
+static inline uint32_t syn_fp_access_trap(int cv, int cond, bool is_16bit)
160
qemu_set_irq(s->mpcexp_status_in[n], level);
473
+{
161
}
474
+ /* AArch32 FP trap or any AArch64 FP/SIMD trap: TA == 0 coproc == 0xa */
162
475
+ return (EC_ADVSIMDFPACCESSTRAP << ARM_EL_EC_SHIFT)
163
static void iotkit_realize(DeviceState *dev, Error **errp)
476
+ | (is_16bit ? 0 : ARM_EL_IL)
164
{
477
+ | (cv << 24) | (cond << 20) | 0xa;
165
- IoTKit *s = IOTKIT(dev);
478
+}
166
+ ARMSSE *s = ARMSSE(dev);
479
+
167
int i;
480
+static inline uint32_t syn_simd_access_trap(int cv, int cond, bool is_16bit)
168
MemoryRegion *mr;
481
+{
169
Error *err = NULL;
482
+ /* AArch32 SIMD trap: TA == 1 coproc == 0 */
170
@@ -XXX,XX +XXX,XX @@ static void iotkit_realize(DeviceState *dev, Error **errp)
483
+ return (EC_ADVSIMDFPACCESSTRAP << ARM_EL_EC_SHIFT)
171
* devices exist in both address spaces but with hard-wired security
484
+ | (is_16bit ? 0 : ARM_EL_IL)
172
* permissions that will cause the CPU to fault for non-secure accesses.
485
+ | (cv << 24) | (cond << 20) | (1 << 5);
173
*
486
+}
174
- * The IoTKit has an IDAU (Implementation Defined Access Unit),
487
+
175
+ * The ARMSSE has an IDAU (Implementation Defined Access Unit),
488
+static inline uint32_t syn_sve_access_trap(void)
176
* which specifies hard-wired security permissions for different
489
+{
177
- * areas of the physical address space. For the IoTKit IDAU, the
490
+ return EC_SVEACCESSTRAP << ARM_EL_EC_SHIFT;
178
+ * areas of the physical address space. For the ARMSSE IDAU, the
491
+}
179
* top 4 bits of the physical address are the IDAU region ID, and
492
+
180
* if bit 28 (ie the lowest bit of the ID) is 0 then this is an NS
493
+static inline uint32_t syn_pactrap(void)
181
* region, otherwise it is an S region.
494
+{
182
@@ -XXX,XX +XXX,XX @@ static void iotkit_realize(DeviceState *dev, Error **errp)
495
+ return EC_PACTRAP << ARM_EL_EC_SHIFT;
183
* 0x20000000..0x2007ffff 32KB FPGA block RAM
496
+}
184
* 0x30000000..0x3fffffff alias of 0x20000000..0x2fffffff
497
+
185
* 0x40000000..0x4000ffff base peripheral region 1
498
+static inline uint32_t syn_btitrap(int btype)
186
- * 0x40010000..0x4001ffff CPU peripherals (none for IoTKit)
499
+{
187
+ * 0x40010000..0x4001ffff CPU peripherals (none for ARMSSE)
500
+ return (EC_BTITRAP << ARM_EL_EC_SHIFT) | btype;
188
* 0x40020000..0x4002ffff system control element peripherals
501
+}
189
* 0x40080000..0x400fffff base peripheral region 2
502
+
190
* 0x50000000..0x5fffffff alias of 0x40000000..0x4fffffff
503
+static inline uint32_t syn_insn_abort(int same_el, int ea, int s1ptw, int fsc)
191
@@ -XXX,XX +XXX,XX @@ static void iotkit_realize(DeviceState *dev, Error **errp)
504
+{
192
qdev_connect_gpio_out_named(dev_secctl, "nsc_cfg", 0, s->nsc_cfg_in);
505
+ return (EC_INSNABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
193
506
+ | ARM_EL_IL | (ea << 9) | (s1ptw << 7) | fsc;
194
/* The sec_resp_cfg output from the security controller must be split into
507
+}
195
- * multiple lines, one for each of the PPCs within the IoTKit and one
508
+
196
- * that will be an output from the IoTKit to the system.
509
+static inline uint32_t syn_data_abort_no_iss(int same_el, int fnv,
197
+ * multiple lines, one for each of the PPCs within the ARMSSE and one
510
+ int ea, int cm, int s1ptw,
198
+ * that will be an output from the ARMSSE to the system.
511
+ int wnr, int fsc)
199
*/
512
+{
200
object_property_set_int(OBJECT(&s->sec_resp_splitter), 3,
513
+ return (EC_DATAABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
201
"num-lines", &err);
514
+ | ARM_EL_IL
202
@@ -XXX,XX +XXX,XX @@ static void iotkit_realize(DeviceState *dev, Error **errp)
515
+ | (fnv << 10) | (ea << 9) | (cm << 8) | (s1ptw << 7)
203
516
+ | (wnr << 6) | fsc;
204
/* 0x40010000 .. 0x4001ffff: private CPU region: unused in IoTKit */
517
+}
205
518
+
206
- /* 0x40020000 .. 0x4002ffff : IoTKit system control peripheral region */
519
+static inline uint32_t syn_data_abort_with_iss(int same_el,
207
+ /* 0x40020000 .. 0x4002ffff : ARMSSE system control peripheral region */
520
+ int sas, int sse, int srt,
208
/* Devices behind APB PPC1:
521
+ int sf, int ar,
209
* 0x4002f000: S32K timer
522
+ int ea, int cm, int s1ptw,
210
*/
523
+ int wnr, int fsc,
211
@@ -XXX,XX +XXX,XX @@ static void iotkit_realize(DeviceState *dev, Error **errp)
524
+ bool is_16bit)
212
qdev_get_gpio_in(DEVICE(&s->nmi_orgate), 0));
525
+{
213
sysbus_mmio_map(SYS_BUS_DEVICE(&s->s32kwatchdog), 0, 0x5002e000);
526
+ return (EC_DATAABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
214
527
+ | (is_16bit ? 0 : ARM_EL_IL)
215
- /* 0x40080000 .. 0x4008ffff : IoTKit second Base peripheral region */
528
+ | ARM_EL_ISV | (sas << 22) | (sse << 21) | (srt << 16)
216
+ /* 0x40080000 .. 0x4008ffff : ARMSSE second Base peripheral region */
529
+ | (sf << 15) | (ar << 14)
217
530
+ | (ea << 9) | (cm << 8) | (s1ptw << 7) | (wnr << 6) | fsc;
218
qdev_prop_set_uint32(DEVICE(&s->nswatchdog), "wdogclk-frq", s->mainclk_frq);
531
+}
219
object_property_set_bool(OBJECT(&s->nswatchdog), true, "realized", &err);
532
+
220
@@ -XXX,XX +XXX,XX @@ static void iotkit_realize(DeviceState *dev, Error **errp)
533
+static inline uint32_t syn_swstep(int same_el, int isv, int ex)
221
* Expose our container region to the board model; this corresponds
534
+{
222
* to the AHB Slave Expansion ports which allow bus master devices
535
+ return (EC_SOFTWARESTEP << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
223
* (eg DMA controllers) in the board model to make transactions into
536
+ | ARM_EL_IL | (isv << 24) | (ex << 6) | 0x22;
224
- * devices in the IoTKit.
537
+}
225
+ * devices in the ARMSSE.
538
+
226
*/
539
+static inline uint32_t syn_watchpoint(int same_el, int cm, int wnr)
227
sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->container);
540
+{
228
541
+ return (EC_WATCHPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
229
@@ -XXX,XX +XXX,XX @@ static void iotkit_realize(DeviceState *dev, Error **errp)
542
+ | ARM_EL_IL | (cm << 8) | (wnr << 6) | 0x22;
230
static void iotkit_idau_check(IDAUInterface *ii, uint32_t address,
543
+}
231
int *iregion, bool *exempt, bool *ns, bool *nsc)
544
+
232
{
545
+static inline uint32_t syn_breakpoint(int same_el)
233
- /* For IoTKit systems the IDAU responses are simple logical functions
546
+{
234
+ /*
547
+ return (EC_BREAKPOINT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT)
235
+ * For ARMSSE systems the IDAU responses are simple logical functions
548
+ | ARM_EL_IL | 0x22;
236
* of the address bits. The NSC attribute is guest-adjustable via the
549
+}
237
* NSCCFG register in the security controller.
550
+
238
*/
551
+static inline uint32_t syn_wfx(int cv, int cond, int ti, bool is_16bit)
239
- IoTKit *s = IOTKIT(ii);
552
+{
240
+ ARMSSE *s = ARMSSE(ii);
553
+ return (EC_WFX_TRAP << ARM_EL_EC_SHIFT) |
241
int region = extract32(address, 28, 4);
554
+ (is_16bit ? 0 : (1 << ARM_EL_IL_SHIFT)) |
242
555
+ (cv << 24) | (cond << 20) | ti;
243
*ns = !(region & 1);
556
+}
244
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription iotkit_vmstate = {
557
+
245
.version_id = 1,
558
+#endif /* TARGET_ARM_SYNDROME_H */
246
.minimum_version_id = 1,
247
.fields = (VMStateField[]) {
248
- VMSTATE_UINT32(nsccfg, IoTKit),
249
+ VMSTATE_UINT32(nsccfg, ARMSSE),
250
VMSTATE_END_OF_LIST()
251
}
252
};
253
254
static Property iotkit_properties[] = {
255
- DEFINE_PROP_LINK("memory", IoTKit, board_memory, TYPE_MEMORY_REGION,
256
+ DEFINE_PROP_LINK("memory", ARMSSE, board_memory, TYPE_MEMORY_REGION,
257
MemoryRegion *),
258
- DEFINE_PROP_UINT32("EXP_NUMIRQ", IoTKit, exp_numirq, 64),
259
- DEFINE_PROP_UINT32("MAINCLK", IoTKit, mainclk_frq, 0),
260
+ DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE, exp_numirq, 64),
261
+ DEFINE_PROP_UINT32("MAINCLK", ARMSSE, mainclk_frq, 0),
262
DEFINE_PROP_END_OF_LIST()
263
};
264
265
static void iotkit_reset(DeviceState *dev)
266
{
267
- IoTKit *s = IOTKIT(dev);
268
+ ARMSSE *s = ARMSSE(dev);
269
270
s->nsccfg = 0;
271
}
272
@@ -XXX,XX +XXX,XX @@ static void iotkit_class_init(ObjectClass *klass, void *data)
273
}
274
275
static const TypeInfo iotkit_info = {
276
- .name = TYPE_IOTKIT,
277
+ .name = TYPE_ARMSSE,
278
.parent = TYPE_SYS_BUS_DEVICE,
279
- .instance_size = sizeof(IoTKit),
280
+ .instance_size = sizeof(ARMSSE),
281
.instance_init = iotkit_init,
282
.class_init = iotkit_class_init,
283
.interfaces = (InterfaceInfo[]) {
284
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
285
index XXXXXXX..XXXXXXX 100644
286
--- a/hw/arm/mps2-tz.c
287
+++ b/hw/arm/mps2-tz.c
288
@@ -XXX,XX +XXX,XX @@ typedef struct {
289
typedef struct {
290
MachineState parent;
291
292
- IoTKit iotkit;
293
+ ARMSSE iotkit;
294
MemoryRegion psram;
295
MemoryRegion ssram[3];
296
MemoryRegion ssram1_m;
297
--
559
--
298
2.20.1
560
2.20.1
299
561
300
562
diff view generated by jsdifflib
1
The SSE-200 has a "CPU local security control" register bank; add an
1
From: Richard Henderson <richard.henderson@linaro.org>
2
unimplemented-device stub for it. (The register bank has only one
3
interesting register, which allows the guest to lock down changes
4
to various CPU registers so they cannot be modified further. We
5
don't support that in our Cortex-M33 model anyway.)
6
2
3
A proper syndrome is required to fill in the proper si_code.
4
Use page_get_flags to determine permission vs translation for user-only.
5
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210212184902.1251044-27-richard.henderson@linaro.org
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20190121185118.18550-19-peter.maydell@linaro.org
10
---
10
---
11
include/hw/arm/armsse.h | 1 +
11
linux-user/aarch64/cpu_loop.c | 24 +++++++++++++++++++++---
12
hw/arm/armsse.c | 31 +++++++++++++++++++++++++++++++
12
target/arm/tlb_helper.c | 15 +++++++++------
13
2 files changed, 32 insertions(+)
13
2 files changed, 30 insertions(+), 9 deletions(-)
14
14
15
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
15
diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c
16
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
17
--- a/include/hw/arm/armsse.h
17
--- a/linux-user/aarch64/cpu_loop.c
18
+++ b/include/hw/arm/armsse.h
18
+++ b/linux-user/aarch64/cpu_loop.c
19
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
19
@@ -XXX,XX +XXX,XX @@
20
UnimplementedDeviceState mhu[2];
20
#include "cpu_loop-common.h"
21
UnimplementedDeviceState ppu[NUM_PPUS];
21
#include "qemu/guest-random.h"
22
UnimplementedDeviceState cachectrl[SSE_MAX_CPUS];
22
#include "hw/semihosting/common-semi.h"
23
+ UnimplementedDeviceState cpusecctrl[SSE_MAX_CPUS];
23
+#include "target/arm/syndrome.h"
24
24
25
/*
25
#define get_user_code_u32(x, gaddr, env) \
26
* 'container' holds all devices seen by all CPUs.
26
({ abi_long __r = get_user_u32((x), (gaddr)); \
27
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
27
@@ -XXX,XX +XXX,XX @@
28
index XXXXXXX..XXXXXXX 100644
28
void cpu_loop(CPUARMState *env)
29
--- a/hw/arm/armsse.c
29
{
30
+++ b/hw/arm/armsse.c
30
CPUState *cs = env_cpu(env);
31
@@ -XXX,XX +XXX,XX @@ struct ARMSSEInfo {
31
- int trapnr;
32
bool has_mhus;
32
+ int trapnr, ec, fsc;
33
bool has_ppus;
33
abi_long ret;
34
bool has_cachectrl;
34
target_siginfo_t info;
35
+ bool has_cpusecctrl;
35
36
};
36
@@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUARMState *env)
37
37
case EXCP_DATA_ABORT:
38
static const ARMSSEInfo armsse_variants[] = {
38
info.si_signo = TARGET_SIGSEGV;
39
@@ -XXX,XX +XXX,XX @@ static const ARMSSEInfo armsse_variants[] = {
39
info.si_errno = 0;
40
.has_mhus = false,
40
- /* XXX: check env->error_code */
41
.has_ppus = false,
41
- info.si_code = TARGET_SEGV_MAPERR;
42
.has_cachectrl = false,
42
info._sifields._sigfault._addr = env->exception.vaddress;
43
+ .has_cpusecctrl = false,
44
},
45
};
46
47
@@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj)
48
g_free(name);
49
}
50
}
51
+ if (info->has_cpusecctrl) {
52
+ for (i = 0; i < info->num_cpus; i++) {
53
+ char *name = g_strdup_printf("cpusecctrl%d", i);
54
+
43
+
55
+ sysbus_init_child_obj(obj, name, &s->cpusecctrl[i],
44
+ /* We should only arrive here with EC in {DATAABORT, INSNABORT}. */
56
+ sizeof(s->cpusecctrl[i]),
45
+ ec = syn_get_ec(env->exception.syndrome);
57
+ TYPE_UNIMPLEMENTED_DEVICE);
46
+ assert(ec == EC_DATAABORT || ec == EC_INSNABORT);
58
+ g_free(name);
59
+ }
60
+ }
61
object_initialize_child(obj, "nmi-orgate", &s->nmi_orgate,
62
sizeof(s->nmi_orgate), TYPE_OR_IRQ,
63
&error_abort, NULL);
64
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
65
memory_region_add_subregion(&s->cpu_container[i], 0x50010000, mr);
66
}
67
}
68
+ if (info->has_cpusecctrl) {
69
+ for (i = 0; i < info->num_cpus; i++) {
70
+ char *name = g_strdup_printf("CPUSECCTRL%d", i);
71
+ MemoryRegion *mr;
72
+
47
+
73
+ qdev_prop_set_string(DEVICE(&s->cpusecctrl[i]), "name", name);
48
+ /* Both EC have the same format for FSC, or close enough. */
74
+ g_free(name);
49
+ fsc = extract32(env->exception.syndrome, 0, 6);
75
+ qdev_prop_set_uint64(DEVICE(&s->cpusecctrl[i]), "size", 0x1000);
50
+ switch (fsc) {
76
+ object_property_set_bool(OBJECT(&s->cpusecctrl[i]), true,
51
+ case 0x04 ... 0x07: /* Translation fault, level {0-3} */
77
+ "realized", &err);
52
+ info.si_code = TARGET_SEGV_MAPERR;
78
+ if (err) {
53
+ break;
79
+ error_propagate(errp, err);
54
+ case 0x09 ... 0x0b: /* Access flag fault, level {1-3} */
80
+ return;
55
+ case 0x0d ... 0x0f: /* Permission fault, level {1-3} */
56
+ info.si_code = TARGET_SEGV_ACCERR;
57
+ break;
58
+ default:
59
+ g_assert_not_reached();
81
+ }
60
+ }
82
+
61
+
83
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpusecctrl[i]), 0);
62
queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
84
+ memory_region_add_subregion(&s->cpu_container[i], 0x50011000, mr);
63
break;
85
+ }
64
case EXCP_DEBUG:
86
+ }
65
diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c
87
66
index XXXXXXX..XXXXXXX 100644
88
/* 0x40020000 .. 0x4002ffff : ARMSSE system control peripheral region */
67
--- a/target/arm/tlb_helper.c
89
/* Devices behind APB PPC1:
68
+++ b/target/arm/tlb_helper.c
69
@@ -XXX,XX +XXX,XX @@ bool arm_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
70
bool probe, uintptr_t retaddr)
71
{
72
ARMCPU *cpu = ARM_CPU(cs);
73
+ ARMMMUFaultInfo fi = {};
74
75
#ifdef CONFIG_USER_ONLY
76
- cpu->env.exception.vaddress = address;
77
- if (access_type == MMU_INST_FETCH) {
78
- cs->exception_index = EXCP_PREFETCH_ABORT;
79
+ int flags = page_get_flags(useronly_clean_ptr(address));
80
+ if (flags & PAGE_VALID) {
81
+ fi.type = ARMFault_Permission;
82
} else {
83
- cs->exception_index = EXCP_DATA_ABORT;
84
+ fi.type = ARMFault_Translation;
85
}
86
- cpu_loop_exit_restore(cs, retaddr);
87
+
88
+ /* now we have a real cpu fault */
89
+ cpu_restore_state(cs, retaddr, true);
90
+ arm_deliver_fault(cpu, address, access_type, mmu_idx, &fi);
91
#else
92
hwaddr phys_addr;
93
target_ulong page_size;
94
int prot, ret;
95
MemTxAttrs attrs = {};
96
- ARMMMUFaultInfo fi = {};
97
ARMCacheAttrs cacheattrs = {};
98
99
/*
90
--
100
--
91
2.20.1
101
2.20.1
92
102
93
103
diff view generated by jsdifflib
1
The PRFM prefetch insn in the load/store with imm9 encodings
1
From: Richard Henderson <richard.henderson@linaro.org>
2
requires idx field 0b00; we were underdecoding this by
3
only checking !is_unpriv (which is equivalent to idx != 2).
4
Correctly UNDEF the unallocated encodings where idx == 0b01
5
and 0b11 as well as 0b10.
6
2
7
Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com>
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-id: 20210212184902.1251044-28-richard.henderson@linaro.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com>
10
Message-id: 20190125182626.9221-3-peter.maydell@linaro.org
11
---
7
---
12
target/arm/translate-a64.c | 2 +-
8
linux-user/aarch64/target_signal.h | 2 ++
13
1 file changed, 1 insertion(+), 1 deletion(-)
9
linux-user/aarch64/cpu_loop.c | 3 +++
10
2 files changed, 5 insertions(+)
14
11
15
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
12
diff --git a/linux-user/aarch64/target_signal.h b/linux-user/aarch64/target_signal.h
16
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/translate-a64.c
14
--- a/linux-user/aarch64/target_signal.h
18
+++ b/target/arm/translate-a64.c
15
+++ b/linux-user/aarch64/target_signal.h
19
@@ -XXX,XX +XXX,XX @@ static void disas_ldst_reg_imm9(DisasContext *s, uint32_t insn,
16
@@ -XXX,XX +XXX,XX @@ typedef struct target_sigaltstack {
20
} else {
17
21
if (size == 3 && opc == 2) {
18
#include "../generic/signal.h"
22
/* PRFM - prefetch */
19
23
- if (is_unpriv) {
20
+#define TARGET_SEGV_MTESERR 9 /* Synchronous ARM MTE exception */
24
+ if (idx != 0) {
21
+
25
unallocated_encoding(s);
22
#define TARGET_ARCH_HAS_SETUP_FRAME
26
return;
23
#endif /* AARCH64_TARGET_SIGNAL_H */
24
diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c
25
index XXXXXXX..XXXXXXX 100644
26
--- a/linux-user/aarch64/cpu_loop.c
27
+++ b/linux-user/aarch64/cpu_loop.c
28
@@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUARMState *env)
29
case 0x0d ... 0x0f: /* Permission fault, level {1-3} */
30
info.si_code = TARGET_SEGV_ACCERR;
31
break;
32
+ case 0x11: /* Synchronous Tag Check Fault */
33
+ info.si_code = TARGET_SEGV_MTESERR;
34
+ break;
35
default:
36
g_assert_not_reached();
27
}
37
}
28
--
38
--
29
2.20.1
39
2.20.1
30
40
31
41
diff view generated by jsdifflib
1
From: Aaron Lindsay OS <aaron@os.amperecomputing.com>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Whenever we notice that a counter overflow has occurred, send an
3
The real kernel collects _TIF_MTE_ASYNC_FAULT into the current thread's
4
interrupt. This is made more reliable with the addition of a timer in a
4
state on any kernel entry (interrupt, exception etc), and then delivers
5
follow-on commit.
5
the signal in advance of resuming the thread.
6
6
7
Signed-off-by: Aaron Lindsay <aaron@os.amperecomputing.com>
7
This means that while the signal won't be delivered immediately, it will
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
not be delayed forever -- at minimum it will be delivered after the next
9
Message-id: 20190124162401.5111-2-aaron@os.amperecomputing.com
9
clock interrupt.
10
11
We don't have a clock interrupt in linux-user, so we issue a cpu_kick
12
to signal a return to the main loop at the end of the current TB.
13
14
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
16
Message-id: 20210212184902.1251044-29-richard.henderson@linaro.org
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
18
---
12
target/arm/helper.c | 61 +++++++++++++++++++++++++++++++++++++--------
19
linux-user/aarch64/target_signal.h | 1 +
13
1 file changed, 51 insertions(+), 10 deletions(-)
20
linux-user/aarch64/cpu_loop.c | 11 +++++++++++
21
target/arm/mte_helper.c | 10 ++++++++++
22
3 files changed, 22 insertions(+)
14
23
15
diff --git a/target/arm/helper.c b/target/arm/helper.c
24
diff --git a/linux-user/aarch64/target_signal.h b/linux-user/aarch64/target_signal.h
16
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/helper.c
26
--- a/linux-user/aarch64/target_signal.h
18
+++ b/target/arm/helper.c
27
+++ b/linux-user/aarch64/target_signal.h
19
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v6_cp_reginfo[] = {
28
@@ -XXX,XX +XXX,XX @@ typedef struct target_sigaltstack {
20
/* Definitions for the PMU registers */
29
21
#define PMCRN_MASK 0xf800
30
#include "../generic/signal.h"
22
#define PMCRN_SHIFT 11
31
23
+#define PMCRLC 0x40
32
+#define TARGET_SEGV_MTEAERR 8 /* Asynchronous ARM MTE error */
24
#define PMCRDP 0x10
33
#define TARGET_SEGV_MTESERR 9 /* Synchronous ARM MTE exception */
25
#define PMCRD 0x8
34
26
#define PMCRC 0x4
35
#define TARGET_ARCH_HAS_SETUP_FRAME
27
@@ -XXX,XX +XXX,XX @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter)
36
diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c
28
return enabled && !prohibited && !filtered;
37
index XXXXXXX..XXXXXXX 100644
29
}
38
--- a/linux-user/aarch64/cpu_loop.c
30
39
+++ b/linux-user/aarch64/cpu_loop.c
31
+static void pmu_update_irq(CPUARMState *env)
40
@@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUARMState *env)
32
+{
41
EXCP_DUMP(env, "qemu: unhandled CPU exception 0x%x - aborting\n", trapnr);
33
+ ARMCPU *cpu = arm_env_get_cpu(env);
42
abort();
34
+ qemu_set_irq(cpu->pmu_interrupt, (env->cp15.c9_pmcr & PMCRE) &&
43
}
35
+ (env->cp15.c9_pminten & env->cp15.c9_pmovsr));
36
+}
37
+
44
+
38
/*
45
+ /* Check for MTE asynchronous faults */
39
* Ensure c15_ccnt is the guest-visible count so that operations such as
46
+ if (unlikely(env->cp15.tfsr_el[0])) {
40
* enabling/disabling the counter or filtering, modifying the count itself,
47
+ env->cp15.tfsr_el[0] = 0;
41
@@ -XXX,XX +XXX,XX @@ void pmccntr_op_start(CPUARMState *env)
48
+ info.si_signo = TARGET_SIGSEGV;
42
eff_cycles /= 64;
49
+ info.si_errno = 0;
43
}
50
+ info._sifields._sigfault._addr = 0;
44
51
+ info.si_code = TARGET_SEGV_MTEAERR;
45
- env->cp15.c15_ccnt = eff_cycles - env->cp15.c15_ccnt_delta;
52
+ queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
46
+ uint64_t new_pmccntr = eff_cycles - env->cp15.c15_ccnt_delta;
47
+
48
+ uint64_t overflow_mask = env->cp15.c9_pmcr & PMCRLC ? \
49
+ 1ull << 63 : 1ull << 31;
50
+ if (env->cp15.c15_ccnt & ~new_pmccntr & overflow_mask) {
51
+ env->cp15.c9_pmovsr |= (1 << 31);
52
+ pmu_update_irq(env);
53
+ }
53
+ }
54
+
54
+
55
+ env->cp15.c15_ccnt = new_pmccntr;
55
process_pending_signals(env);
56
}
56
/* Exception return on AArch64 always clears the exclusive monitor,
57
env->cp15.c15_ccnt_delta = cycles;
57
* so any return to running guest code implies this.
58
}
58
diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c
59
@@ -XXX,XX +XXX,XX @@ static void pmevcntr_op_start(CPUARMState *env, uint8_t counter)
59
index XXXXXXX..XXXXXXX 100644
60
}
60
--- a/target/arm/mte_helper.c
61
61
+++ b/target/arm/mte_helper.c
62
if (pmu_counter_enabled(env, counter)) {
62
@@ -XXX,XX +XXX,XX @@ static void mte_check_fail(CPUARMState *env, uint32_t desc,
63
- env->cp15.c14_pmevcntr[counter] =
63
select = 0;
64
- count - env->cp15.c14_pmevcntr_delta[counter];
65
+ uint32_t new_pmevcntr = count - env->cp15.c14_pmevcntr_delta[counter];
66
+
67
+ if (env->cp15.c14_pmevcntr[counter] & ~new_pmevcntr & INT32_MIN) {
68
+ env->cp15.c9_pmovsr |= (1 << counter);
69
+ pmu_update_irq(env);
70
+ }
71
+ env->cp15.c14_pmevcntr[counter] = new_pmevcntr;
72
}
73
env->cp15.c14_pmevcntr_delta[counter] = count;
74
}
75
@@ -XXX,XX +XXX,XX @@ static void pmswinc_write(CPUARMState *env, const ARMCPRegInfo *ri,
76
/* counter is SW_INCR */
77
(env->cp15.c14_pmevtyper[i] & PMXEVTYPER_EVTCOUNT) == 0x0) {
78
pmevcntr_op_start(env, i);
79
- env->cp15.c14_pmevcntr[i]++;
80
+
81
+ /*
82
+ * Detect if this write causes an overflow since we can't predict
83
+ * PMSWINC overflows like we can for other events
84
+ */
85
+ uint32_t new_pmswinc = env->cp15.c14_pmevcntr[i] + 1;
86
+
87
+ if (env->cp15.c14_pmevcntr[i] & ~new_pmswinc & INT32_MIN) {
88
+ env->cp15.c9_pmovsr |= (1 << i);
89
+ pmu_update_irq(env);
90
+ }
91
+
92
+ env->cp15.c14_pmevcntr[i] = new_pmswinc;
93
+
94
pmevcntr_op_finish(env, i);
95
}
64
}
96
}
65
env->cp15.tfsr_el[el] |= 1 << select;
97
@@ -XXX,XX +XXX,XX @@ static void pmovsr_write(CPUARMState *env, const ARMCPRegInfo *ri,
66
+#ifdef CONFIG_USER_ONLY
98
{
67
+ /*
99
value &= pmu_counter_mask(env);
68
+ * Stand in for a timer irq, setting _TIF_MTE_ASYNC_FAULT,
100
env->cp15.c9_pmovsr &= ~value;
69
+ * which then sends a SIGSEGV when the thread is next scheduled.
101
+ pmu_update_irq(env);
70
+ * This cpu will return to the main loop at the end of the TB,
102
}
71
+ * which is rather sooner than "normal". But the alternative
103
72
+ * is waiting until the next syscall.
104
static void pmovsset_write(CPUARMState *env, const ARMCPRegInfo *ri,
73
+ */
105
@@ -XXX,XX +XXX,XX @@ static void pmovsset_write(CPUARMState *env, const ARMCPRegInfo *ri,
74
+ qemu_cpu_kick(env_cpu(env));
106
{
75
+#endif
107
value &= pmu_counter_mask(env);
76
break;
108
env->cp15.c9_pmovsr |= value;
77
109
+ pmu_update_irq(env);
78
default:
110
}
111
112
static void pmevtyper_write(CPUARMState *env, const ARMCPRegInfo *ri,
113
@@ -XXX,XX +XXX,XX @@ static void pmintenset_write(CPUARMState *env, const ARMCPRegInfo *ri,
114
/* We have no event counters so only the C bit can be changed */
115
value &= pmu_counter_mask(env);
116
env->cp15.c9_pminten |= value;
117
+ pmu_update_irq(env);
118
}
119
120
static void pmintenclr_write(CPUARMState *env, const ARMCPRegInfo *ri,
121
@@ -XXX,XX +XXX,XX @@ static void pmintenclr_write(CPUARMState *env, const ARMCPRegInfo *ri,
122
{
123
value &= pmu_counter_mask(env);
124
env->cp15.c9_pminten &= ~value;
125
+ pmu_update_irq(env);
126
}
127
128
static void vbar_write(CPUARMState *env, const ARMCPRegInfo *ri,
129
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = {
130
.fieldoffset = offsetof(CPUARMState, cp15.c9_pmcnten),
131
.writefn = pmcntenclr_write },
132
{ .name = "PMOVSR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 3,
133
- .access = PL0_RW,
134
+ .access = PL0_RW, .type = ARM_CP_IO,
135
.fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmovsr),
136
.accessfn = pmreg_access,
137
.writefn = pmovsr_write,
138
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = {
139
{ .name = "PMOVSCLR_EL0", .state = ARM_CP_STATE_AA64,
140
.opc0 = 3, .opc1 = 3, .crn = 9, .crm = 12, .opc2 = 3,
141
.access = PL0_RW, .accessfn = pmreg_access,
142
- .type = ARM_CP_ALIAS,
143
+ .type = ARM_CP_ALIAS | ARM_CP_IO,
144
.fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr),
145
.writefn = pmovsr_write,
146
.raw_writefn = raw_write },
147
{ .name = "PMSWINC", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 4,
148
- .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NO_RAW,
149
+ .access = PL0_W, .accessfn = pmreg_access_swinc,
150
+ .type = ARM_CP_NO_RAW | ARM_CP_IO,
151
.writefn = pmswinc_write },
152
{ .name = "PMSWINC_EL0", .state = ARM_CP_STATE_AA64,
153
.opc0 = 3, .opc1 = 3, .crn = 9, .crm = 12, .opc2 = 4,
154
- .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NO_RAW,
155
+ .access = PL0_W, .accessfn = pmreg_access_swinc,
156
+ .type = ARM_CP_NO_RAW | ARM_CP_IO,
157
.writefn = pmswinc_write },
158
{ .name = "PMSELR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 5,
159
.access = PL0_RW, .type = ARM_CP_ALIAS,
160
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo pmovsset_cp_reginfo[] = {
161
/* PMOVSSET is not implemented in v7 before v7ve */
162
{ .name = "PMOVSSET", .cp = 15, .opc1 = 0, .crn = 9, .crm = 14, .opc2 = 3,
163
.access = PL0_RW, .accessfn = pmreg_access,
164
- .type = ARM_CP_ALIAS,
165
+ .type = ARM_CP_ALIAS | ARM_CP_IO,
166
.fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmovsr),
167
.writefn = pmovsset_write,
168
.raw_writefn = raw_write },
169
{ .name = "PMOVSSET_EL0", .state = ARM_CP_STATE_AA64,
170
.opc0 = 3, .opc1 = 3, .crn = 9, .crm = 14, .opc2 = 3,
171
.access = PL0_RW, .accessfn = pmreg_access,
172
- .type = ARM_CP_ALIAS,
173
+ .type = ARM_CP_ALIAS | ARM_CP_IO,
174
.fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr),
175
.writefn = pmovsset_write,
176
.raw_writefn = raw_write },
177
--
79
--
178
2.20.1
80
2.20.1
179
81
180
82
diff view generated by jsdifflib
1
In the encoding groups
1
From: Richard Henderson <richard.henderson@linaro.org>
2
* floating-point data-processing (1 source)
3
* floating-point data-processing (2 source)
4
* floating-point data-processing (3 source)
5
* floating-point immediate
6
* floating-point compare
7
* floating-ponit conditional compare
8
* floating-point conditional select
9
2
10
bit 31 is M and bit 29 is S (and bit 30 is 0, already checked at
3
Use the now-saved PAGE_ANON and PAGE_MTE bits,
11
this point in the decode). None of these groups allocate any
4
and the per-page saved data.
12
encoding for M=1 or S=1. We checked this in disas_fp_compare(),
13
disas_fp_ccomp() and disas_fp_csel(), but missed it in disas_fp_1src(),
14
disas_fp_2src(), disas_fp_3src() and disas_fp_imm().
15
5
16
We also missed that in the fp immediate encoding the imm5 field
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
17
must be all zeroes.
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20210212184902.1251044-30-richard.henderson@linaro.org
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
target/arm/mte_helper.c | 29 +++++++++++++++++++++++++++--
12
1 file changed, 27 insertions(+), 2 deletions(-)
18
13
19
Correctly UNDEF the unallocated encodings here.
14
diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c
20
21
Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com>
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com>
24
Message-id: 20190125182626.9221-7-peter.maydell@linaro.org
25
---
26
target/arm/translate-a64.c | 22 +++++++++++++++++++++-
27
1 file changed, 21 insertions(+), 1 deletion(-)
28
29
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
30
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
31
--- a/target/arm/translate-a64.c
16
--- a/target/arm/mte_helper.c
32
+++ b/target/arm/translate-a64.c
17
+++ b/target/arm/mte_helper.c
33
@@ -XXX,XX +XXX,XX @@ static void handle_fp_fcvt(DisasContext *s, int opcode,
18
@@ -XXX,XX +XXX,XX @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx,
34
*/
19
int tag_size, uintptr_t ra)
35
static void disas_fp_1src(DisasContext *s, uint32_t insn)
36
{
20
{
37
+ int mos = extract32(insn, 29, 3);
21
#ifdef CONFIG_USER_ONLY
38
int type = extract32(insn, 22, 2);
22
- /* Tag storage not implemented. */
39
int opcode = extract32(insn, 15, 6);
23
- return NULL;
40
int rn = extract32(insn, 5, 5);
24
+ uint64_t clean_ptr = useronly_clean_ptr(ptr);
41
int rd = extract32(insn, 0, 5);
25
+ int flags = page_get_flags(clean_ptr);
42
26
+ uint8_t *tags;
43
+ if (mos) {
27
+ uintptr_t index;
44
+ unallocated_encoding(s);
28
+
45
+ return;
29
+ if (!(flags & (ptr_access == MMU_DATA_STORE ? PAGE_WRITE : PAGE_READ))) {
30
+ /* SIGSEGV */
31
+ arm_cpu_tlb_fill(env_cpu(env), ptr, ptr_size, ptr_access,
32
+ ptr_mmu_idx, false, ra);
33
+ g_assert_not_reached();
46
+ }
34
+ }
47
+
35
+
48
switch (opcode) {
36
+ /* Require both MAP_ANON and PROT_MTE for the page. */
49
case 0x4: case 0x5: case 0x7:
37
+ if (!(flags & PAGE_ANON) || !(flags & PAGE_MTE)) {
50
{
38
+ return NULL;
51
@@ -XXX,XX +XXX,XX @@ static void handle_fp_2src_half(DisasContext *s, int opcode,
52
*/
53
static void disas_fp_2src(DisasContext *s, uint32_t insn)
54
{
55
+ int mos = extract32(insn, 29, 3);
56
int type = extract32(insn, 22, 2);
57
int rd = extract32(insn, 0, 5);
58
int rn = extract32(insn, 5, 5);
59
int rm = extract32(insn, 16, 5);
60
int opcode = extract32(insn, 12, 4);
61
62
- if (opcode > 8) {
63
+ if (opcode > 8 || mos) {
64
unallocated_encoding(s);
65
return;
66
}
67
@@ -XXX,XX +XXX,XX @@ static void handle_fp_3src_half(DisasContext *s, bool o0, bool o1,
68
*/
69
static void disas_fp_3src(DisasContext *s, uint32_t insn)
70
{
71
+ int mos = extract32(insn, 29, 3);
72
int type = extract32(insn, 22, 2);
73
int rd = extract32(insn, 0, 5);
74
int rn = extract32(insn, 5, 5);
75
@@ -XXX,XX +XXX,XX @@ static void disas_fp_3src(DisasContext *s, uint32_t insn)
76
bool o0 = extract32(insn, 15, 1);
77
bool o1 = extract32(insn, 21, 1);
78
79
+ if (mos) {
80
+ unallocated_encoding(s);
81
+ return;
82
+ }
39
+ }
83
+
40
+
84
switch (type) {
41
+ tags = page_get_target_data(clean_ptr);
85
case 0:
42
+ if (tags == NULL) {
86
if (!fp_access_check(s)) {
43
+ size_t alloc_size = TARGET_PAGE_SIZE >> (LOG2_TAG_GRANULE + 1);
87
@@ -XXX,XX +XXX,XX @@ uint64_t vfp_expand_imm(int size, uint8_t imm8)
44
+ tags = page_alloc_target_data(clean_ptr, alloc_size);
88
static void disas_fp_imm(DisasContext *s, uint32_t insn)
45
+ assert(tags != NULL);
89
{
90
int rd = extract32(insn, 0, 5);
91
+ int imm5 = extract32(insn, 5, 5);
92
int imm8 = extract32(insn, 13, 8);
93
int type = extract32(insn, 22, 2);
94
+ int mos = extract32(insn, 29, 3);
95
uint64_t imm;
96
TCGv_i64 tcg_res;
97
TCGMemOp sz;
98
99
+ if (mos || imm5) {
100
+ unallocated_encoding(s);
101
+ return;
102
+ }
46
+ }
103
+
47
+
104
switch (type) {
48
+ index = extract32(ptr, LOG2_TAG_GRANULE + 1,
105
case 0:
49
+ TARGET_PAGE_BITS - LOG2_TAG_GRANULE - 1);
106
sz = MO_32;
50
+ return tags + index;
51
#else
52
uintptr_t index;
53
CPUIOTLBEntry *iotlbentry;
107
--
54
--
108
2.20.1
55
2.20.1
109
56
110
57
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Drop the pac properties. This approach cannot work as written
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
because the properties are applied before arm_cpu_reset, which
5
zeros SCTLR_EL1 (amongst everything else).
6
7
We can re-introduce the properties if they turn out to be useful.
8
But since linux 5.0 enables all of the keys, they may not be.
9
10
Fixes: 1ae9cfbd470
11
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
12
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Message-id: 20210212184902.1251044-31-richard.henderson@linaro.org
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
7
---
15
target/arm/cpu.c | 3 +++
8
target/arm/cpu.c | 15 +++++++++++++++
16
target/arm/cpu64.c | 60 ----------------------------------------------
9
1 file changed, 15 insertions(+)
17
2 files changed, 3 insertions(+), 60 deletions(-)
18
10
19
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
11
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
20
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
21
--- a/target/arm/cpu.c
13
--- a/target/arm/cpu.c
22
+++ b/target/arm/cpu.c
14
+++ b/target/arm/cpu.c
23
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s)
15
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev)
24
env->pstate = PSTATE_MODE_EL0t;
16
* Note that this must match useronly_clean_ptr.
25
/* Userspace expects access to DC ZVA, CTL_EL0 and the cache ops */
26
env->cp15.sctlr_el[1] |= SCTLR_UCT | SCTLR_UCI | SCTLR_DZE;
27
+ /* Enable all PAC keys. */
28
+ env->cp15.sctlr_el[1] |= (SCTLR_EnIA | SCTLR_EnIB |
29
+ SCTLR_EnDA | SCTLR_EnDB);
30
/* Enable all PAC instructions */
31
env->cp15.hcr_el2 |= HCR_API;
32
env->cp15.scr_el3 |= SCR_API;
33
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
34
index XXXXXXX..XXXXXXX 100644
35
--- a/target/arm/cpu64.c
36
+++ b/target/arm/cpu64.c
37
@@ -XXX,XX +XXX,XX @@ static void cpu_max_set_sve_vq(Object *obj, Visitor *v, const char *name,
38
error_propagate(errp, err);
39
}
40
41
-#ifdef CONFIG_USER_ONLY
42
-static void cpu_max_get_packey(Object *obj, Visitor *v, const char *name,
43
- void *opaque, Error **errp)
44
-{
45
- ARMCPU *cpu = ARM_CPU(obj);
46
- const uint64_t *bit = opaque;
47
- bool enabled = (cpu->env.cp15.sctlr_el[1] & *bit) != 0;
48
-
49
- visit_type_bool(v, name, &enabled, errp);
50
-}
51
-
52
-static void cpu_max_set_packey(Object *obj, Visitor *v, const char *name,
53
- void *opaque, Error **errp)
54
-{
55
- ARMCPU *cpu = ARM_CPU(obj);
56
- Error *err = NULL;
57
- const uint64_t *bit = opaque;
58
- bool enabled;
59
-
60
- visit_type_bool(v, name, &enabled, errp);
61
-
62
- if (!err) {
63
- if (enabled) {
64
- cpu->env.cp15.sctlr_el[1] |= *bit;
65
- } else {
66
- cpu->env.cp15.sctlr_el[1] &= ~*bit;
67
- }
68
- }
69
- error_propagate(errp, err);
70
-}
71
-#endif
72
-
73
/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host);
74
* otherwise, a CPU with as many features enabled as our emulation supports.
75
* The version of '-cpu max' for qemu-system-arm is defined in cpu.c;
76
@@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj)
77
*/
17
*/
78
cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */
18
env->cp15.tcr_el[1].raw_tcr = (1ULL << 37);
79
cpu->dcz_blocksize = 7; /* 512 bytes */
19
+
80
-
20
+ /* Enable MTE */
81
- /*
21
+ if (cpu_isar_feature(aa64_mte, cpu)) {
82
- * Note that Linux will enable enable all of the keys at once.
22
+ /* Enable tag access, but leave TCF0 as No Effect (0). */
83
- * But doing it this way will allow experimentation beyond that.
23
+ env->cp15.sctlr_el[1] |= SCTLR_ATA0;
84
- */
24
+ /*
85
- {
25
+ * Exclude all tags, so that tag 0 is always used.
86
- static const uint64_t apia_bit = SCTLR_EnIA;
26
+ * This corresponds to Linux current->thread.gcr_incl = 0.
87
- static const uint64_t apib_bit = SCTLR_EnIB;
27
+ *
88
- static const uint64_t apda_bit = SCTLR_EnDA;
28
+ * Set RRND, so that helper_irg() will generate a seed later.
89
- static const uint64_t apdb_bit = SCTLR_EnDB;
29
+ * Here in cpu_reset(), the crypto subsystem has not yet been
90
-
30
+ * initialized.
91
- object_property_add(obj, "apia", "bool", cpu_max_get_packey,
31
+ */
92
- cpu_max_set_packey, NULL,
32
+ env->cp15.gcr_el1 = 0x1ffff;
93
- (void *)&apia_bit, &error_fatal);
33
+ }
94
- object_property_add(obj, "apib", "bool", cpu_max_get_packey,
34
#else
95
- cpu_max_set_packey, NULL,
35
/* Reset into the highest available EL */
96
- (void *)&apib_bit, &error_fatal);
36
if (arm_feature(env, ARM_FEATURE_EL3)) {
97
- object_property_add(obj, "apda", "bool", cpu_max_get_packey,
98
- cpu_max_set_packey, NULL,
99
- (void *)&apda_bit, &error_fatal);
100
- object_property_add(obj, "apdb", "bool", cpu_max_get_packey,
101
- cpu_max_set_packey, NULL,
102
- (void *)&apdb_bit, &error_fatal);
103
-
104
- /* Enable all PAC keys by default. */
105
- cpu->env.cp15.sctlr_el[1] |= SCTLR_EnIA | SCTLR_EnIB;
106
- cpu->env.cp15.sctlr_el[1] |= SCTLR_EnDA | SCTLR_EnDB;
107
- }
108
#endif
109
110
cpu->sve_max_vq = ARM_MAX_VQ;
111
--
37
--
112
2.20.1
38
2.20.1
113
39
114
40
diff view generated by jsdifflib
1
For the IoTKit the SRAM bank size is always 32K (15 bits); for the
1
From: Richard Henderson <richard.henderson@linaro.org>
2
SSE-200 this is a configurable parameter, which defaults to 32K but
3
can be changed when it is built into a particular SoC. For instance
4
the Musca-B1 board sets it to 128K (17 bits).
5
2
6
Make the bank size a QOM property. We follow the SSE-200 hardware in
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
naming the parameter SRAM_ADDR_WIDTH, which specifies the number of
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
address bits of a single SRAM bank.
5
Message-id: 20210212184902.1251044-32-richard.henderson@linaro.org
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
8
tests/tcg/aarch64/mte.h | 60 +++++++++++++++++++++++++++++++
9
tests/tcg/aarch64/mte-1.c | 28 +++++++++++++++
10
tests/tcg/aarch64/mte-2.c | 45 +++++++++++++++++++++++
11
tests/tcg/aarch64/mte-3.c | 51 ++++++++++++++++++++++++++
12
tests/tcg/aarch64/mte-4.c | 45 +++++++++++++++++++++++
13
tests/tcg/aarch64/Makefile.target | 6 ++++
14
tests/tcg/configure.sh | 4 +++
15
7 files changed, 239 insertions(+)
16
create mode 100644 tests/tcg/aarch64/mte.h
17
create mode 100644 tests/tcg/aarch64/mte-1.c
18
create mode 100644 tests/tcg/aarch64/mte-2.c
19
create mode 100644 tests/tcg/aarch64/mte-3.c
20
create mode 100644 tests/tcg/aarch64/mte-4.c
9
21
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
diff --git a/tests/tcg/aarch64/mte.h b/tests/tcg/aarch64/mte.h
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
23
new file mode 100644
12
Message-id: 20190121185118.18550-11-peter.maydell@linaro.org
24
index XXXXXXX..XXXXXXX
13
---
25
--- /dev/null
14
include/hw/arm/armsse.h | 1 +
26
+++ b/tests/tcg/aarch64/mte.h
15
hw/arm/armsse.c | 18 ++++++++++++++++--
27
@@ -XXX,XX +XXX,XX @@
16
2 files changed, 17 insertions(+), 2 deletions(-)
28
+/*
17
29
+ * Linux kernel fallback API definitions for MTE and test helpers.
18
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
30
+ *
31
+ * Copyright (c) 2021 Linaro Ltd
32
+ * SPDX-License-Identifier: GPL-2.0-or-later
33
+ */
34
+
35
+#include <assert.h>
36
+#include <string.h>
37
+#include <stdlib.h>
38
+#include <stdio.h>
39
+#include <unistd.h>
40
+#include <signal.h>
41
+#include <sys/mman.h>
42
+#include <sys/prctl.h>
43
+
44
+#ifndef PR_SET_TAGGED_ADDR_CTRL
45
+# define PR_SET_TAGGED_ADDR_CTRL 55
46
+#endif
47
+#ifndef PR_TAGGED_ADDR_ENABLE
48
+# define PR_TAGGED_ADDR_ENABLE (1UL << 0)
49
+#endif
50
+#ifndef PR_MTE_TCF_SHIFT
51
+# define PR_MTE_TCF_SHIFT 1
52
+# define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT)
53
+# define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT)
54
+# define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT)
55
+# define PR_MTE_TAG_SHIFT 3
56
+#endif
57
+
58
+#ifndef PROT_MTE
59
+# define PROT_MTE 0x20
60
+#endif
61
+
62
+#ifndef SEGV_MTEAERR
63
+# define SEGV_MTEAERR 8
64
+# define SEGV_MTESERR 9
65
+#endif
66
+
67
+static void enable_mte(int tcf)
68
+{
69
+ int r = prctl(PR_SET_TAGGED_ADDR_CTRL,
70
+ PR_TAGGED_ADDR_ENABLE | tcf | (0xfffe << PR_MTE_TAG_SHIFT),
71
+ 0, 0, 0);
72
+ if (r < 0) {
73
+ perror("PR_SET_TAGGED_ADDR_CTRL");
74
+ exit(2);
75
+ }
76
+}
77
+
78
+static void *alloc_mte_mem(size_t size)
79
+{
80
+ void *p = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_MTE,
81
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
82
+ if (p == MAP_FAILED) {
83
+ perror("mmap PROT_MTE");
84
+ exit(2);
85
+ }
86
+ return p;
87
+}
88
diff --git a/tests/tcg/aarch64/mte-1.c b/tests/tcg/aarch64/mte-1.c
89
new file mode 100644
90
index XXXXXXX..XXXXXXX
91
--- /dev/null
92
+++ b/tests/tcg/aarch64/mte-1.c
93
@@ -XXX,XX +XXX,XX @@
94
+/*
95
+ * Memory tagging, basic pass cases.
96
+ *
97
+ * Copyright (c) 2021 Linaro Ltd
98
+ * SPDX-License-Identifier: GPL-2.0-or-later
99
+ */
100
+
101
+#include "mte.h"
102
+
103
+int main(int ac, char **av)
104
+{
105
+ int *p0, *p1, *p2;
106
+ long c;
107
+
108
+ enable_mte(PR_MTE_TCF_NONE);
109
+ p0 = alloc_mte_mem(sizeof(*p0));
110
+
111
+ asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(1));
112
+ assert(p1 != p0);
113
+ asm("subp %0,%1,%2" : "=r"(c) : "r"(p0), "r"(p1));
114
+ assert(c == 0);
115
+
116
+ asm("stg %0, [%0]" : : "r"(p1));
117
+ asm("ldg %0, [%1]" : "=r"(p2) : "r"(p0), "0"(p0));
118
+ assert(p1 == p2);
119
+
120
+ return 0;
121
+}
122
diff --git a/tests/tcg/aarch64/mte-2.c b/tests/tcg/aarch64/mte-2.c
123
new file mode 100644
124
index XXXXXXX..XXXXXXX
125
--- /dev/null
126
+++ b/tests/tcg/aarch64/mte-2.c
127
@@ -XXX,XX +XXX,XX @@
128
+/*
129
+ * Memory tagging, basic fail cases, synchronous signals.
130
+ *
131
+ * Copyright (c) 2021 Linaro Ltd
132
+ * SPDX-License-Identifier: GPL-2.0-or-later
133
+ */
134
+
135
+#include "mte.h"
136
+
137
+void pass(int sig, siginfo_t *info, void *uc)
138
+{
139
+ assert(info->si_code == SEGV_MTESERR);
140
+ exit(0);
141
+}
142
+
143
+int main(int ac, char **av)
144
+{
145
+ struct sigaction sa;
146
+ int *p0, *p1, *p2;
147
+ long excl = 1;
148
+
149
+ enable_mte(PR_MTE_TCF_SYNC);
150
+ p0 = alloc_mte_mem(sizeof(*p0));
151
+
152
+ /* Create two differently tagged pointers. */
153
+ asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl));
154
+ asm("gmi %0,%1,%0" : "+r"(excl) : "r" (p1));
155
+ assert(excl != 1);
156
+ asm("irg %0,%1,%2" : "=r"(p2) : "r"(p0), "r"(excl));
157
+ assert(p1 != p2);
158
+
159
+ /* Store the tag from the first pointer. */
160
+ asm("stg %0, [%0]" : : "r"(p1));
161
+
162
+ *p1 = 0;
163
+
164
+ memset(&sa, 0, sizeof(sa));
165
+ sa.sa_sigaction = pass;
166
+ sa.sa_flags = SA_SIGINFO;
167
+ sigaction(SIGSEGV, &sa, NULL);
168
+
169
+ *p2 = 0;
170
+
171
+ abort();
172
+}
173
diff --git a/tests/tcg/aarch64/mte-3.c b/tests/tcg/aarch64/mte-3.c
174
new file mode 100644
175
index XXXXXXX..XXXXXXX
176
--- /dev/null
177
+++ b/tests/tcg/aarch64/mte-3.c
178
@@ -XXX,XX +XXX,XX @@
179
+/*
180
+ * Memory tagging, basic fail cases, asynchronous signals.
181
+ *
182
+ * Copyright (c) 2021 Linaro Ltd
183
+ * SPDX-License-Identifier: GPL-2.0-or-later
184
+ */
185
+
186
+#include "mte.h"
187
+
188
+void pass(int sig, siginfo_t *info, void *uc)
189
+{
190
+ assert(info->si_code == SEGV_MTEAERR);
191
+ exit(0);
192
+}
193
+
194
+int main(int ac, char **av)
195
+{
196
+ struct sigaction sa;
197
+ long *p0, *p1, *p2;
198
+ long excl = 1;
199
+
200
+ enable_mte(PR_MTE_TCF_ASYNC);
201
+ p0 = alloc_mte_mem(sizeof(*p0));
202
+
203
+ /* Create two differently tagged pointers. */
204
+ asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl));
205
+ asm("gmi %0,%1,%0" : "+r"(excl) : "r" (p1));
206
+ assert(excl != 1);
207
+ asm("irg %0,%1,%2" : "=r"(p2) : "r"(p0), "r"(excl));
208
+ assert(p1 != p2);
209
+
210
+ /* Store the tag from the first pointer. */
211
+ asm("stg %0, [%0]" : : "r"(p1));
212
+
213
+ *p1 = 0;
214
+
215
+ memset(&sa, 0, sizeof(sa));
216
+ sa.sa_sigaction = pass;
217
+ sa.sa_flags = SA_SIGINFO;
218
+ sigaction(SIGSEGV, &sa, NULL);
219
+
220
+ /*
221
+ * Signal for async error will happen eventually.
222
+ * For a real kernel this should be after the next IRQ (e.g. timer).
223
+ * For qemu linux-user, we kick the cpu and exit at the next TB.
224
+ * In either case, loop until this happens (or killed by timeout).
225
+ * For extra sauce, yield, producing EXCP_YIELD to cpu_loop().
226
+ */
227
+ asm("str %0, [%0]; yield" : : "r"(p2));
228
+ while (1);
229
+}
230
diff --git a/tests/tcg/aarch64/mte-4.c b/tests/tcg/aarch64/mte-4.c
231
new file mode 100644
232
index XXXXXXX..XXXXXXX
233
--- /dev/null
234
+++ b/tests/tcg/aarch64/mte-4.c
235
@@ -XXX,XX +XXX,XX @@
236
+/*
237
+ * Memory tagging, re-reading tag checks.
238
+ *
239
+ * Copyright (c) 2021 Linaro Ltd
240
+ * SPDX-License-Identifier: GPL-2.0-or-later
241
+ */
242
+
243
+#include "mte.h"
244
+
245
+void __attribute__((noinline)) tagset(void *p, size_t size)
246
+{
247
+ size_t i;
248
+ for (i = 0; i < size; i += 16) {
249
+ asm("stg %0, [%0]" : : "r"(p + i));
250
+ }
251
+}
252
+
253
+void __attribute__((noinline)) tagcheck(void *p, size_t size)
254
+{
255
+ size_t i;
256
+ void *c;
257
+
258
+ for (i = 0; i < size; i += 16) {
259
+ asm("ldg %0, [%1]" : "=r"(c) : "r"(p + i), "0"(p));
260
+ assert(c == p);
261
+ }
262
+}
263
+
264
+int main(int ac, char **av)
265
+{
266
+ size_t size = getpagesize() * 4;
267
+ long excl = 1;
268
+ int *p0, *p1;
269
+
270
+ enable_mte(PR_MTE_TCF_ASYNC);
271
+ p0 = alloc_mte_mem(size);
272
+
273
+ /* Tag the pointer. */
274
+ asm("irg %0,%1,%2" : "=r"(p1) : "r"(p0), "r"(excl));
275
+
276
+ tagset(p1, size);
277
+ tagcheck(p1, size);
278
+
279
+ return 0;
280
+}
281
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
19
index XXXXXXX..XXXXXXX 100644
282
index XXXXXXX..XXXXXXX 100644
20
--- a/include/hw/arm/armsse.h
283
--- a/tests/tcg/aarch64/Makefile.target
21
+++ b/include/hw/arm/armsse.h
284
+++ b/tests/tcg/aarch64/Makefile.target
22
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
285
@@ -XXX,XX +XXX,XX @@ endif
23
MemoryRegion *board_memory;
286
# bti-2 tests PROT_BTI, so no special compiler support required.
24
uint32_t exp_numirq;
287
AARCH64_TESTS += bti-2
25
uint32_t mainclk_frq;
288
26
+ uint32_t sram_addr_width;
289
+# MTE Tests
27
} ARMSSE;
290
+ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_MTE),)
28
291
+AARCH64_TESTS += mte-1 mte-2 mte-3 mte-4
29
typedef struct ARMSSEInfo ARMSSEInfo;
292
+mte-%: CFLAGS += -march=armv8.5-a+memtag
30
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
293
+endif
31
index XXXXXXX..XXXXXXX 100644
294
+
32
--- a/hw/arm/armsse.c
295
# Semihosting smoke test for linux-user
33
+++ b/hw/arm/armsse.c
296
AARCH64_TESTS += semihosting
34
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
297
run-semihosting: semihosting
35
DeviceState *dev_apb_ppc1;
298
diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh
36
DeviceState *dev_secctl;
299
index XXXXXXX..XXXXXXX 100755
37
DeviceState *dev_splitter;
300
--- a/tests/tcg/configure.sh
38
+ uint32_t addr_width_max;
301
+++ b/tests/tcg/configure.sh
39
302
@@ -XXX,XX +XXX,XX @@ for target in $target_list; do
40
if (!s->board_memory) {
303
-mbranch-protection=standard -o $TMPE $TMPC; then
41
error_setg(errp, "memory property was not set");
304
echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak
42
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
305
fi
43
return;
306
+ if do_compiler "$target_compiler" $target_compiler_cflags \
44
}
307
+ -march=armv8.5-a+memtag -o $TMPE $TMPC; then
45
308
+ echo "CROSS_CC_HAS_ARMV8_MTE=y" >> $config_target_mak
46
+ /* max SRAM_ADDR_WIDTH: 24 - log2(SRAM_NUM_BANK) */
309
+ fi
47
+ assert(is_power_of_2(info->sram_banks));
310
;;
48
+ addr_width_max = 24 - ctz32(info->sram_banks);
311
esac
49
+ if (s->sram_addr_width < 1 || s->sram_addr_width > addr_width_max) {
50
+ error_setg(errp, "SRAM_ADDR_WIDTH must be between 1 and %d",
51
+ addr_width_max);
52
+ return;
53
+ }
54
+
55
/* Handling of which devices should be available only to secure
56
* code is usually done differently for M profile than for A profile.
57
* Instead of putting some devices only into the secure address space,
58
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
59
for (i = 0; i < info->sram_banks; i++) {
60
char *ramname = g_strdup_printf("armsse.sram%d", i);
61
SysBusDevice *sbd_mpc;
62
+ uint32_t sram_bank_size = 1 << s->sram_addr_width;
63
64
- memory_region_init_ram(&s->sram[i], NULL, ramname, 0x00008000, &err);
65
+ memory_region_init_ram(&s->sram[i], NULL, ramname,
66
+ sram_bank_size, &err);
67
g_free(ramname);
68
if (err) {
69
error_propagate(errp, err);
70
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
71
}
72
/* Map the upstream end of the MPC into the right place... */
73
sbd_mpc = SYS_BUS_DEVICE(&s->mpc[i]);
74
- memory_region_add_subregion(&s->container, 0x20000000 + i * 0x8000,
75
+ memory_region_add_subregion(&s->container,
76
+ 0x20000000 + i * sram_bank_size,
77
sysbus_mmio_get_region(sbd_mpc, 1));
78
/* ...and its register interface */
79
memory_region_add_subregion(&s->container, 0x50083000 + i * 0x1000,
80
@@ -XXX,XX +XXX,XX @@ static Property armsse_properties[] = {
81
MemoryRegion *),
82
DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE, exp_numirq, 64),
83
DEFINE_PROP_UINT32("MAINCLK", ARMSSE, mainclk_frq, 0),
84
+ DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE, sram_addr_width, 15),
85
DEFINE_PROP_END_OF_LIST()
86
};
87
312
88
--
313
--
89
2.20.1
314
2.20.1
90
315
91
316
diff view generated by jsdifflib
1
From: Steffen Görtz <contrib@steffen-goertz.de>
1
From: Hao Wu <wuhaotsh@google.com>
2
2
3
The nRF51 contains three regions of non-volatile memory (NVM):
3
This commit implements the single-byte mode of the SMBus.
4
- CODE (R/W): contains code
5
- FICR (R): Factory information like code size, chip id etc.
6
- UICR (R/W): Changeable configuration data. Lock bits, Code
7
protection configuration, Bootloader address, Nordic SoftRadio
8
configuration, Firmware configuration.
9
4
10
Read and write access to the memories is managed by the
5
Each Nuvoton SoC has 16 System Management Bus (SMBus). These buses
11
Non-volatile memory controller.
6
compliant with SMBus and I2C protocol.
12
7
13
Memory schema:
8
This patch implements the single-byte mode of the SMBus. In this mode,
14
[ CPU ] -+- [ NVM, either FICR, UICR or CODE ]
9
the user sends or receives a byte each time. The SMBus device transmits
15
| |
10
it to the underlying i2c device and sends an interrupt back to the QEMU
16
\- [ NVMC ]
11
guest.
17
12
18
Signed-off-by: Steffen Görtz <contrib@steffen-goertz.de>
13
Reviewed-by: Doug Evans<dje@google.com>
19
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
14
Reviewed-by: Tyrong Ting<kfting@nuvoton.com>
20
Tested-by: Joel Stanley <joel@jms.id.au>
15
Signed-off-by: Hao Wu <wuhaotsh@google.com>
21
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
16
Reviewed-by: Corey Minyard <cminyard@mvista.com>
22
Message-id: 20190201023357.22596-2-stefanha@redhat.com
17
Message-id: 20210210220426.3577804-2-wuhaotsh@google.com
18
Acked-by: Corey Minyard <cminyard@mvista.com>
23
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
24
---
20
---
25
hw/nvram/Makefile.objs | 1 +
21
docs/system/arm/nuvoton.rst | 2 +-
26
include/hw/nvram/nrf51_nvm.h | 64 ++++++
22
include/hw/arm/npcm7xx.h | 2 +
27
hw/nvram/nrf51_nvm.c | 388 +++++++++++++++++++++++++++++++++++
23
include/hw/i2c/npcm7xx_smbus.h | 88 ++++
28
3 files changed, 453 insertions(+)
24
hw/arm/npcm7xx.c | 68 ++-
29
create mode 100644 include/hw/nvram/nrf51_nvm.h
25
hw/i2c/npcm7xx_smbus.c | 783 +++++++++++++++++++++++++++++++++
30
create mode 100644 hw/nvram/nrf51_nvm.c
26
hw/i2c/meson.build | 1 +
27
hw/i2c/trace-events | 11 +
28
7 files changed, 938 insertions(+), 17 deletions(-)
29
create mode 100644 include/hw/i2c/npcm7xx_smbus.h
30
create mode 100644 hw/i2c/npcm7xx_smbus.c
31
31
32
diff --git a/hw/nvram/Makefile.objs b/hw/nvram/Makefile.objs
32
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
33
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/nvram/Makefile.objs
34
--- a/docs/system/arm/nuvoton.rst
35
+++ b/hw/nvram/Makefile.objs
35
+++ b/docs/system/arm/nuvoton.rst
36
@@ -XXX,XX +XXX,XX @@ common-obj-y += fw_cfg.o
36
@@ -XXX,XX +XXX,XX @@ Supported devices
37
common-obj-y += chrp_nvram.o
37
* GPIO controller
38
common-obj-$(CONFIG_MAC_NVRAM) += mac_nvram.o
38
* Analog to Digital Converter (ADC)
39
obj-$(CONFIG_PSERIES) += spapr_nvram.o
39
* Pulse Width Modulation (PWM)
40
+obj-$(CONFIG_NRF51_SOC) += nrf51_nvm.o
40
+ * SMBus controller (SMBF)
41
diff --git a/include/hw/nvram/nrf51_nvm.h b/include/hw/nvram/nrf51_nvm.h
41
42
Missing devices
43
---------------
44
@@ -XXX,XX +XXX,XX @@ Missing devices
45
46
* Ethernet controllers (GMAC and EMC)
47
* USB device (USBD)
48
- * SMBus controller (SMBF)
49
* Peripheral SPI controller (PSPI)
50
* SD/MMC host
51
* PECI interface
52
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
53
index XXXXXXX..XXXXXXX 100644
54
--- a/include/hw/arm/npcm7xx.h
55
+++ b/include/hw/arm/npcm7xx.h
56
@@ -XXX,XX +XXX,XX @@
57
#include "hw/adc/npcm7xx_adc.h"
58
#include "hw/cpu/a9mpcore.h"
59
#include "hw/gpio/npcm7xx_gpio.h"
60
+#include "hw/i2c/npcm7xx_smbus.h"
61
#include "hw/mem/npcm7xx_mc.h"
62
#include "hw/misc/npcm7xx_clk.h"
63
#include "hw/misc/npcm7xx_gcr.h"
64
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
65
NPCM7xxMCState mc;
66
NPCM7xxRNGState rng;
67
NPCM7xxGPIOState gpio[8];
68
+ NPCM7xxSMBusState smbus[16];
69
EHCISysBusState ehci;
70
OHCISysBusState ohci;
71
NPCM7xxFIUState fiu[2];
72
diff --git a/include/hw/i2c/npcm7xx_smbus.h b/include/hw/i2c/npcm7xx_smbus.h
42
new file mode 100644
73
new file mode 100644
43
index XXXXXXX..XXXXXXX
74
index XXXXXXX..XXXXXXX
44
--- /dev/null
75
--- /dev/null
45
+++ b/include/hw/nvram/nrf51_nvm.h
76
+++ b/include/hw/i2c/npcm7xx_smbus.h
46
@@ -XXX,XX +XXX,XX @@
77
@@ -XXX,XX +XXX,XX @@
47
+/*
78
+/*
48
+ * Nordic Semiconductor nRF51 non-volatile memory
79
+ * Nuvoton NPCM7xx SMBus Module.
49
+ *
80
+ *
50
+ * It provides an interface to erase regions in flash memory.
81
+ * Copyright 2020 Google LLC
51
+ * Furthermore it provides the user and factory information registers.
52
+ *
82
+ *
53
+ * QEMU interface:
83
+ * This program is free software; you can redistribute it and/or modify it
54
+ * + sysbus MMIO regions 0: NVMC peripheral registers
84
+ * under the terms of the GNU General Public License as published by the
55
+ * + sysbus MMIO regions 1: FICR peripheral registers
85
+ * Free Software Foundation; either version 2 of the License, or
56
+ * + sysbus MMIO regions 2: UICR peripheral registers
86
+ * (at your option) any later version.
57
+ * + flash-size property: flash size in bytes.
58
+ *
87
+ *
59
+ * Accuracy of the peripheral model:
88
+ * This program is distributed in the hope that it will be useful, but WITHOUT
60
+ * + Code regions (MPU configuration) are disregarded.
89
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
61
+ *
90
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
62
+ * Copyright 2018 Steffen Görtz <contrib@steffen-goertz.de>
91
+ * for more details.
63
+ *
64
+ * This code is licensed under the GPL version 2 or later. See
65
+ * the COPYING file in the top-level directory.
66
+ *
67
+ */
92
+ */
68
+#ifndef NRF51_NVM_H
93
+#ifndef NPCM7XX_SMBUS_H
69
+#define NRF51_NVM_H
94
+#define NPCM7XX_SMBUS_H
70
+
95
+
96
+#include "exec/memory.h"
97
+#include "hw/i2c/i2c.h"
98
+#include "hw/irq.h"
71
+#include "hw/sysbus.h"
99
+#include "hw/sysbus.h"
72
+#define TYPE_NRF51_NVM "nrf51_soc.nvm"
100
+
73
+#define NRF51_NVM(obj) OBJECT_CHECK(NRF51NVMState, (obj), TYPE_NRF51_NVM)
101
+/*
74
+
102
+ * Number of addresses this module contains. Do not change this without
75
+#define NRF51_UICR_FIXTURE_SIZE 64
103
+ * incrementing the version_id in the vmstate.
76
+
104
+ */
77
+#define NRF51_NVMC_SIZE 0x1000
105
+#define NPCM7XX_SMBUS_NR_ADDRS 10
78
+
106
+
79
+#define NRF51_NVMC_READY 0x400
107
+typedef enum NPCM7xxSMBusStatus {
80
+#define NRF51_NVMC_READY_READY 0x01
108
+ NPCM7XX_SMBUS_STATUS_IDLE,
81
+#define NRF51_NVMC_CONFIG 0x504
109
+ NPCM7XX_SMBUS_STATUS_SENDING,
82
+#define NRF51_NVMC_CONFIG_MASK 0x03
110
+ NPCM7XX_SMBUS_STATUS_RECEIVING,
83
+#define NRF51_NVMC_CONFIG_WEN 0x01
111
+ NPCM7XX_SMBUS_STATUS_NEGACK,
84
+#define NRF51_NVMC_CONFIG_EEN 0x02
112
+ NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE,
85
+#define NRF51_NVMC_ERASEPCR1 0x508
113
+ NPCM7XX_SMBUS_STATUS_STOPPING_NEGACK,
86
+#define NRF51_NVMC_ERASEPCR0 0x510
114
+} NPCM7xxSMBusStatus;
87
+#define NRF51_NVMC_ERASEALL 0x50C
115
+
88
+#define NRF51_NVMC_ERASEUICR 0x514
116
+/*
89
+#define NRF51_NVMC_ERASE 0x01
117
+ * struct NPCM7xxSMBusState - System Management Bus device state.
90
+
118
+ * @bus: The underlying I2C Bus.
91
+#define NRF51_UICR_SIZE 0x100
119
+ * @irq: GIC interrupt line to fire on events (if enabled).
92
+
120
+ * @sda: The serial data register.
93
+typedef struct NRF51NVMState {
121
+ * @st: The status register.
94
+ SysBusDevice parent_obj;
122
+ * @cst: The control status register.
95
+
123
+ * @cst2: The control status register 2.
96
+ MemoryRegion mmio;
124
+ * @cst3: The control status register 3.
97
+ MemoryRegion ficr;
125
+ * @ctl1: The control register 1.
98
+ MemoryRegion uicr;
126
+ * @ctl2: The control register 2.
99
+ MemoryRegion flash;
127
+ * @ctl3: The control register 3.
100
+
128
+ * @ctl4: The control register 4.
101
+ uint32_t uicr_content[NRF51_UICR_FIXTURE_SIZE];
129
+ * @ctl5: The control register 5.
102
+ uint32_t flash_size;
130
+ * @addr: The SMBus module's own addresses on the I2C bus.
103
+ uint8_t *storage;
131
+ * @scllt: The SCL low time register.
104
+
132
+ * @sclht: The SCL high time register.
105
+ uint32_t config;
133
+ * @status: The current status of the SMBus.
106
+
134
+ */
107
+} NRF51NVMState;
135
+typedef struct NPCM7xxSMBusState {
108
+
136
+ SysBusDevice parent;
109
+
137
+
110
+#endif
138
+ MemoryRegion iomem;
111
diff --git a/hw/nvram/nrf51_nvm.c b/hw/nvram/nrf51_nvm.c
139
+
140
+ I2CBus *bus;
141
+ qemu_irq irq;
142
+
143
+ uint8_t sda;
144
+ uint8_t st;
145
+ uint8_t cst;
146
+ uint8_t cst2;
147
+ uint8_t cst3;
148
+ uint8_t ctl1;
149
+ uint8_t ctl2;
150
+ uint8_t ctl3;
151
+ uint8_t ctl4;
152
+ uint8_t ctl5;
153
+ uint8_t addr[NPCM7XX_SMBUS_NR_ADDRS];
154
+
155
+ uint8_t scllt;
156
+ uint8_t sclht;
157
+
158
+ NPCM7xxSMBusStatus status;
159
+} NPCM7xxSMBusState;
160
+
161
+#define TYPE_NPCM7XX_SMBUS "npcm7xx-smbus"
162
+#define NPCM7XX_SMBUS(obj) OBJECT_CHECK(NPCM7xxSMBusState, (obj), \
163
+ TYPE_NPCM7XX_SMBUS)
164
+
165
+#endif /* NPCM7XX_SMBUS_H */
166
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
167
index XXXXXXX..XXXXXXX 100644
168
--- a/hw/arm/npcm7xx.c
169
+++ b/hw/arm/npcm7xx.c
170
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
171
NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */
172
NPCM7XX_EHCI_IRQ = 61,
173
NPCM7XX_OHCI_IRQ = 62,
174
+ NPCM7XX_SMBUS0_IRQ = 64,
175
+ NPCM7XX_SMBUS1_IRQ,
176
+ NPCM7XX_SMBUS2_IRQ,
177
+ NPCM7XX_SMBUS3_IRQ,
178
+ NPCM7XX_SMBUS4_IRQ,
179
+ NPCM7XX_SMBUS5_IRQ,
180
+ NPCM7XX_SMBUS6_IRQ,
181
+ NPCM7XX_SMBUS7_IRQ,
182
+ NPCM7XX_SMBUS8_IRQ,
183
+ NPCM7XX_SMBUS9_IRQ,
184
+ NPCM7XX_SMBUS10_IRQ,
185
+ NPCM7XX_SMBUS11_IRQ,
186
+ NPCM7XX_SMBUS12_IRQ,
187
+ NPCM7XX_SMBUS13_IRQ,
188
+ NPCM7XX_SMBUS14_IRQ,
189
+ NPCM7XX_SMBUS15_IRQ,
190
NPCM7XX_PWM0_IRQ = 93, /* PWM module 0 */
191
NPCM7XX_PWM1_IRQ, /* PWM module 1 */
192
NPCM7XX_GPIO0_IRQ = 116,
193
@@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_pwm_addr[] = {
194
0xf0104000,
195
};
196
197
+/* Direct memory-mapped access to each SMBus Module. */
198
+static const hwaddr npcm7xx_smbus_addr[] = {
199
+ 0xf0080000,
200
+ 0xf0081000,
201
+ 0xf0082000,
202
+ 0xf0083000,
203
+ 0xf0084000,
204
+ 0xf0085000,
205
+ 0xf0086000,
206
+ 0xf0087000,
207
+ 0xf0088000,
208
+ 0xf0089000,
209
+ 0xf008a000,
210
+ 0xf008b000,
211
+ 0xf008c000,
212
+ 0xf008d000,
213
+ 0xf008e000,
214
+ 0xf008f000,
215
+};
216
+
217
static const struct {
218
hwaddr regs_addr;
219
uint32_t unconnected_pins;
220
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
221
object_initialize_child(obj, "gpio[*]", &s->gpio[i], TYPE_NPCM7XX_GPIO);
222
}
223
224
+ for (i = 0; i < ARRAY_SIZE(s->smbus); i++) {
225
+ object_initialize_child(obj, "smbus[*]", &s->smbus[i],
226
+ TYPE_NPCM7XX_SMBUS);
227
+ }
228
+
229
object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI);
230
object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI);
231
232
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
233
npcm7xx_irq(s, NPCM7XX_GPIO0_IRQ + i));
234
}
235
236
+ /* SMBus modules. Cannot fail. */
237
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_smbus_addr) != ARRAY_SIZE(s->smbus));
238
+ for (i = 0; i < ARRAY_SIZE(s->smbus); i++) {
239
+ Object *obj = OBJECT(&s->smbus[i]);
240
+
241
+ sysbus_realize(SYS_BUS_DEVICE(obj), &error_abort);
242
+ sysbus_mmio_map(SYS_BUS_DEVICE(obj), 0, npcm7xx_smbus_addr[i]);
243
+ sysbus_connect_irq(SYS_BUS_DEVICE(obj), 0,
244
+ npcm7xx_irq(s, NPCM7XX_SMBUS0_IRQ + i));
245
+ }
246
+
247
/* USB Host */
248
object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true,
249
&error_abort);
250
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
251
create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB);
252
create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB);
253
create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB);
254
- create_unimplemented_device("npcm7xx.smbus[0]", 0xf0080000, 4 * KiB);
255
- create_unimplemented_device("npcm7xx.smbus[1]", 0xf0081000, 4 * KiB);
256
- create_unimplemented_device("npcm7xx.smbus[2]", 0xf0082000, 4 * KiB);
257
- create_unimplemented_device("npcm7xx.smbus[3]", 0xf0083000, 4 * KiB);
258
- create_unimplemented_device("npcm7xx.smbus[4]", 0xf0084000, 4 * KiB);
259
- create_unimplemented_device("npcm7xx.smbus[5]", 0xf0085000, 4 * KiB);
260
- create_unimplemented_device("npcm7xx.smbus[6]", 0xf0086000, 4 * KiB);
261
- create_unimplemented_device("npcm7xx.smbus[7]", 0xf0087000, 4 * KiB);
262
- create_unimplemented_device("npcm7xx.smbus[8]", 0xf0088000, 4 * KiB);
263
- create_unimplemented_device("npcm7xx.smbus[9]", 0xf0089000, 4 * KiB);
264
- create_unimplemented_device("npcm7xx.smbus[10]", 0xf008a000, 4 * KiB);
265
- create_unimplemented_device("npcm7xx.smbus[11]", 0xf008b000, 4 * KiB);
266
- create_unimplemented_device("npcm7xx.smbus[12]", 0xf008c000, 4 * KiB);
267
- create_unimplemented_device("npcm7xx.smbus[13]", 0xf008d000, 4 * KiB);
268
- create_unimplemented_device("npcm7xx.smbus[14]", 0xf008e000, 4 * KiB);
269
- create_unimplemented_device("npcm7xx.smbus[15]", 0xf008f000, 4 * KiB);
270
create_unimplemented_device("npcm7xx.espi", 0xf009f000, 4 * KiB);
271
create_unimplemented_device("npcm7xx.peci", 0xf0100000, 4 * KiB);
272
create_unimplemented_device("npcm7xx.siox[1]", 0xf0101000, 4 * KiB);
273
diff --git a/hw/i2c/npcm7xx_smbus.c b/hw/i2c/npcm7xx_smbus.c
112
new file mode 100644
274
new file mode 100644
113
index XXXXXXX..XXXXXXX
275
index XXXXXXX..XXXXXXX
114
--- /dev/null
276
--- /dev/null
115
+++ b/hw/nvram/nrf51_nvm.c
277
+++ b/hw/i2c/npcm7xx_smbus.c
116
@@ -XXX,XX +XXX,XX @@
278
@@ -XXX,XX +XXX,XX @@
117
+/*
279
+/*
118
+ * Nordic Semiconductor nRF51 non-volatile memory
280
+ * Nuvoton NPCM7xx SMBus Module.
119
+ *
281
+ *
120
+ * It provides an interface to erase regions in flash memory.
282
+ * Copyright 2020 Google LLC
121
+ * Furthermore it provides the user and factory information registers.
122
+ *
283
+ *
123
+ * Reference Manual: http://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.pdf
284
+ * This program is free software; you can redistribute it and/or modify it
285
+ * under the terms of the GNU General Public License as published by the
286
+ * Free Software Foundation; either version 2 of the License, or
287
+ * (at your option) any later version.
124
+ *
288
+ *
125
+ * See nRF51 reference manual and product sheet sections:
289
+ * This program is distributed in the hope that it will be useful, but WITHOUT
126
+ * + Non-Volatile Memory Controller (NVMC)
290
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
127
+ * + Factory Information Configuration Registers (FICR)
291
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
128
+ * + User Information Configuration Registers (UICR)
292
+ * for more details.
129
+ *
130
+ * Copyright 2018 Steffen Görtz <contrib@steffen-goertz.de>
131
+ *
132
+ * This code is licensed under the GPL version 2 or later. See
133
+ * the COPYING file in the top-level directory.
134
+ */
293
+ */
135
+
294
+
136
+#include "qemu/osdep.h"
295
+#include "qemu/osdep.h"
137
+#include "qapi/error.h"
296
+
297
+#include "hw/i2c/npcm7xx_smbus.h"
298
+#include "migration/vmstate.h"
299
+#include "qemu/bitops.h"
300
+#include "qemu/guest-random.h"
138
+#include "qemu/log.h"
301
+#include "qemu/log.h"
139
+#include "exec/address-spaces.h"
302
+#include "qemu/module.h"
140
+#include "hw/arm/nrf51.h"
303
+#include "qemu/units.h"
141
+#include "hw/nvram/nrf51_nvm.h"
304
+
142
+
305
+#include "trace.h"
143
+/*
306
+
144
+ * FICR Registers Assignments
307
+enum NPCM7xxSMBusCommonRegister {
145
+ * CODEPAGESIZE 0x010
308
+ NPCM7XX_SMB_SDA = 0x0,
146
+ * CODESIZE 0x014
309
+ NPCM7XX_SMB_ST = 0x2,
147
+ * CLENR0 0x028
310
+ NPCM7XX_SMB_CST = 0x4,
148
+ * PPFC 0x02C
311
+ NPCM7XX_SMB_CTL1 = 0x6,
149
+ * NUMRAMBLOCK 0x034
312
+ NPCM7XX_SMB_ADDR1 = 0x8,
150
+ * SIZERAMBLOCKS 0x038
313
+ NPCM7XX_SMB_CTL2 = 0xa,
151
+ * SIZERAMBLOCK[0] 0x038
314
+ NPCM7XX_SMB_ADDR2 = 0xc,
152
+ * SIZERAMBLOCK[1] 0x03C
315
+ NPCM7XX_SMB_CTL3 = 0xe,
153
+ * SIZERAMBLOCK[2] 0x040
316
+ NPCM7XX_SMB_CST2 = 0x18,
154
+ * SIZERAMBLOCK[3] 0x044
317
+ NPCM7XX_SMB_CST3 = 0x19,
155
+ * CONFIGID 0x05C
318
+ NPCM7XX_SMB_VER = 0x1f,
156
+ * DEVICEID[0] 0x060
157
+ * DEVICEID[1] 0x064
158
+ * ER[0] 0x080
159
+ * ER[1] 0x084
160
+ * ER[2] 0x088
161
+ * ER[3] 0x08C
162
+ * IR[0] 0x090
163
+ * IR[1] 0x094
164
+ * IR[2] 0x098
165
+ * IR[3] 0x09C
166
+ * DEVICEADDRTYPE 0x0A0
167
+ * DEVICEADDR[0] 0x0A4
168
+ * DEVICEADDR[1] 0x0A8
169
+ * OVERRIDEEN 0x0AC
170
+ * NRF_1MBIT[0] 0x0B0
171
+ * NRF_1MBIT[1] 0x0B4
172
+ * NRF_1MBIT[2] 0x0B8
173
+ * NRF_1MBIT[3] 0x0BC
174
+ * NRF_1MBIT[4] 0x0C0
175
+ * BLE_1MBIT[0] 0x0EC
176
+ * BLE_1MBIT[1] 0x0F0
177
+ * BLE_1MBIT[2] 0x0F4
178
+ * BLE_1MBIT[3] 0x0F8
179
+ * BLE_1MBIT[4] 0x0FC
180
+ */
181
+static const uint32_t ficr_content[64] = {
182
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000400,
183
+ 0x00000100, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000002, 0x00002000,
184
+ 0x00002000, 0x00002000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
185
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
186
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000003,
187
+ 0x12345678, 0x9ABCDEF1, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
188
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
189
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
190
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
191
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
192
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
193
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
194
+ 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
195
+};
319
+};
196
+
320
+
197
+static uint64_t ficr_read(void *opaque, hwaddr offset, unsigned int size)
321
+enum NPCM7xxSMBusBank0Register {
198
+{
322
+ NPCM7XX_SMB_ADDR3 = 0x10,
199
+ assert(offset < sizeof(ficr_content));
323
+ NPCM7XX_SMB_ADDR7 = 0x11,
200
+ return ficr_content[offset / 4];
324
+ NPCM7XX_SMB_ADDR4 = 0x12,
201
+}
325
+ NPCM7XX_SMB_ADDR8 = 0x13,
202
+
326
+ NPCM7XX_SMB_ADDR5 = 0x14,
203
+static void ficr_write(void *opaque, hwaddr offset, uint64_t value,
327
+ NPCM7XX_SMB_ADDR9 = 0x15,
204
+ unsigned int size)
328
+ NPCM7XX_SMB_ADDR6 = 0x16,
205
+{
329
+ NPCM7XX_SMB_ADDR10 = 0x17,
206
+ /* Intentionally do nothing */
330
+ NPCM7XX_SMB_CTL4 = 0x1a,
207
+}
331
+ NPCM7XX_SMB_CTL5 = 0x1b,
208
+
332
+ NPCM7XX_SMB_SCLLT = 0x1c,
209
+static const MemoryRegionOps ficr_ops = {
333
+ NPCM7XX_SMB_FIF_CTL = 0x1d,
210
+ .read = ficr_read,
334
+ NPCM7XX_SMB_SCLHT = 0x1e,
211
+ .write = ficr_write,
212
+ .impl.min_access_size = 4,
213
+ .impl.max_access_size = 4,
214
+ .endianness = DEVICE_LITTLE_ENDIAN
215
+};
335
+};
216
+
336
+
217
+/*
337
+enum NPCM7xxSMBusBank1Register {
218
+ * UICR Registers Assignments
338
+ NPCM7XX_SMB_FIF_CTS = 0x10,
219
+ * CLENR0 0x000
339
+ NPCM7XX_SMB_FAIR_PER = 0x11,
220
+ * RBPCONF 0x004
340
+ NPCM7XX_SMB_TXF_CTL = 0x12,
221
+ * XTALFREQ 0x008
341
+ NPCM7XX_SMB_T_OUT = 0x14,
222
+ * FWID 0x010
342
+ NPCM7XX_SMB_TXF_STS = 0x1a,
223
+ * BOOTLOADERADDR 0x014
343
+ NPCM7XX_SMB_RXF_STS = 0x1c,
224
+ * NRFFW[0] 0x014
344
+ NPCM7XX_SMB_RXF_CTL = 0x1e,
225
+ * NRFFW[1] 0x018
226
+ * NRFFW[2] 0x01C
227
+ * NRFFW[3] 0x020
228
+ * NRFFW[4] 0x024
229
+ * NRFFW[5] 0x028
230
+ * NRFFW[6] 0x02C
231
+ * NRFFW[7] 0x030
232
+ * NRFFW[8] 0x034
233
+ * NRFFW[9] 0x038
234
+ * NRFFW[10] 0x03C
235
+ * NRFFW[11] 0x040
236
+ * NRFFW[12] 0x044
237
+ * NRFFW[13] 0x048
238
+ * NRFFW[14] 0x04C
239
+ * NRFHW[0] 0x050
240
+ * NRFHW[1] 0x054
241
+ * NRFHW[2] 0x058
242
+ * NRFHW[3] 0x05C
243
+ * NRFHW[4] 0x060
244
+ * NRFHW[5] 0x064
245
+ * NRFHW[6] 0x068
246
+ * NRFHW[7] 0x06C
247
+ * NRFHW[8] 0x070
248
+ * NRFHW[9] 0x074
249
+ * NRFHW[10] 0x078
250
+ * NRFHW[11] 0x07C
251
+ * CUSTOMER[0] 0x080
252
+ * CUSTOMER[1] 0x084
253
+ * CUSTOMER[2] 0x088
254
+ * CUSTOMER[3] 0x08C
255
+ * CUSTOMER[4] 0x090
256
+ * CUSTOMER[5] 0x094
257
+ * CUSTOMER[6] 0x098
258
+ * CUSTOMER[7] 0x09C
259
+ * CUSTOMER[8] 0x0A0
260
+ * CUSTOMER[9] 0x0A4
261
+ * CUSTOMER[10] 0x0A8
262
+ * CUSTOMER[11] 0x0AC
263
+ * CUSTOMER[12] 0x0B0
264
+ * CUSTOMER[13] 0x0B4
265
+ * CUSTOMER[14] 0x0B8
266
+ * CUSTOMER[15] 0x0BC
267
+ * CUSTOMER[16] 0x0C0
268
+ * CUSTOMER[17] 0x0C4
269
+ * CUSTOMER[18] 0x0C8
270
+ * CUSTOMER[19] 0x0CC
271
+ * CUSTOMER[20] 0x0D0
272
+ * CUSTOMER[21] 0x0D4
273
+ * CUSTOMER[22] 0x0D8
274
+ * CUSTOMER[23] 0x0DC
275
+ * CUSTOMER[24] 0x0E0
276
+ * CUSTOMER[25] 0x0E4
277
+ * CUSTOMER[26] 0x0E8
278
+ * CUSTOMER[27] 0x0EC
279
+ * CUSTOMER[28] 0x0F0
280
+ * CUSTOMER[29] 0x0F4
281
+ * CUSTOMER[30] 0x0F8
282
+ * CUSTOMER[31] 0x0FC
283
+ */
284
+
285
+static uint64_t uicr_read(void *opaque, hwaddr offset, unsigned int size)
286
+{
287
+ NRF51NVMState *s = NRF51_NVM(opaque);
288
+
289
+ assert(offset < sizeof(s->uicr_content));
290
+ return s->uicr_content[offset / 4];
291
+}
292
+
293
+static void uicr_write(void *opaque, hwaddr offset, uint64_t value,
294
+ unsigned int size)
295
+{
296
+ NRF51NVMState *s = NRF51_NVM(opaque);
297
+
298
+ assert(offset < sizeof(s->uicr_content));
299
+ s->uicr_content[offset / 4] = value;
300
+}
301
+
302
+static const MemoryRegionOps uicr_ops = {
303
+ .read = uicr_read,
304
+ .write = uicr_write,
305
+ .impl.min_access_size = 4,
306
+ .impl.max_access_size = 4,
307
+ .endianness = DEVICE_LITTLE_ENDIAN
308
+};
345
+};
309
+
346
+
310
+
347
+/* ST fields */
311
+static uint64_t io_read(void *opaque, hwaddr offset, unsigned int size)
348
+#define NPCM7XX_SMBST_STP BIT(7)
312
+{
349
+#define NPCM7XX_SMBST_SDAST BIT(6)
313
+ NRF51NVMState *s = NRF51_NVM(opaque);
350
+#define NPCM7XX_SMBST_BER BIT(5)
314
+ uint64_t r = 0;
351
+#define NPCM7XX_SMBST_NEGACK BIT(4)
315
+
352
+#define NPCM7XX_SMBST_STASTR BIT(3)
353
+#define NPCM7XX_SMBST_NMATCH BIT(2)
354
+#define NPCM7XX_SMBST_MODE BIT(1)
355
+#define NPCM7XX_SMBST_XMIT BIT(0)
356
+
357
+/* CST fields */
358
+#define NPCM7XX_SMBCST_ARPMATCH BIT(7)
359
+#define NPCM7XX_SMBCST_MATCHAF BIT(6)
360
+#define NPCM7XX_SMBCST_TGSCL BIT(5)
361
+#define NPCM7XX_SMBCST_TSDA BIT(4)
362
+#define NPCM7XX_SMBCST_GCMATCH BIT(3)
363
+#define NPCM7XX_SMBCST_MATCH BIT(2)
364
+#define NPCM7XX_SMBCST_BB BIT(1)
365
+#define NPCM7XX_SMBCST_BUSY BIT(0)
366
+
367
+/* CST2 fields */
368
+#define NPCM7XX_SMBCST2_INTSTS BIT(7)
369
+#define NPCM7XX_SMBCST2_MATCH7F BIT(6)
370
+#define NPCM7XX_SMBCST2_MATCH6F BIT(5)
371
+#define NPCM7XX_SMBCST2_MATCH5F BIT(4)
372
+#define NPCM7XX_SMBCST2_MATCH4F BIT(3)
373
+#define NPCM7XX_SMBCST2_MATCH3F BIT(2)
374
+#define NPCM7XX_SMBCST2_MATCH2F BIT(1)
375
+#define NPCM7XX_SMBCST2_MATCH1F BIT(0)
376
+
377
+/* CST3 fields */
378
+#define NPCM7XX_SMBCST3_EO_BUSY BIT(7)
379
+#define NPCM7XX_SMBCST3_MATCH10F BIT(2)
380
+#define NPCM7XX_SMBCST3_MATCH9F BIT(1)
381
+#define NPCM7XX_SMBCST3_MATCH8F BIT(0)
382
+
383
+/* CTL1 fields */
384
+#define NPCM7XX_SMBCTL1_STASTRE BIT(7)
385
+#define NPCM7XX_SMBCTL1_NMINTE BIT(6)
386
+#define NPCM7XX_SMBCTL1_GCMEN BIT(5)
387
+#define NPCM7XX_SMBCTL1_ACK BIT(4)
388
+#define NPCM7XX_SMBCTL1_EOBINTE BIT(3)
389
+#define NPCM7XX_SMBCTL1_INTEN BIT(2)
390
+#define NPCM7XX_SMBCTL1_STOP BIT(1)
391
+#define NPCM7XX_SMBCTL1_START BIT(0)
392
+
393
+/* CTL2 fields */
394
+#define NPCM7XX_SMBCTL2_SCLFRQ(rv) extract8((rv), 1, 6)
395
+#define NPCM7XX_SMBCTL2_ENABLE BIT(0)
396
+
397
+/* CTL3 fields */
398
+#define NPCM7XX_SMBCTL3_SCL_LVL BIT(7)
399
+#define NPCM7XX_SMBCTL3_SDA_LVL BIT(6)
400
+#define NPCM7XX_SMBCTL3_BNK_SEL BIT(5)
401
+#define NPCM7XX_SMBCTL3_400K_MODE BIT(4)
402
+#define NPCM7XX_SMBCTL3_IDL_START BIT(3)
403
+#define NPCM7XX_SMBCTL3_ARPMEN BIT(2)
404
+#define NPCM7XX_SMBCTL3_SCLFRQ(rv) extract8((rv), 0, 2)
405
+
406
+/* ADDR fields */
407
+#define NPCM7XX_ADDR_EN BIT(7)
408
+#define NPCM7XX_ADDR_A(rv) extract8((rv), 0, 6)
409
+
410
+#define KEEP_OLD_BIT(o, n, b) (((n) & (~(b))) | ((o) & (b)))
411
+#define WRITE_ONE_CLEAR(o, n, b) ((n) & (b) ? (o) & (~(b)) : (o))
412
+
413
+#define NPCM7XX_SMBUS_ENABLED(s) ((s)->ctl2 & NPCM7XX_SMBCTL2_ENABLE)
414
+
415
+/* VERSION fields values, read-only. */
416
+#define NPCM7XX_SMBUS_VERSION_NUMBER 1
417
+#define NPCM7XX_SMBUS_VERSION_FIFO_SUPPORTED 0
418
+
419
+/* Reset values */
420
+#define NPCM7XX_SMB_ST_INIT_VAL 0x00
421
+#define NPCM7XX_SMB_CST_INIT_VAL 0x10
422
+#define NPCM7XX_SMB_CST2_INIT_VAL 0x00
423
+#define NPCM7XX_SMB_CST3_INIT_VAL 0x00
424
+#define NPCM7XX_SMB_CTL1_INIT_VAL 0x00
425
+#define NPCM7XX_SMB_CTL2_INIT_VAL 0x00
426
+#define NPCM7XX_SMB_CTL3_INIT_VAL 0xc0
427
+#define NPCM7XX_SMB_CTL4_INIT_VAL 0x07
428
+#define NPCM7XX_SMB_CTL5_INIT_VAL 0x00
429
+#define NPCM7XX_SMB_ADDR_INIT_VAL 0x00
430
+#define NPCM7XX_SMB_SCLLT_INIT_VAL 0x00
431
+#define NPCM7XX_SMB_SCLHT_INIT_VAL 0x00
432
+
433
+static uint8_t npcm7xx_smbus_get_version(void)
434
+{
435
+ return NPCM7XX_SMBUS_VERSION_FIFO_SUPPORTED << 7 |
436
+ NPCM7XX_SMBUS_VERSION_NUMBER;
437
+}
438
+
439
+static void npcm7xx_smbus_update_irq(NPCM7xxSMBusState *s)
440
+{
441
+ int level;
442
+
443
+ if (s->ctl1 & NPCM7XX_SMBCTL1_INTEN) {
444
+ level = !!((s->ctl1 & NPCM7XX_SMBCTL1_NMINTE &&
445
+ s->st & NPCM7XX_SMBST_NMATCH) ||
446
+ (s->st & NPCM7XX_SMBST_BER) ||
447
+ (s->st & NPCM7XX_SMBST_NEGACK) ||
448
+ (s->st & NPCM7XX_SMBST_SDAST) ||
449
+ (s->ctl1 & NPCM7XX_SMBCTL1_STASTRE &&
450
+ s->st & NPCM7XX_SMBST_SDAST) ||
451
+ (s->ctl1 & NPCM7XX_SMBCTL1_EOBINTE &&
452
+ s->cst3 & NPCM7XX_SMBCST3_EO_BUSY));
453
+
454
+ if (level) {
455
+ s->cst2 |= NPCM7XX_SMBCST2_INTSTS;
456
+ } else {
457
+ s->cst2 &= ~NPCM7XX_SMBCST2_INTSTS;
458
+ }
459
+ qemu_set_irq(s->irq, level);
460
+ }
461
+}
462
+
463
+static void npcm7xx_smbus_nack(NPCM7xxSMBusState *s)
464
+{
465
+ s->st &= ~NPCM7XX_SMBST_SDAST;
466
+ s->st |= NPCM7XX_SMBST_NEGACK;
467
+ s->status = NPCM7XX_SMBUS_STATUS_NEGACK;
468
+}
469
+
470
+static void npcm7xx_smbus_send_byte(NPCM7xxSMBusState *s, uint8_t value)
471
+{
472
+ int rv = i2c_send(s->bus, value);
473
+
474
+ if (rv) {
475
+ npcm7xx_smbus_nack(s);
476
+ } else {
477
+ s->st |= NPCM7XX_SMBST_SDAST;
478
+ }
479
+ trace_npcm7xx_smbus_send_byte((DEVICE(s)->canonical_path), value, !rv);
480
+ npcm7xx_smbus_update_irq(s);
481
+}
482
+
483
+static void npcm7xx_smbus_recv_byte(NPCM7xxSMBusState *s)
484
+{
485
+ s->sda = i2c_recv(s->bus);
486
+ s->st |= NPCM7XX_SMBST_SDAST;
487
+ if (s->st & NPCM7XX_SMBCTL1_ACK) {
488
+ trace_npcm7xx_smbus_nack(DEVICE(s)->canonical_path);
489
+ i2c_nack(s->bus);
490
+ s->st &= NPCM7XX_SMBCTL1_ACK;
491
+ }
492
+ trace_npcm7xx_smbus_recv_byte((DEVICE(s)->canonical_path), s->sda);
493
+ npcm7xx_smbus_update_irq(s);
494
+}
495
+
496
+static void npcm7xx_smbus_start(NPCM7xxSMBusState *s)
497
+{
498
+ /*
499
+ * We can start the bus if one of these is true:
500
+ * 1. The bus is idle (so we can request it)
501
+ * 2. We are the occupier (it's a repeated start condition.)
502
+ */
503
+ int available = !i2c_bus_busy(s->bus) ||
504
+ s->status != NPCM7XX_SMBUS_STATUS_IDLE;
505
+
506
+ if (available) {
507
+ s->st |= NPCM7XX_SMBST_MODE | NPCM7XX_SMBST_XMIT | NPCM7XX_SMBST_SDAST;
508
+ s->cst |= NPCM7XX_SMBCST_BUSY;
509
+ } else {
510
+ s->st &= ~NPCM7XX_SMBST_MODE;
511
+ s->cst &= ~NPCM7XX_SMBCST_BUSY;
512
+ s->st |= NPCM7XX_SMBST_BER;
513
+ }
514
+
515
+ trace_npcm7xx_smbus_start(DEVICE(s)->canonical_path, available);
516
+ s->cst |= NPCM7XX_SMBCST_BB;
517
+ s->status = NPCM7XX_SMBUS_STATUS_IDLE;
518
+ npcm7xx_smbus_update_irq(s);
519
+}
520
+
521
+static void npcm7xx_smbus_send_address(NPCM7xxSMBusState *s, uint8_t value)
522
+{
523
+ int recv;
524
+ int rv;
525
+
526
+ recv = value & BIT(0);
527
+ rv = i2c_start_transfer(s->bus, value >> 1, recv);
528
+ trace_npcm7xx_smbus_send_address(DEVICE(s)->canonical_path,
529
+ value >> 1, recv, !rv);
530
+ if (rv) {
531
+ qemu_log_mask(LOG_GUEST_ERROR,
532
+ "%s: requesting i2c bus for 0x%02x failed: %d\n",
533
+ DEVICE(s)->canonical_path, value, rv);
534
+ /* Failed to start transfer. NACK to reject.*/
535
+ if (recv) {
536
+ s->st &= ~NPCM7XX_SMBST_XMIT;
537
+ } else {
538
+ s->st |= NPCM7XX_SMBST_XMIT;
539
+ }
540
+ npcm7xx_smbus_nack(s);
541
+ npcm7xx_smbus_update_irq(s);
542
+ return;
543
+ }
544
+
545
+ s->st &= ~NPCM7XX_SMBST_NEGACK;
546
+ if (recv) {
547
+ s->status = NPCM7XX_SMBUS_STATUS_RECEIVING;
548
+ s->st &= ~NPCM7XX_SMBST_XMIT;
549
+ } else {
550
+ s->status = NPCM7XX_SMBUS_STATUS_SENDING;
551
+ s->st |= NPCM7XX_SMBST_XMIT;
552
+ }
553
+
554
+ if (s->ctl1 & NPCM7XX_SMBCTL1_STASTRE) {
555
+ s->st |= NPCM7XX_SMBST_STASTR;
556
+ if (!recv) {
557
+ s->st |= NPCM7XX_SMBST_SDAST;
558
+ }
559
+ } else if (recv) {
560
+ npcm7xx_smbus_recv_byte(s);
561
+ }
562
+ npcm7xx_smbus_update_irq(s);
563
+}
564
+
565
+static void npcm7xx_smbus_execute_stop(NPCM7xxSMBusState *s)
566
+{
567
+ i2c_end_transfer(s->bus);
568
+ s->st = 0;
569
+ s->cst = 0;
570
+ s->status = NPCM7XX_SMBUS_STATUS_IDLE;
571
+ s->cst3 |= NPCM7XX_SMBCST3_EO_BUSY;
572
+ trace_npcm7xx_smbus_stop(DEVICE(s)->canonical_path);
573
+ npcm7xx_smbus_update_irq(s);
574
+}
575
+
576
+
577
+static void npcm7xx_smbus_stop(NPCM7xxSMBusState *s)
578
+{
579
+ if (s->st & NPCM7XX_SMBST_MODE) {
580
+ switch (s->status) {
581
+ case NPCM7XX_SMBUS_STATUS_RECEIVING:
582
+ case NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE:
583
+ s->status = NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE;
584
+ break;
585
+
586
+ case NPCM7XX_SMBUS_STATUS_NEGACK:
587
+ s->status = NPCM7XX_SMBUS_STATUS_STOPPING_NEGACK;
588
+ break;
589
+
590
+ default:
591
+ npcm7xx_smbus_execute_stop(s);
592
+ break;
593
+ }
594
+ }
595
+}
596
+
597
+static uint8_t npcm7xx_smbus_read_sda(NPCM7xxSMBusState *s)
598
+{
599
+ uint8_t value = s->sda;
600
+
601
+ switch (s->status) {
602
+ case NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE:
603
+ npcm7xx_smbus_execute_stop(s);
604
+ break;
605
+
606
+ case NPCM7XX_SMBUS_STATUS_RECEIVING:
607
+ npcm7xx_smbus_recv_byte(s);
608
+ break;
609
+
610
+ default:
611
+ /* Do nothing */
612
+ break;
613
+ }
614
+
615
+ return value;
616
+}
617
+
618
+static void npcm7xx_smbus_write_sda(NPCM7xxSMBusState *s, uint8_t value)
619
+{
620
+ s->sda = value;
621
+ if (s->st & NPCM7XX_SMBST_MODE) {
622
+ switch (s->status) {
623
+ case NPCM7XX_SMBUS_STATUS_IDLE:
624
+ npcm7xx_smbus_send_address(s, value);
625
+ break;
626
+ case NPCM7XX_SMBUS_STATUS_SENDING:
627
+ npcm7xx_smbus_send_byte(s, value);
628
+ break;
629
+ default:
630
+ qemu_log_mask(LOG_GUEST_ERROR,
631
+ "%s: write to SDA in invalid status %d: %u\n",
632
+ DEVICE(s)->canonical_path, s->status, value);
633
+ break;
634
+ }
635
+ }
636
+}
637
+
638
+static void npcm7xx_smbus_write_st(NPCM7xxSMBusState *s, uint8_t value)
639
+{
640
+ s->st = WRITE_ONE_CLEAR(s->st, value, NPCM7XX_SMBST_STP);
641
+ s->st = WRITE_ONE_CLEAR(s->st, value, NPCM7XX_SMBST_BER);
642
+ s->st = WRITE_ONE_CLEAR(s->st, value, NPCM7XX_SMBST_STASTR);
643
+ s->st = WRITE_ONE_CLEAR(s->st, value, NPCM7XX_SMBST_NMATCH);
644
+
645
+ if (value & NPCM7XX_SMBST_NEGACK) {
646
+ s->st &= ~NPCM7XX_SMBST_NEGACK;
647
+ if (s->status == NPCM7XX_SMBUS_STATUS_STOPPING_NEGACK) {
648
+ npcm7xx_smbus_execute_stop(s);
649
+ }
650
+ }
651
+
652
+ if (value & NPCM7XX_SMBST_STASTR &&
653
+ s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) {
654
+ npcm7xx_smbus_recv_byte(s);
655
+ }
656
+
657
+ npcm7xx_smbus_update_irq(s);
658
+}
659
+
660
+static void npcm7xx_smbus_write_cst(NPCM7xxSMBusState *s, uint8_t value)
661
+{
662
+ uint8_t new_value = s->cst;
663
+
664
+ s->cst = WRITE_ONE_CLEAR(new_value, value, NPCM7XX_SMBCST_BB);
665
+ npcm7xx_smbus_update_irq(s);
666
+}
667
+
668
+static void npcm7xx_smbus_write_cst3(NPCM7xxSMBusState *s, uint8_t value)
669
+{
670
+ s->cst3 = WRITE_ONE_CLEAR(s->cst3, value, NPCM7XX_SMBCST3_EO_BUSY);
671
+ npcm7xx_smbus_update_irq(s);
672
+}
673
+
674
+static void npcm7xx_smbus_write_ctl1(NPCM7xxSMBusState *s, uint8_t value)
675
+{
676
+ s->ctl1 = KEEP_OLD_BIT(s->ctl1, value,
677
+ NPCM7XX_SMBCTL1_START | NPCM7XX_SMBCTL1_STOP | NPCM7XX_SMBCTL1_ACK);
678
+
679
+ if (value & NPCM7XX_SMBCTL1_START) {
680
+ npcm7xx_smbus_start(s);
681
+ }
682
+
683
+ if (value & NPCM7XX_SMBCTL1_STOP) {
684
+ npcm7xx_smbus_stop(s);
685
+ }
686
+
687
+ npcm7xx_smbus_update_irq(s);
688
+}
689
+
690
+static void npcm7xx_smbus_write_ctl2(NPCM7xxSMBusState *s, uint8_t value)
691
+{
692
+ s->ctl2 = value;
693
+
694
+ if (!NPCM7XX_SMBUS_ENABLED(s)) {
695
+ /* Disable this SMBus module. */
696
+ s->ctl1 = 0;
697
+ s->st = 0;
698
+ s->cst3 = s->cst3 & (~NPCM7XX_SMBCST3_EO_BUSY);
699
+ s->cst = 0;
700
+ }
701
+}
702
+
703
+static void npcm7xx_smbus_write_ctl3(NPCM7xxSMBusState *s, uint8_t value)
704
+{
705
+ uint8_t old_ctl3 = s->ctl3;
706
+
707
+ /* Write to SDA and SCL bits are ignored. */
708
+ s->ctl3 = KEEP_OLD_BIT(old_ctl3, value,
709
+ NPCM7XX_SMBCTL3_SCL_LVL | NPCM7XX_SMBCTL3_SDA_LVL);
710
+}
711
+
712
+static uint64_t npcm7xx_smbus_read(void *opaque, hwaddr offset, unsigned size)
713
+{
714
+ NPCM7xxSMBusState *s = opaque;
715
+ uint64_t value = 0;
716
+ uint8_t bank = s->ctl3 & NPCM7XX_SMBCTL3_BNK_SEL;
717
+
718
+ /* The order of the registers are their order in memory. */
316
+ switch (offset) {
719
+ switch (offset) {
317
+ case NRF51_NVMC_READY:
720
+ case NPCM7XX_SMB_SDA:
318
+ r = NRF51_NVMC_READY_READY;
721
+ value = npcm7xx_smbus_read_sda(s);
319
+ break;
722
+ break;
320
+ case NRF51_NVMC_CONFIG:
723
+
321
+ r = s->config;
724
+ case NPCM7XX_SMB_ST:
322
+ break;
725
+ value = s->st;
726
+ break;
727
+
728
+ case NPCM7XX_SMB_CST:
729
+ value = s->cst;
730
+ break;
731
+
732
+ case NPCM7XX_SMB_CTL1:
733
+ value = s->ctl1;
734
+ break;
735
+
736
+ case NPCM7XX_SMB_ADDR1:
737
+ value = s->addr[0];
738
+ break;
739
+
740
+ case NPCM7XX_SMB_CTL2:
741
+ value = s->ctl2;
742
+ break;
743
+
744
+ case NPCM7XX_SMB_ADDR2:
745
+ value = s->addr[1];
746
+ break;
747
+
748
+ case NPCM7XX_SMB_CTL3:
749
+ value = s->ctl3;
750
+ break;
751
+
752
+ case NPCM7XX_SMB_CST2:
753
+ value = s->cst2;
754
+ break;
755
+
756
+ case NPCM7XX_SMB_CST3:
757
+ value = s->cst3;
758
+ break;
759
+
760
+ case NPCM7XX_SMB_VER:
761
+ value = npcm7xx_smbus_get_version();
762
+ break;
763
+
764
+ /* This register is either invalid or banked at this point. */
323
+ default:
765
+ default:
324
+ qemu_log_mask(LOG_GUEST_ERROR,
766
+ if (bank) {
325
+ "%s: bad read offset 0x%" HWADDR_PRIx "\n", __func__, offset);
767
+ /* Bank 1 */
326
+ break;
768
+ qemu_log_mask(LOG_GUEST_ERROR,
327
+ }
769
+ "%s: read from invalid offset 0x%" HWADDR_PRIx "\n",
328
+
770
+ DEVICE(s)->canonical_path, offset);
329
+ return r;
330
+}
331
+
332
+static void io_write(void *opaque, hwaddr offset, uint64_t value,
333
+ unsigned int size)
334
+{
335
+ NRF51NVMState *s = NRF51_NVM(opaque);
336
+
337
+ switch (offset) {
338
+ case NRF51_NVMC_CONFIG:
339
+ s->config = value & NRF51_NVMC_CONFIG_MASK;
340
+ break;
341
+ case NRF51_NVMC_ERASEPCR0:
342
+ case NRF51_NVMC_ERASEPCR1:
343
+ if (s->config & NRF51_NVMC_CONFIG_EEN) {
344
+ /* Mask in-page sub address */
345
+ value &= ~(NRF51_PAGE_SIZE - 1);
346
+ if (value <= (s->flash_size - NRF51_PAGE_SIZE)) {
347
+ memset(s->storage + value, 0xFF, NRF51_PAGE_SIZE);
348
+ memory_region_flush_rom_device(&s->flash, value,
349
+ NRF51_PAGE_SIZE);
350
+ }
351
+ } else {
771
+ } else {
352
+ qemu_log_mask(LOG_GUEST_ERROR,
772
+ /* Bank 0 */
353
+ "%s: Flash erase at 0x%" HWADDR_PRIx" while flash not erasable.\n",
773
+ switch (offset) {
354
+ __func__, offset);
774
+ case NPCM7XX_SMB_ADDR3:
355
+ }
775
+ value = s->addr[2];
356
+ break;
776
+ break;
357
+ case NRF51_NVMC_ERASEALL:
777
+
358
+ if (value == NRF51_NVMC_ERASE) {
778
+ case NPCM7XX_SMB_ADDR7:
359
+ if (s->config & NRF51_NVMC_CONFIG_EEN) {
779
+ value = s->addr[6];
360
+ memset(s->storage, 0xFF, s->flash_size);
780
+ break;
361
+ memory_region_flush_rom_device(&s->flash, 0, s->flash_size);
781
+
362
+ memset(s->uicr_content, 0xFF, sizeof(s->uicr_content));
782
+ case NPCM7XX_SMB_ADDR4:
363
+ } else {
783
+ value = s->addr[3];
364
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Flash not erasable.\n",
784
+ break;
365
+ __func__);
785
+
786
+ case NPCM7XX_SMB_ADDR8:
787
+ value = s->addr[7];
788
+ break;
789
+
790
+ case NPCM7XX_SMB_ADDR5:
791
+ value = s->addr[4];
792
+ break;
793
+
794
+ case NPCM7XX_SMB_ADDR9:
795
+ value = s->addr[8];
796
+ break;
797
+
798
+ case NPCM7XX_SMB_ADDR6:
799
+ value = s->addr[5];
800
+ break;
801
+
802
+ case NPCM7XX_SMB_ADDR10:
803
+ value = s->addr[9];
804
+ break;
805
+
806
+ case NPCM7XX_SMB_CTL4:
807
+ value = s->ctl4;
808
+ break;
809
+
810
+ case NPCM7XX_SMB_CTL5:
811
+ value = s->ctl5;
812
+ break;
813
+
814
+ case NPCM7XX_SMB_SCLLT:
815
+ value = s->scllt;
816
+ break;
817
+
818
+ case NPCM7XX_SMB_SCLHT:
819
+ value = s->sclht;
820
+ break;
821
+
822
+ default:
823
+ qemu_log_mask(LOG_GUEST_ERROR,
824
+ "%s: read from invalid offset 0x%" HWADDR_PRIx "\n",
825
+ DEVICE(s)->canonical_path, offset);
826
+ break;
366
+ }
827
+ }
367
+ }
828
+ }
368
+ break;
829
+ break;
369
+ case NRF51_NVMC_ERASEUICR:
830
+ }
370
+ if (value == NRF51_NVMC_ERASE) {
831
+
371
+ memset(s->uicr_content, 0xFF, sizeof(s->uicr_content));
832
+ trace_npcm7xx_smbus_read(DEVICE(s)->canonical_path, offset, value, size);
833
+
834
+ return value;
835
+}
836
+
837
+static void npcm7xx_smbus_write(void *opaque, hwaddr offset, uint64_t value,
838
+ unsigned size)
839
+{
840
+ NPCM7xxSMBusState *s = opaque;
841
+ uint8_t bank = s->ctl3 & NPCM7XX_SMBCTL3_BNK_SEL;
842
+
843
+ trace_npcm7xx_smbus_write(DEVICE(s)->canonical_path, offset, value, size);
844
+
845
+ /* The order of the registers are their order in memory. */
846
+ switch (offset) {
847
+ case NPCM7XX_SMB_SDA:
848
+ npcm7xx_smbus_write_sda(s, value);
849
+ break;
850
+
851
+ case NPCM7XX_SMB_ST:
852
+ npcm7xx_smbus_write_st(s, value);
853
+ break;
854
+
855
+ case NPCM7XX_SMB_CST:
856
+ npcm7xx_smbus_write_cst(s, value);
857
+ break;
858
+
859
+ case NPCM7XX_SMB_CTL1:
860
+ npcm7xx_smbus_write_ctl1(s, value);
861
+ break;
862
+
863
+ case NPCM7XX_SMB_ADDR1:
864
+ s->addr[0] = value;
865
+ break;
866
+
867
+ case NPCM7XX_SMB_CTL2:
868
+ npcm7xx_smbus_write_ctl2(s, value);
869
+ break;
870
+
871
+ case NPCM7XX_SMB_ADDR2:
872
+ s->addr[1] = value;
873
+ break;
874
+
875
+ case NPCM7XX_SMB_CTL3:
876
+ npcm7xx_smbus_write_ctl3(s, value);
877
+ break;
878
+
879
+ case NPCM7XX_SMB_CST2:
880
+ qemu_log_mask(LOG_GUEST_ERROR,
881
+ "%s: write to read-only reg: offset 0x%" HWADDR_PRIx "\n",
882
+ DEVICE(s)->canonical_path, offset);
883
+ break;
884
+
885
+ case NPCM7XX_SMB_CST3:
886
+ npcm7xx_smbus_write_cst3(s, value);
887
+ break;
888
+
889
+ case NPCM7XX_SMB_VER:
890
+ qemu_log_mask(LOG_GUEST_ERROR,
891
+ "%s: write to read-only reg: offset 0x%" HWADDR_PRIx "\n",
892
+ DEVICE(s)->canonical_path, offset);
893
+ break;
894
+
895
+ /* This register is either invalid or banked at this point. */
896
+ default:
897
+ if (bank) {
898
+ /* Bank 1 */
899
+ qemu_log_mask(LOG_GUEST_ERROR,
900
+ "%s: write to invalid offset 0x%" HWADDR_PRIx "\n",
901
+ DEVICE(s)->canonical_path, offset);
902
+ } else {
903
+ /* Bank 0 */
904
+ switch (offset) {
905
+ case NPCM7XX_SMB_ADDR3:
906
+ s->addr[2] = value;
907
+ break;
908
+
909
+ case NPCM7XX_SMB_ADDR7:
910
+ s->addr[6] = value;
911
+ break;
912
+
913
+ case NPCM7XX_SMB_ADDR4:
914
+ s->addr[3] = value;
915
+ break;
916
+
917
+ case NPCM7XX_SMB_ADDR8:
918
+ s->addr[7] = value;
919
+ break;
920
+
921
+ case NPCM7XX_SMB_ADDR5:
922
+ s->addr[4] = value;
923
+ break;
924
+
925
+ case NPCM7XX_SMB_ADDR9:
926
+ s->addr[8] = value;
927
+ break;
928
+
929
+ case NPCM7XX_SMB_ADDR6:
930
+ s->addr[5] = value;
931
+ break;
932
+
933
+ case NPCM7XX_SMB_ADDR10:
934
+ s->addr[9] = value;
935
+ break;
936
+
937
+ case NPCM7XX_SMB_CTL4:
938
+ s->ctl4 = value;
939
+ break;
940
+
941
+ case NPCM7XX_SMB_CTL5:
942
+ s->ctl5 = value;
943
+ break;
944
+
945
+ case NPCM7XX_SMB_SCLLT:
946
+ s->scllt = value;
947
+ break;
948
+
949
+ case NPCM7XX_SMB_SCLHT:
950
+ s->sclht = value;
951
+ break;
952
+
953
+ default:
954
+ qemu_log_mask(LOG_GUEST_ERROR,
955
+ "%s: write to invalid offset 0x%" HWADDR_PRIx "\n",
956
+ DEVICE(s)->canonical_path, offset);
957
+ break;
958
+ }
372
+ }
959
+ }
373
+ break;
960
+ break;
374
+
961
+ }
375
+ default:
962
+}
376
+ qemu_log_mask(LOG_GUEST_ERROR,
963
+
377
+ "%s: bad write offset 0x%" HWADDR_PRIx "\n", __func__, offset);
964
+static const MemoryRegionOps npcm7xx_smbus_ops = {
378
+ }
965
+ .read = npcm7xx_smbus_read,
379
+}
966
+ .write = npcm7xx_smbus_write,
380
+
967
+ .endianness = DEVICE_LITTLE_ENDIAN,
381
+static const MemoryRegionOps io_ops = {
968
+ .valid = {
382
+ .read = io_read,
969
+ .min_access_size = 1,
383
+ .write = io_write,
970
+ .max_access_size = 1,
384
+ .impl.min_access_size = 4,
971
+ .unaligned = false,
385
+ .impl.max_access_size = 4,
972
+ },
386
+ .endianness = DEVICE_LITTLE_ENDIAN,
387
+};
973
+};
388
+
974
+
389
+
975
+static void npcm7xx_smbus_enter_reset(Object *obj, ResetType type)
390
+static void flash_write(void *opaque, hwaddr offset, uint64_t value,
976
+{
391
+ unsigned int size)
977
+ NPCM7xxSMBusState *s = NPCM7XX_SMBUS(obj);
392
+{
978
+
393
+ NRF51NVMState *s = NRF51_NVM(opaque);
979
+ s->st = NPCM7XX_SMB_ST_INIT_VAL;
394
+
980
+ s->cst = NPCM7XX_SMB_CST_INIT_VAL;
395
+ if (s->config & NRF51_NVMC_CONFIG_WEN) {
981
+ s->cst2 = NPCM7XX_SMB_CST2_INIT_VAL;
396
+ uint32_t oldval;
982
+ s->cst3 = NPCM7XX_SMB_CST3_INIT_VAL;
397
+
983
+ s->ctl1 = NPCM7XX_SMB_CTL1_INIT_VAL;
398
+ assert(offset + size <= s->flash_size);
984
+ s->ctl2 = NPCM7XX_SMB_CTL2_INIT_VAL;
399
+
985
+ s->ctl3 = NPCM7XX_SMB_CTL3_INIT_VAL;
400
+ /* NOR Flash only allows bits to be flipped from 1's to 0's on write */
986
+ s->ctl4 = NPCM7XX_SMB_CTL4_INIT_VAL;
401
+ oldval = ldl_le_p(s->storage + offset);
987
+ s->ctl5 = NPCM7XX_SMB_CTL5_INIT_VAL;
402
+ oldval &= value;
988
+
403
+ stl_le_p(s->storage + offset, oldval);
989
+ for (int i = 0; i < NPCM7XX_SMBUS_NR_ADDRS; ++i) {
404
+
990
+ s->addr[i] = NPCM7XX_SMB_ADDR_INIT_VAL;
405
+ memory_region_flush_rom_device(&s->flash, offset, size);
991
+ }
406
+ } else {
992
+ s->scllt = NPCM7XX_SMB_SCLLT_INIT_VAL;
407
+ qemu_log_mask(LOG_GUEST_ERROR,
993
+ s->sclht = NPCM7XX_SMB_SCLHT_INIT_VAL;
408
+ "%s: Flash write 0x%" HWADDR_PRIx" while flash not writable.\n",
994
+
409
+ __func__, offset);
995
+ s->status = NPCM7XX_SMBUS_STATUS_IDLE;
410
+ }
996
+}
411
+}
997
+
412
+
998
+static void npcm7xx_smbus_hold_reset(Object *obj)
413
+
999
+{
414
+
1000
+ NPCM7xxSMBusState *s = NPCM7XX_SMBUS(obj);
415
+static const MemoryRegionOps flash_ops = {
1001
+
416
+ .write = flash_write,
1002
+ qemu_irq_lower(s->irq);
417
+ .valid.min_access_size = 4,
1003
+}
418
+ .valid.max_access_size = 4,
1004
+
419
+ .endianness = DEVICE_LITTLE_ENDIAN,
1005
+static void npcm7xx_smbus_init(Object *obj)
1006
+{
1007
+ NPCM7xxSMBusState *s = NPCM7XX_SMBUS(obj);
1008
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
1009
+
1010
+ sysbus_init_irq(sbd, &s->irq);
1011
+ memory_region_init_io(&s->iomem, obj, &npcm7xx_smbus_ops, s,
1012
+ "regs", 4 * KiB);
1013
+ sysbus_init_mmio(sbd, &s->iomem);
1014
+
1015
+ s->bus = i2c_init_bus(DEVICE(s), "i2c-bus");
1016
+ s->status = NPCM7XX_SMBUS_STATUS_IDLE;
1017
+}
1018
+
1019
+static const VMStateDescription vmstate_npcm7xx_smbus = {
1020
+ .name = "npcm7xx-smbus",
1021
+ .version_id = 0,
1022
+ .minimum_version_id = 0,
1023
+ .fields = (VMStateField[]) {
1024
+ VMSTATE_UINT8(sda, NPCM7xxSMBusState),
1025
+ VMSTATE_UINT8(st, NPCM7xxSMBusState),
1026
+ VMSTATE_UINT8(cst, NPCM7xxSMBusState),
1027
+ VMSTATE_UINT8(cst2, NPCM7xxSMBusState),
1028
+ VMSTATE_UINT8(cst3, NPCM7xxSMBusState),
1029
+ VMSTATE_UINT8(ctl1, NPCM7xxSMBusState),
1030
+ VMSTATE_UINT8(ctl2, NPCM7xxSMBusState),
1031
+ VMSTATE_UINT8(ctl3, NPCM7xxSMBusState),
1032
+ VMSTATE_UINT8(ctl4, NPCM7xxSMBusState),
1033
+ VMSTATE_UINT8(ctl5, NPCM7xxSMBusState),
1034
+ VMSTATE_UINT8_ARRAY(addr, NPCM7xxSMBusState, NPCM7XX_SMBUS_NR_ADDRS),
1035
+ VMSTATE_UINT8(scllt, NPCM7xxSMBusState),
1036
+ VMSTATE_UINT8(sclht, NPCM7xxSMBusState),
1037
+ VMSTATE_END_OF_LIST(),
1038
+ },
420
+};
1039
+};
421
+
1040
+
422
+static void nrf51_nvm_init(Object *obj)
1041
+static void npcm7xx_smbus_class_init(ObjectClass *klass, void *data)
423
+{
1042
+{
424
+ NRF51NVMState *s = NRF51_NVM(obj);
1043
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
425
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
1044
+ DeviceClass *dc = DEVICE_CLASS(klass);
426
+
1045
+
427
+ memory_region_init_io(&s->mmio, obj, &io_ops, s, "nrf51_soc.nvmc",
1046
+ dc->desc = "NPCM7xx System Management Bus";
428
+ NRF51_NVMC_SIZE);
1047
+ dc->vmsd = &vmstate_npcm7xx_smbus;
429
+ sysbus_init_mmio(sbd, &s->mmio);
1048
+ rc->phases.enter = npcm7xx_smbus_enter_reset;
430
+
1049
+ rc->phases.hold = npcm7xx_smbus_hold_reset;
431
+ memory_region_init_io(&s->ficr, obj, &ficr_ops, s, "nrf51_soc.ficr",
1050
+}
432
+ sizeof(ficr_content));
1051
+
433
+ sysbus_init_mmio(sbd, &s->ficr);
1052
+static const TypeInfo npcm7xx_smbus_types[] = {
434
+
1053
+ {
435
+ memory_region_init_io(&s->uicr, obj, &uicr_ops, s, "nrf51_soc.uicr",
1054
+ .name = TYPE_NPCM7XX_SMBUS,
436
+ sizeof(s->uicr_content));
1055
+ .parent = TYPE_SYS_BUS_DEVICE,
437
+ sysbus_init_mmio(sbd, &s->uicr);
1056
+ .instance_size = sizeof(NPCM7xxSMBusState),
438
+}
1057
+ .class_init = npcm7xx_smbus_class_init,
439
+
1058
+ .instance_init = npcm7xx_smbus_init,
440
+static void nrf51_nvm_realize(DeviceState *dev, Error **errp)
1059
+ },
441
+{
442
+ NRF51NVMState *s = NRF51_NVM(dev);
443
+ Error *err = NULL;
444
+
445
+ memory_region_init_rom_device(&s->flash, OBJECT(dev), &flash_ops, s,
446
+ "nrf51_soc.flash", s->flash_size, &err);
447
+ if (err) {
448
+ error_propagate(errp, err);
449
+ return;
450
+ }
451
+
452
+ s->storage = memory_region_get_ram_ptr(&s->flash);
453
+ sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->flash);
454
+}
455
+
456
+static void nrf51_nvm_reset(DeviceState *dev)
457
+{
458
+ NRF51NVMState *s = NRF51_NVM(dev);
459
+
460
+ s->config = 0x00;
461
+ memset(s->uicr_content, 0xFF, sizeof(s->uicr_content));
462
+}
463
+
464
+static Property nrf51_nvm_properties[] = {
465
+ DEFINE_PROP_UINT32("flash-size", NRF51NVMState, flash_size, 0x40000),
466
+ DEFINE_PROP_END_OF_LIST(),
467
+};
1060
+};
468
+
1061
+DEFINE_TYPES(npcm7xx_smbus_types);
469
+static const VMStateDescription vmstate_nvm = {
1062
diff --git a/hw/i2c/meson.build b/hw/i2c/meson.build
470
+ .name = "nrf51_soc.nvm",
1063
index XXXXXXX..XXXXXXX 100644
471
+ .version_id = 1,
1064
--- a/hw/i2c/meson.build
472
+ .minimum_version_id = 1,
1065
+++ b/hw/i2c/meson.build
473
+ .fields = (VMStateField[]) {
1066
@@ -XXX,XX +XXX,XX @@ i2c_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_i2c.c'))
474
+ VMSTATE_UINT32_ARRAY(uicr_content, NRF51NVMState,
1067
i2c_ss.add(when: 'CONFIG_IMX_I2C', if_true: files('imx_i2c.c'))
475
+ NRF51_UICR_FIXTURE_SIZE),
1068
i2c_ss.add(when: 'CONFIG_MPC_I2C', if_true: files('mpc_i2c.c'))
476
+ VMSTATE_UINT32(config, NRF51NVMState),
1069
i2c_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('microbit_i2c.c'))
477
+ VMSTATE_END_OF_LIST()
1070
+i2c_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_smbus.c'))
478
+ }
1071
i2c_ss.add(when: 'CONFIG_SMBUS_EEPROM', if_true: files('smbus_eeprom.c'))
479
+};
1072
i2c_ss.add(when: 'CONFIG_VERSATILE_I2C', if_true: files('versatile_i2c.c'))
480
+
1073
i2c_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_i2c.c'))
481
+static void nrf51_nvm_class_init(ObjectClass *klass, void *data)
1074
diff --git a/hw/i2c/trace-events b/hw/i2c/trace-events
482
+{
1075
index XXXXXXX..XXXXXXX 100644
483
+ DeviceClass *dc = DEVICE_CLASS(klass);
1076
--- a/hw/i2c/trace-events
484
+
1077
+++ b/hw/i2c/trace-events
485
+ dc->props = nrf51_nvm_properties;
1078
@@ -XXX,XX +XXX,XX @@ aspeed_i2c_bus_read(uint32_t busid, uint64_t offset, unsigned size, uint64_t val
486
+ dc->vmsd = &vmstate_nvm;
1079
aspeed_i2c_bus_write(uint32_t busid, uint64_t offset, unsigned size, uint64_t value) "bus[%d]: To 0x%" PRIx64 " of size %u: 0x%" PRIx64
487
+ dc->realize = nrf51_nvm_realize;
1080
aspeed_i2c_bus_send(const char *mode, int i, int count, uint8_t byte) "%s send %d/%d 0x%02x"
488
+ dc->reset = nrf51_nvm_reset;
1081
aspeed_i2c_bus_recv(const char *mode, int i, int count, uint8_t byte) "%s recv %d/%d 0x%02x"
489
+}
1082
+
490
+
1083
+# npcm7xx_smbus.c
491
+static const TypeInfo nrf51_nvm_info = {
1084
+
492
+ .name = TYPE_NRF51_NVM,
1085
+npcm7xx_smbus_read(const char *id, uint64_t offset, uint64_t value, unsigned size) "%s offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u"
493
+ .parent = TYPE_SYS_BUS_DEVICE,
1086
+npcm7xx_smbus_write(const char *id, uint64_t offset, uint64_t value, unsigned size) "%s offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u"
494
+ .instance_size = sizeof(NRF51NVMState),
1087
+npcm7xx_smbus_start(const char *id, int success) "%s starting, success: %d"
495
+ .instance_init = nrf51_nvm_init,
1088
+npcm7xx_smbus_send_address(const char *id, uint8_t addr, int recv, int success) "%s sending address: 0x%02x, recv: %d, success: %d"
496
+ .class_init = nrf51_nvm_class_init
1089
+npcm7xx_smbus_send_byte(const char *id, uint8_t value, int success) "%s send byte: 0x%02x, success: %d"
497
+};
1090
+npcm7xx_smbus_recv_byte(const char *id, uint8_t value) "%s recv byte: 0x%02x"
498
+
1091
+npcm7xx_smbus_stop(const char *id) "%s stopping"
499
+static void nrf51_nvm_register_types(void)
1092
+npcm7xx_smbus_nack(const char *id) "%s nacking"
500
+{
501
+ type_register_static(&nrf51_nvm_info);
502
+}
503
+
504
+type_init(nrf51_nvm_register_types)
505
--
1093
--
506
2.20.1
1094
2.20.1
507
1095
508
1096
diff view generated by jsdifflib
1
From: Steffen Görtz <contrib@steffen-goertz.de>
1
From: Hao Wu <wuhaotsh@google.com>
2
2
3
Signed-off-by: Steffen Görtz <contrib@steffen-goertz.de>
3
Add I2C temperature sensors for NPCM750 eval board.
4
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
4
5
Acked-by: Thomas Huth <thuth@redhat.com>
5
Reviewed-by: Doug Evans<dje@google.com>
6
Reviewed-by: Tyrong Ting<kfting@nuvoton.com>
7
Signed-off-by: Hao Wu <wuhaotsh@google.com>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Message-id: 20190201023357.22596-4-stefanha@redhat.com
9
Message-id: 20210210220426.3577804-3-wuhaotsh@google.com
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
11
---
10
tests/microbit-test.c | 108 ++++++++++++++++++++++++++++++++++++++++++
12
hw/arm/npcm7xx_boards.c | 19 +++++++++++++++++++
11
1 file changed, 108 insertions(+)
13
1 file changed, 19 insertions(+)
12
14
13
diff --git a/tests/microbit-test.c b/tests/microbit-test.c
15
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
14
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
15
--- a/tests/microbit-test.c
17
--- a/hw/arm/npcm7xx_boards.c
16
+++ b/tests/microbit-test.c
18
+++ b/hw/arm/npcm7xx_boards.c
17
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ static NPCM7xxState *npcm7xx_create_soc(MachineState *machine,
18
#include "hw/arm/nrf51.h"
20
return NPCM7XX(obj);
19
#include "hw/char/nrf51_uart.h"
20
#include "hw/gpio/nrf51_gpio.h"
21
+#include "hw/nvram/nrf51_nvm.h"
22
#include "hw/timer/nrf51_timer.h"
23
#include "hw/i2c/microbit_i2c.h"
24
25
@@ -XXX,XX +XXX,XX @@ static void test_microbit_i2c(void)
26
qtest_quit(qts);
27
}
21
}
28
22
29
+#define FLASH_SIZE (256 * NRF51_PAGE_SIZE)
23
+static I2CBus *npcm7xx_i2c_get_bus(NPCM7xxState *soc, uint32_t num)
30
+
31
+static void fill_and_erase(QTestState *qts, hwaddr base, hwaddr size,
32
+ uint32_t address_reg)
33
+{
24
+{
34
+ hwaddr i;
25
+ g_assert(num < ARRAY_SIZE(soc->smbus));
35
+
26
+ return I2C_BUS(qdev_get_child_bus(DEVICE(&soc->smbus[num]), "i2c-bus"));
36
+ /* Erase Page */
37
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x02);
38
+ qtest_writel(qts, NRF51_NVMC_BASE + address_reg, base);
39
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x00);
40
+
41
+ /* Check memory */
42
+ for (i = 0; i < size / 4; i++) {
43
+ g_assert_cmpuint(qtest_readl(qts, base + i * 4), ==, 0xFFFFFFFF);
44
+ }
45
+
46
+ /* Fill memory */
47
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x01);
48
+ for (i = 0; i < size / 4; i++) {
49
+ qtest_writel(qts, base + i * 4, i);
50
+ g_assert_cmpuint(qtest_readl(qts, base + i * 4), ==, i);
51
+ }
52
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x00);
53
+}
27
+}
54
+
28
+
55
+static void test_nrf51_nvmc(void)
29
+static void npcm750_evb_i2c_init(NPCM7xxState *soc)
56
+{
30
+{
57
+ uint32_t value;
31
+ /* lm75 temperature sensor on SVB, tmp105 is compatible */
58
+ hwaddr i;
32
+ i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 0), "tmp105", 0x48);
59
+ QTestState *qts = qtest_init("-M microbit");
33
+ /* lm75 temperature sensor on EB, tmp105 is compatible */
60
+
34
+ i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), "tmp105", 0x48);
61
+ /* Test always ready */
35
+ /* tmp100 temperature sensor on EB, tmp105 is compatible */
62
+ value = qtest_readl(qts, NRF51_NVMC_BASE + NRF51_NVMC_READY);
36
+ i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 2), "tmp105", 0x48);
63
+ g_assert_cmpuint(value & 0x01, ==, 0x01);
37
+ /* tmp100 temperature sensor on SVB, tmp105 is compatible */
64
+
38
+ i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 6), "tmp105", 0x48);
65
+ /* Test write-read config register */
66
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x03);
67
+ g_assert_cmpuint(qtest_readl(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG),
68
+ ==, 0x03);
69
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x00);
70
+ g_assert_cmpuint(qtest_readl(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG),
71
+ ==, 0x00);
72
+
73
+ /* Test PCR0 */
74
+ fill_and_erase(qts, NRF51_FLASH_BASE, NRF51_PAGE_SIZE,
75
+ NRF51_NVMC_ERASEPCR0);
76
+ fill_and_erase(qts, NRF51_FLASH_BASE + NRF51_PAGE_SIZE,
77
+ NRF51_PAGE_SIZE, NRF51_NVMC_ERASEPCR0);
78
+
79
+ /* Test PCR1 */
80
+ fill_and_erase(qts, NRF51_FLASH_BASE, NRF51_PAGE_SIZE,
81
+ NRF51_NVMC_ERASEPCR1);
82
+ fill_and_erase(qts, NRF51_FLASH_BASE + NRF51_PAGE_SIZE,
83
+ NRF51_PAGE_SIZE, NRF51_NVMC_ERASEPCR1);
84
+
85
+ /* Erase all */
86
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x02);
87
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_ERASEALL, 0x01);
88
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x00);
89
+
90
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x01);
91
+ for (i = 0; i < FLASH_SIZE / 4; i++) {
92
+ qtest_writel(qts, NRF51_FLASH_BASE + i * 4, i);
93
+ g_assert_cmpuint(qtest_readl(qts, NRF51_FLASH_BASE + i * 4), ==, i);
94
+ }
95
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x00);
96
+
97
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x02);
98
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_ERASEALL, 0x01);
99
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x00);
100
+
101
+ for (i = 0; i < FLASH_SIZE / 4; i++) {
102
+ g_assert_cmpuint(qtest_readl(qts, NRF51_FLASH_BASE + i * 4),
103
+ ==, 0xFFFFFFFF);
104
+ }
105
+
106
+ /* Erase UICR */
107
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x02);
108
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_ERASEUICR, 0x01);
109
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x00);
110
+
111
+ for (i = 0; i < NRF51_UICR_SIZE / 4; i++) {
112
+ g_assert_cmpuint(qtest_readl(qts, NRF51_UICR_BASE + i * 4),
113
+ ==, 0xFFFFFFFF);
114
+ }
115
+
116
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x01);
117
+ for (i = 0; i < NRF51_UICR_SIZE / 4; i++) {
118
+ qtest_writel(qts, NRF51_UICR_BASE + i * 4, i);
119
+ g_assert_cmpuint(qtest_readl(qts, NRF51_UICR_BASE + i * 4), ==, i);
120
+ }
121
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x00);
122
+
123
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x02);
124
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_ERASEUICR, 0x01);
125
+ qtest_writel(qts, NRF51_NVMC_BASE + NRF51_NVMC_CONFIG, 0x00);
126
+
127
+ for (i = 0; i < NRF51_UICR_SIZE / 4; i++) {
128
+ g_assert_cmpuint(qtest_readl(qts, NRF51_UICR_BASE + i * 4),
129
+ ==, 0xFFFFFFFF);
130
+ }
131
+
132
+ qtest_quit(qts);
133
+}
39
+}
134
+
40
+
135
static void test_nrf51_gpio(void)
41
static void npcm750_evb_init(MachineState *machine)
136
{
42
{
137
size_t i;
43
NPCM7xxState *soc;
138
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
44
@@ -XXX,XX +XXX,XX @@ static void npcm750_evb_init(MachineState *machine)
139
45
140
qtest_add_func("/microbit/nrf51/uart", test_nrf51_uart);
46
npcm7xx_load_bootrom(machine, soc);
141
qtest_add_func("/microbit/nrf51/gpio", test_nrf51_gpio);
47
npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0, 0));
142
+ qtest_add_func("/microbit/nrf51/nvmc", test_nrf51_nvmc);
48
+ npcm750_evb_i2c_init(soc);
143
qtest_add_func("/microbit/nrf51/timer", test_nrf51_timer);
49
npcm7xx_load_kernel(machine, soc);
144
qtest_add_func("/microbit/microbit/i2c", test_microbit_i2c);
50
}
145
51
146
--
52
--
147
2.20.1
53
2.20.1
148
54
149
55
diff view generated by jsdifflib
1
Add a model of the MPS2 FPGA image described in Application Note
1
From: Hao Wu <wuhaotsh@google.com>
2
AN521. This is identical to the AN505 image, except that it uses
3
the SSE-200 rather than the IoTKit and so has two Cortex-M33 CPUs.
4
2
3
Add AT24 EEPROM and temperature sensors for GSJ machine.
4
5
Reviewed-by: Doug Evans<dje@google.com>
6
Reviewed-by: Tyrong Ting<kfting@nuvoton.com>
7
Signed-off-by: Hao Wu <wuhaotsh@google.com>
8
Message-id: 20210210220426.3577804-4-wuhaotsh@google.com
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20190121185118.18550-24-peter.maydell@linaro.org
8
---
11
---
9
hw/arm/mps2-tz.c | 38 ++++++++++++++++++++++++++++++++++++--
12
hw/arm/npcm7xx_boards.c | 27 +++++++++++++++++++++++++++
10
1 file changed, 36 insertions(+), 2 deletions(-)
13
hw/arm/Kconfig | 1 +
14
2 files changed, 28 insertions(+)
11
15
12
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
16
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
13
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/arm/mps2-tz.c
18
--- a/hw/arm/npcm7xx_boards.c
15
+++ b/hw/arm/mps2-tz.c
19
+++ b/hw/arm/npcm7xx_boards.c
16
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@
17
* as seen by the guest depend significantly on the FPGA image.
21
#include "exec/address-spaces.h"
18
* This source file covers the following FPGA images, for TrustZone cores:
22
#include "hw/arm/npcm7xx.h"
19
* "mps2-an505" -- Cortex-M33 as documented in ARM Application Note AN505
23
#include "hw/core/cpu.h"
20
+ * "mps2-an521" -- Dual Cortex-M33 as documented in Application Note AN521
24
+#include "hw/i2c/smbus_eeprom.h"
21
*
25
#include "hw/loader.h"
22
* Links to the TRM for the board itself and to the various Application
26
#include "hw/qdev-properties.h"
23
* Notes which document the FPGA images can be found here:
27
#include "qapi/error.h"
24
@@ -XXX,XX +XXX,XX @@
28
@@ -XXX,XX +XXX,XX @@ static I2CBus *npcm7xx_i2c_get_bus(NPCM7xxState *soc, uint32_t num)
25
* http://infocenter.arm.com/help/topic/com.arm.doc.100112_0200_06_en/versatile_express_cortex_m_prototyping_systems_v2m_mps2_and_v2m_mps2plus_technical_reference_100112_0200_06_en.pdf
29
return I2C_BUS(qdev_get_child_bus(DEVICE(&soc->smbus[num]), "i2c-bus"));
26
* Application Note AN505:
27
* http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
28
+ * Application Note AN521:
29
+ * http://infocenter.arm.com/help/topic/com.arm.doc.dai0521c/index.html
30
*
31
* The AN505 defers to the Cortex-M33 processor ARMv8M IoT Kit FVP User Guide
32
* (ARM ECM0601256) for the details of some of the device layout:
33
* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
34
+ * Similarly, the AN521 uses the SSE-200, and the SSE-200 TRM defines
35
+ * most of the device layout:
36
+ * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
37
+ *
38
*/
39
40
#include "qemu/osdep.h"
41
@@ -XXX,XX +XXX,XX @@ typedef struct {
42
MachineClass parent;
43
MPS2TZFPGAType fpga_type;
44
uint32_t scc_id;
45
+ const char *armsse_type;
46
} MPS2TZMachineClass;
47
48
typedef struct {
49
@@ -XXX,XX +XXX,XX @@ typedef struct {
50
51
#define TYPE_MPS2TZ_MACHINE "mps2tz"
52
#define TYPE_MPS2TZ_AN505_MACHINE MACHINE_TYPE_NAME("mps2-an505")
53
+#define TYPE_MPS2TZ_AN521_MACHINE MACHINE_TYPE_NAME("mps2-an521")
54
55
#define MPS2TZ_MACHINE(obj) \
56
OBJECT_CHECK(MPS2TZMachineState, obj, TYPE_MPS2TZ_MACHINE)
57
@@ -XXX,XX +XXX,XX @@ static void mps2tz_common_init(MachineState *machine)
58
}
59
60
sysbus_init_child_obj(OBJECT(machine), "iotkit", &mms->iotkit,
61
- sizeof(mms->iotkit), TYPE_IOTKIT);
62
+ sizeof(mms->iotkit), mmc->armsse_type);
63
iotkitdev = DEVICE(&mms->iotkit);
64
object_property_set_link(OBJECT(&mms->iotkit), OBJECT(system_memory),
65
"memory", &error_abort);
66
@@ -XXX,XX +XXX,XX @@ static void mps2tz_class_init(ObjectClass *oc, void *data)
67
IDAUInterfaceClass *iic = IDAU_INTERFACE_CLASS(oc);
68
69
mc->init = mps2tz_common_init;
70
- mc->max_cpus = 1;
71
iic->check = mps2_tz_idau_check;
72
}
30
}
73
31
74
@@ -XXX,XX +XXX,XX @@ static void mps2tz_an505_class_init(ObjectClass *oc, void *data)
32
+static void at24c_eeprom_init(NPCM7xxState *soc, int bus, uint8_t addr,
75
MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc);
33
+ uint32_t rsize)
76
34
+{
77
mc->desc = "ARM MPS2 with AN505 FPGA image for Cortex-M33";
35
+ I2CBus *i2c_bus = npcm7xx_i2c_get_bus(soc, bus);
78
+ mc->default_cpus = 1;
36
+ I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
79
+ mc->min_cpus = mc->default_cpus;
37
+ DeviceState *dev = DEVICE(i2c_dev);
80
+ mc->max_cpus = mc->default_cpus;
38
+
81
mmc->fpga_type = FPGA_AN505;
39
+ qdev_prop_set_uint32(dev, "rom-size", rsize);
82
mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
40
+ i2c_slave_realize_and_unref(i2c_dev, i2c_bus, &error_abort);
83
mmc->scc_id = 0x41045050;
84
+ mmc->armsse_type = TYPE_IOTKIT;
85
+}
41
+}
86
+
42
+
87
+static void mps2tz_an521_class_init(ObjectClass *oc, void *data)
43
static void npcm750_evb_i2c_init(NPCM7xxState *soc)
44
{
45
/* lm75 temperature sensor on SVB, tmp105 is compatible */
46
@@ -XXX,XX +XXX,XX @@ static void npcm750_evb_i2c_init(NPCM7xxState *soc)
47
i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 6), "tmp105", 0x48);
48
}
49
50
+static void quanta_gsj_i2c_init(NPCM7xxState *soc)
88
+{
51
+{
89
+ MachineClass *mc = MACHINE_CLASS(oc);
52
+ /* GSJ machine have 4 max31725 temperature sensors, tmp105 is compatible. */
90
+ MPS2TZMachineClass *mmc = MPS2TZ_MACHINE_CLASS(oc);
53
+ i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), "tmp105", 0x5c);
54
+ i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 2), "tmp105", 0x5c);
55
+ i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 3), "tmp105", 0x5c);
56
+ i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 4), "tmp105", 0x5c);
91
+
57
+
92
+ mc->desc = "ARM MPS2 with AN521 FPGA image for dual Cortex-M33";
58
+ at24c_eeprom_init(soc, 9, 0x55, 8192);
93
+ mc->default_cpus = 2;
59
+ at24c_eeprom_init(soc, 10, 0x55, 8192);
94
+ mc->min_cpus = mc->default_cpus;
60
+
95
+ mc->max_cpus = mc->default_cpus;
61
+ /* TODO: Add additional i2c devices. */
96
+ mmc->fpga_type = FPGA_AN521;
62
+}
97
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m33");
63
+
98
+ mmc->scc_id = 0x41045210;
64
static void npcm750_evb_init(MachineState *machine)
99
+ mmc->armsse_type = TYPE_SSE200;
65
{
66
NPCM7xxState *soc;
67
@@ -XXX,XX +XXX,XX @@ static void quanta_gsj_init(MachineState *machine)
68
npcm7xx_load_bootrom(machine, soc);
69
npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e",
70
drive_get(IF_MTD, 0, 0));
71
+ quanta_gsj_i2c_init(soc);
72
npcm7xx_load_kernel(machine, soc);
100
}
73
}
101
74
102
static const TypeInfo mps2tz_info = {
75
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
103
@@ -XXX,XX +XXX,XX @@ static const TypeInfo mps2tz_an505_info = {
76
index XXXXXXX..XXXXXXX 100644
104
.class_init = mps2tz_an505_class_init,
77
--- a/hw/arm/Kconfig
105
};
78
+++ b/hw/arm/Kconfig
106
79
@@ -XXX,XX +XXX,XX @@ config NPCM7XX
107
+static const TypeInfo mps2tz_an521_info = {
80
bool
108
+ .name = TYPE_MPS2TZ_AN521_MACHINE,
81
select A9MPCORE
109
+ .parent = TYPE_MPS2TZ_MACHINE,
82
select ARM_GIC
110
+ .class_init = mps2tz_an521_class_init,
83
+ select AT24C # EEPROM
111
+};
84
select PL310 # cache controller
112
+
85
select SERIAL
113
static void mps2tz_machine_init(void)
86
select SSI
114
{
115
type_register_static(&mps2tz_info);
116
type_register_static(&mps2tz_an505_info);
117
+ type_register_static(&mps2tz_an521_info);
118
}
119
120
type_init(mps2tz_machine_init);
121
--
87
--
122
2.20.1
88
2.20.1
123
89
124
90
diff view generated by jsdifflib
1
Add unimplemented-device stubs for the various Power Policy Unit
1
From: Hao Wu <wuhaotsh@google.com>
2
devices that the SSE-200 has.
2
3
3
This patch adds a QTest for NPCM7XX SMBus's single byte mode. It sends a
4
byte to a device in the evaluation board, and verify the retrieved value
5
is equivalent to the sent value.
6
7
Reviewed-by: Doug Evans<dje@google.com>
8
Reviewed-by: Tyrong Ting<kfting@nuvoton.com>
9
Signed-off-by: Hao Wu <wuhaotsh@google.com>
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Message-id: 20210210220426.3577804-5-wuhaotsh@google.com
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20190121185118.18550-17-peter.maydell@linaro.org
7
---
13
---
8
include/hw/arm/armsse.h | 11 ++++++++
14
tests/qtest/npcm7xx_smbus-test.c | 352 +++++++++++++++++++++++++++++++
9
hw/arm/armsse.c | 58 +++++++++++++++++++++++++++++++++++++++++
15
tests/qtest/meson.build | 1 +
10
2 files changed, 69 insertions(+)
16
2 files changed, 353 insertions(+)
11
17
create mode 100644 tests/qtest/npcm7xx_smbus-test.c
12
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
18
13
index XXXXXXX..XXXXXXX 100644
19
diff --git a/tests/qtest/npcm7xx_smbus-test.c b/tests/qtest/npcm7xx_smbus-test.c
14
--- a/include/hw/arm/armsse.h
20
new file mode 100644
15
+++ b/include/hw/arm/armsse.h
21
index XXXXXXX..XXXXXXX
22
--- /dev/null
23
+++ b/tests/qtest/npcm7xx_smbus-test.c
16
@@ -XXX,XX +XXX,XX @@
24
@@ -XXX,XX +XXX,XX @@
17
25
+/*
18
#define SSE_MAX_CPUS 2
26
+ * QTests for Nuvoton NPCM7xx SMBus Modules.
19
27
+ *
20
+/* These define what each PPU in the ppu[] index is for */
28
+ * Copyright 2020 Google LLC
21
+#define CPU0CORE_PPU 0
29
+ *
22
+#define CPU1CORE_PPU 1
30
+ * This program is free software; you can redistribute it and/or modify it
23
+#define DBG_PPU 2
31
+ * under the terms of the GNU General Public License as published by the
24
+#define RAM0_PPU 3
32
+ * Free Software Foundation; either version 2 of the License, or
25
+#define RAM1_PPU 4
33
+ * (at your option) any later version.
26
+#define RAM2_PPU 5
34
+ *
27
+#define RAM3_PPU 6
35
+ * This program is distributed in the hope that it will be useful, but WITHOUT
28
+#define NUM_PPUS 7
36
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
29
+
37
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
30
typedef struct ARMSSE {
38
+ * for more details.
31
/*< private >*/
39
+ */
32
SysBusDevice parent_obj;
40
+
33
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
41
+#include "qemu/osdep.h"
34
IoTKitSysCtl sysinfo;
42
+#include "qemu/bitops.h"
35
43
+#include "libqos/i2c.h"
36
UnimplementedDeviceState mhu[2];
44
+#include "libqos/libqtest.h"
37
+ UnimplementedDeviceState ppu[NUM_PPUS];
45
+#include "hw/misc/tmp105_regs.h"
38
46
+
39
/*
47
+#define NR_SMBUS_DEVICES 16
40
* 'container' holds all devices seen by all CPUs.
48
+#define SMBUS_ADDR(x) (0xf0080000 + 0x1000 * (x))
41
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
49
+#define SMBUS_IRQ(x) (64 + (x))
42
index XXXXXXX..XXXXXXX 100644
50
+
43
--- a/hw/arm/armsse.c
51
+#define EVB_DEVICE_ADDR 0x48
44
+++ b/hw/arm/armsse.c
52
+#define INVALID_DEVICE_ADDR 0x01
45
@@ -XXX,XX +XXX,XX @@ struct ARMSSEInfo {
53
+
46
uint32_t sys_version;
54
+const int evb_bus_list[] = {0, 1, 2, 6};
47
SysConfigFormat sys_config_format;
55
+
48
bool has_mhus;
56
+/* Offsets */
49
+ bool has_ppus;
57
+enum CommonRegister {
50
};
58
+ OFFSET_SDA = 0x0,
51
59
+ OFFSET_ST = 0x2,
52
static const ARMSSEInfo armsse_variants[] = {
60
+ OFFSET_CST = 0x4,
53
@@ -XXX,XX +XXX,XX @@ static const ARMSSEInfo armsse_variants[] = {
61
+ OFFSET_CTL1 = 0x6,
54
.sys_version = 0x41743,
62
+ OFFSET_ADDR1 = 0x8,
55
.sys_config_format = IoTKitFormat,
63
+ OFFSET_CTL2 = 0xa,
56
.has_mhus = false,
64
+ OFFSET_ADDR2 = 0xc,
57
+ .has_ppus = false,
65
+ OFFSET_CTL3 = 0xe,
58
},
66
+ OFFSET_CST2 = 0x18,
59
};
67
+ OFFSET_CST3 = 0x19,
60
68
+};
61
@@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj)
69
+
62
sysbus_init_child_obj(obj, "mhu1", &s->mhu[1], sizeof(s->mhu[1]),
70
+enum NPCM7xxSMBusBank0Register {
63
TYPE_UNIMPLEMENTED_DEVICE);
71
+ OFFSET_ADDR3 = 0x10,
64
}
72
+ OFFSET_ADDR7 = 0x11,
65
+ if (info->has_ppus) {
73
+ OFFSET_ADDR4 = 0x12,
66
+ for (i = 0; i < info->num_cpus; i++) {
74
+ OFFSET_ADDR8 = 0x13,
67
+ char *name = g_strdup_printf("CPU%dCORE_PPU", i);
75
+ OFFSET_ADDR5 = 0x14,
68
+ int ppuidx = CPU0CORE_PPU + i;
76
+ OFFSET_ADDR9 = 0x15,
69
+
77
+ OFFSET_ADDR6 = 0x16,
70
+ sysbus_init_child_obj(obj, name, &s->ppu[ppuidx],
78
+ OFFSET_ADDR10 = 0x17,
71
+ sizeof(s->ppu[ppuidx]),
79
+ OFFSET_CTL4 = 0x1a,
72
+ TYPE_UNIMPLEMENTED_DEVICE);
80
+ OFFSET_CTL5 = 0x1b,
73
+ g_free(name);
81
+ OFFSET_SCLLT = 0x1c,
82
+ OFFSET_FIF_CTL = 0x1d,
83
+ OFFSET_SCLHT = 0x1e,
84
+};
85
+
86
+enum NPCM7xxSMBusBank1Register {
87
+ OFFSET_FIF_CTS = 0x10,
88
+ OFFSET_FAIR_PER = 0x11,
89
+ OFFSET_TXF_CTL = 0x12,
90
+ OFFSET_T_OUT = 0x14,
91
+ OFFSET_TXF_STS = 0x1a,
92
+ OFFSET_RXF_STS = 0x1c,
93
+ OFFSET_RXF_CTL = 0x1e,
94
+};
95
+
96
+/* ST fields */
97
+#define ST_STP BIT(7)
98
+#define ST_SDAST BIT(6)
99
+#define ST_BER BIT(5)
100
+#define ST_NEGACK BIT(4)
101
+#define ST_STASTR BIT(3)
102
+#define ST_NMATCH BIT(2)
103
+#define ST_MODE BIT(1)
104
+#define ST_XMIT BIT(0)
105
+
106
+/* CST fields */
107
+#define CST_ARPMATCH BIT(7)
108
+#define CST_MATCHAF BIT(6)
109
+#define CST_TGSCL BIT(5)
110
+#define CST_TSDA BIT(4)
111
+#define CST_GCMATCH BIT(3)
112
+#define CST_MATCH BIT(2)
113
+#define CST_BB BIT(1)
114
+#define CST_BUSY BIT(0)
115
+
116
+/* CST2 fields */
117
+#define CST2_INSTTS BIT(7)
118
+#define CST2_MATCH7F BIT(6)
119
+#define CST2_MATCH6F BIT(5)
120
+#define CST2_MATCH5F BIT(4)
121
+#define CST2_MATCH4F BIT(3)
122
+#define CST2_MATCH3F BIT(2)
123
+#define CST2_MATCH2F BIT(1)
124
+#define CST2_MATCH1F BIT(0)
125
+
126
+/* CST3 fields */
127
+#define CST3_EO_BUSY BIT(7)
128
+#define CST3_MATCH10F BIT(2)
129
+#define CST3_MATCH9F BIT(1)
130
+#define CST3_MATCH8F BIT(0)
131
+
132
+/* CTL1 fields */
133
+#define CTL1_STASTRE BIT(7)
134
+#define CTL1_NMINTE BIT(6)
135
+#define CTL1_GCMEN BIT(5)
136
+#define CTL1_ACK BIT(4)
137
+#define CTL1_EOBINTE BIT(3)
138
+#define CTL1_INTEN BIT(2)
139
+#define CTL1_STOP BIT(1)
140
+#define CTL1_START BIT(0)
141
+
142
+/* CTL2 fields */
143
+#define CTL2_SCLFRQ(rv) extract8((rv), 1, 6)
144
+#define CTL2_ENABLE BIT(0)
145
+
146
+/* CTL3 fields */
147
+#define CTL3_SCL_LVL BIT(7)
148
+#define CTL3_SDA_LVL BIT(6)
149
+#define CTL3_BNK_SEL BIT(5)
150
+#define CTL3_400K_MODE BIT(4)
151
+#define CTL3_IDL_START BIT(3)
152
+#define CTL3_ARPMEN BIT(2)
153
+#define CTL3_SCLFRQ(rv) extract8((rv), 0, 2)
154
+
155
+/* ADDR fields */
156
+#define ADDR_EN BIT(7)
157
+#define ADDR_A(rv) extract8((rv), 0, 6)
158
+
159
+
160
+static void check_running(QTestState *qts, uint64_t base_addr)
161
+{
162
+ g_assert_true(qtest_readb(qts, base_addr + OFFSET_CST) & CST_BUSY);
163
+ g_assert_true(qtest_readb(qts, base_addr + OFFSET_CST) & CST_BB);
164
+}
165
+
166
+static void check_stopped(QTestState *qts, uint64_t base_addr)
167
+{
168
+ uint8_t cst3;
169
+
170
+ g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, 0);
171
+ g_assert_false(qtest_readb(qts, base_addr + OFFSET_CST) & CST_BUSY);
172
+ g_assert_false(qtest_readb(qts, base_addr + OFFSET_CST) & CST_BB);
173
+
174
+ cst3 = qtest_readb(qts, base_addr + OFFSET_CST3);
175
+ g_assert_true(cst3 & CST3_EO_BUSY);
176
+ qtest_writeb(qts, base_addr + OFFSET_CST3, cst3);
177
+ cst3 = qtest_readb(qts, base_addr + OFFSET_CST3);
178
+ g_assert_false(cst3 & CST3_EO_BUSY);
179
+}
180
+
181
+static void enable_bus(QTestState *qts, uint64_t base_addr)
182
+{
183
+ uint8_t ctl2 = qtest_readb(qts, base_addr + OFFSET_CTL2);
184
+
185
+ ctl2 |= CTL2_ENABLE;
186
+ qtest_writeb(qts, base_addr + OFFSET_CTL2, ctl2);
187
+ g_assert_true(qtest_readb(qts, base_addr + OFFSET_CTL2) & CTL2_ENABLE);
188
+}
189
+
190
+static void disable_bus(QTestState *qts, uint64_t base_addr)
191
+{
192
+ uint8_t ctl2 = qtest_readb(qts, base_addr + OFFSET_CTL2);
193
+
194
+ ctl2 &= ~CTL2_ENABLE;
195
+ qtest_writeb(qts, base_addr + OFFSET_CTL2, ctl2);
196
+ g_assert_false(qtest_readb(qts, base_addr + OFFSET_CTL2) & CTL2_ENABLE);
197
+}
198
+
199
+static void start_transfer(QTestState *qts, uint64_t base_addr)
200
+{
201
+ uint8_t ctl1;
202
+
203
+ ctl1 = CTL1_START | CTL1_INTEN | CTL1_STASTRE;
204
+ qtest_writeb(qts, base_addr + OFFSET_CTL1, ctl1);
205
+ g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_CTL1), ==,
206
+ CTL1_INTEN | CTL1_STASTRE | CTL1_INTEN);
207
+ g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==,
208
+ ST_MODE | ST_XMIT | ST_SDAST);
209
+ check_running(qts, base_addr);
210
+}
211
+
212
+static void stop_transfer(QTestState *qts, uint64_t base_addr)
213
+{
214
+ uint8_t ctl1 = qtest_readb(qts, base_addr + OFFSET_CTL1);
215
+
216
+ ctl1 &= ~(CTL1_START | CTL1_ACK);
217
+ ctl1 |= CTL1_STOP | CTL1_INTEN | CTL1_EOBINTE;
218
+ qtest_writeb(qts, base_addr + OFFSET_CTL1, ctl1);
219
+ ctl1 = qtest_readb(qts, base_addr + OFFSET_CTL1);
220
+ g_assert_false(ctl1 & CTL1_STOP);
221
+}
222
+
223
+static void send_byte(QTestState *qts, uint64_t base_addr, uint8_t byte)
224
+{
225
+ g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==,
226
+ ST_MODE | ST_XMIT | ST_SDAST);
227
+ qtest_writeb(qts, base_addr + OFFSET_SDA, byte);
228
+}
229
+
230
+static uint8_t recv_byte(QTestState *qts, uint64_t base_addr)
231
+{
232
+ g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==,
233
+ ST_MODE | ST_SDAST);
234
+ return qtest_readb(qts, base_addr + OFFSET_SDA);
235
+}
236
+
237
+static void send_address(QTestState *qts, uint64_t base_addr, uint8_t addr,
238
+ bool recv, bool valid)
239
+{
240
+ uint8_t encoded_addr = (addr << 1) | (recv ? 1 : 0);
241
+ uint8_t st;
242
+
243
+ qtest_writeb(qts, base_addr + OFFSET_SDA, encoded_addr);
244
+ st = qtest_readb(qts, base_addr + OFFSET_ST);
245
+
246
+ if (valid) {
247
+ if (recv) {
248
+ g_assert_cmphex(st, ==, ST_MODE | ST_SDAST | ST_STASTR);
249
+ } else {
250
+ g_assert_cmphex(st, ==, ST_MODE | ST_XMIT | ST_SDAST | ST_STASTR);
74
+ }
251
+ }
75
+ sysbus_init_child_obj(obj, "DBG_PPU", &s->ppu[DBG_PPU],
252
+
76
+ sizeof(s->ppu[DBG_PPU]),
253
+ qtest_writeb(qts, base_addr + OFFSET_ST, ST_STASTR);
77
+ TYPE_UNIMPLEMENTED_DEVICE);
254
+ st = qtest_readb(qts, base_addr + OFFSET_ST);
78
+ for (i = 0; i < info->sram_banks; i++) {
255
+ if (recv) {
79
+ char *name = g_strdup_printf("RAM%d_PPU", i);
256
+ g_assert_cmphex(st, ==, ST_MODE | ST_SDAST);
80
+ int ppuidx = RAM0_PPU + i;
257
+ } else {
81
+
258
+ g_assert_cmphex(st, ==, ST_MODE | ST_XMIT | ST_SDAST);
82
+ sysbus_init_child_obj(obj, name, &s->ppu[ppuidx],
259
+ }
83
+ sizeof(s->ppu[ppuidx]),
260
+ } else {
84
+ TYPE_UNIMPLEMENTED_DEVICE);
261
+ if (recv) {
85
+ g_free(name);
262
+ g_assert_cmphex(st, ==, ST_MODE | ST_NEGACK);
263
+ } else {
264
+ g_assert_cmphex(st, ==, ST_MODE | ST_XMIT | ST_NEGACK);
86
+ }
265
+ }
87
+ }
266
+ }
88
object_initialize_child(obj, "nmi-orgate", &s->nmi_orgate,
267
+}
89
sizeof(s->nmi_orgate), TYPE_OR_IRQ,
268
+
90
&error_abort, NULL);
269
+static void send_nack(QTestState *qts, uint64_t base_addr)
91
@@ -XXX,XX +XXX,XX @@ static qemu_irq armsse_get_common_irq_in(ARMSSE *s, int irqno)
270
+{
92
}
271
+ uint8_t ctl1 = qtest_readb(qts, base_addr + OFFSET_CTL1);
93
}
272
+
94
273
+ ctl1 &= ~(CTL1_START | CTL1_STOP);
95
+static void map_ppu(ARMSSE *s, int ppuidx, const char *name, hwaddr addr)
274
+ ctl1 |= CTL1_ACK | CTL1_INTEN;
96
+{
275
+ qtest_writeb(qts, base_addr + OFFSET_CTL1, ctl1);
97
+ /* Map a PPU unimplemented device stub */
276
+}
98
+ DeviceState *dev = DEVICE(&s->ppu[ppuidx]);
277
+
99
+
278
+/* Check the SMBus's status is set correctly when disabled. */
100
+ qdev_prop_set_string(dev, "name", name);
279
+static void test_disable_bus(gconstpointer data)
101
+ qdev_prop_set_uint64(dev, "size", 0x1000);
280
+{
102
+ qdev_init_nofail(dev);
281
+ intptr_t index = (intptr_t)data;
103
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->ppu[ppuidx]), 0, addr);
282
+ uint64_t base_addr = SMBUS_ADDR(index);
104
+}
283
+ QTestState *qts = qtest_init("-machine npcm750-evb");
105
+
284
+
106
static void armsse_realize(DeviceState *dev, Error **errp)
285
+ disable_bus(qts, base_addr);
107
{
286
+ g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_CTL1), ==, 0);
108
ARMSSE *s = ARMSSE(dev);
287
+ g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==, 0);
109
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
288
+ g_assert_false(qtest_readb(qts, base_addr + OFFSET_CST3) & CST3_EO_BUSY);
110
}
289
+ g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_CST), ==, 0);
111
sysbus_mmio_map(SYS_BUS_DEVICE(&s->sysctl), 0, 0x50021000);
290
+ qtest_quit(qts);
112
291
+}
113
+ if (info->has_ppus) {
292
+
114
+ /* CPUnCORE_PPU for each CPU */
293
+/* Check the SMBus returns a NACK for an invalid address. */
115
+ for (i = 0; i < info->num_cpus; i++) {
294
+static void test_invalid_addr(gconstpointer data)
116
+ char *name = g_strdup_printf("CPU%dCORE_PPU", i);
295
+{
117
+
296
+ intptr_t index = (intptr_t)data;
118
+ map_ppu(s, CPU0CORE_PPU + i, name, 0x50023000 + i * 0x2000);
297
+ uint64_t base_addr = SMBUS_ADDR(index);
119
+ /*
298
+ int irq = SMBUS_IRQ(index);
120
+ * We don't support CPU debug so don't create the
299
+ QTestState *qts = qtest_init("-machine npcm750-evb");
121
+ * CPU0DEBUG_PPU at 0x50024000 and 0x50026000.
300
+
122
+ */
301
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
123
+ g_free(name);
302
+ enable_bus(qts, base_addr);
124
+ }
303
+ g_assert_false(qtest_get_irq(qts, irq));
125
+ map_ppu(s, DBG_PPU, "DBG_PPU", 0x50029000);
304
+ start_transfer(qts, base_addr);
126
+
305
+ send_address(qts, base_addr, INVALID_DEVICE_ADDR, false, false);
127
+ for (i = 0; i < info->sram_banks; i++) {
306
+ g_assert_true(qtest_get_irq(qts, irq));
128
+ char *name = g_strdup_printf("RAM%d_PPU", i);
307
+ stop_transfer(qts, base_addr);
129
+
308
+ check_running(qts, base_addr);
130
+ map_ppu(s, RAM0_PPU + i, name, 0x5002a000 + i * 0x1000);
309
+ qtest_writeb(qts, base_addr + OFFSET_ST, ST_NEGACK);
131
+ g_free(name);
310
+ g_assert_false(qtest_readb(qts, base_addr + OFFSET_ST) & ST_NEGACK);
132
+ }
311
+ check_stopped(qts, base_addr);
312
+ qtest_quit(qts);
313
+}
314
+
315
+/* Check the SMBus can send and receive bytes to a device in single mode. */
316
+static void test_single_mode(gconstpointer data)
317
+{
318
+ intptr_t index = (intptr_t)data;
319
+ uint64_t base_addr = SMBUS_ADDR(index);
320
+ int irq = SMBUS_IRQ(index);
321
+ uint8_t value = 0x60;
322
+ QTestState *qts = qtest_init("-machine npcm750-evb");
323
+
324
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
325
+ enable_bus(qts, base_addr);
326
+
327
+ /* Sending */
328
+ g_assert_false(qtest_get_irq(qts, irq));
329
+ start_transfer(qts, base_addr);
330
+ g_assert_true(qtest_get_irq(qts, irq));
331
+ send_address(qts, base_addr, EVB_DEVICE_ADDR, false, true);
332
+ send_byte(qts, base_addr, TMP105_REG_CONFIG);
333
+ send_byte(qts, base_addr, value);
334
+ stop_transfer(qts, base_addr);
335
+ check_stopped(qts, base_addr);
336
+
337
+ /* Receiving */
338
+ start_transfer(qts, base_addr);
339
+ send_address(qts, base_addr, EVB_DEVICE_ADDR, false, true);
340
+ send_byte(qts, base_addr, TMP105_REG_CONFIG);
341
+ start_transfer(qts, base_addr);
342
+ send_address(qts, base_addr, EVB_DEVICE_ADDR, true, true);
343
+ send_nack(qts, base_addr);
344
+ stop_transfer(qts, base_addr);
345
+ check_running(qts, base_addr);
346
+ g_assert_cmphex(recv_byte(qts, base_addr), ==, value);
347
+ check_stopped(qts, base_addr);
348
+ qtest_quit(qts);
349
+}
350
+
351
+static void smbus_add_test(const char *name, int index, GTestDataFunc fn)
352
+{
353
+ g_autofree char *full_name = g_strdup_printf(
354
+ "npcm7xx_smbus[%d]/%s", index, name);
355
+ qtest_add_data_func(full_name, (void *)(intptr_t)index, fn);
356
+}
357
+#define add_test(name, td) smbus_add_test(#name, td, test_##name)
358
+
359
+int main(int argc, char **argv)
360
+{
361
+ int i;
362
+
363
+ g_test_init(&argc, &argv, NULL);
364
+ g_test_set_nonfatal_assertions();
365
+
366
+ for (i = 0; i < NR_SMBUS_DEVICES; ++i) {
367
+ add_test(disable_bus, i);
368
+ add_test(invalid_addr, i);
133
+ }
369
+ }
134
+
370
+
135
/* This OR gate wires together outputs from the secure watchdogs to NMI */
371
+ for (i = 0; i < ARRAY_SIZE(evb_bus_list); ++i) {
136
object_property_set_int(OBJECT(&s->nmi_orgate), 2, "num-lines", &err);
372
+ add_test(single_mode, evb_bus_list[i]);
137
if (err) {
373
+ }
374
+
375
+ return g_test_run();
376
+}
377
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
378
index XXXXXXX..XXXXXXX 100644
379
--- a/tests/qtest/meson.build
380
+++ b/tests/qtest/meson.build
381
@@ -XXX,XX +XXX,XX @@ qtests_npcm7xx = \
382
'npcm7xx_gpio-test',
383
'npcm7xx_pwm-test',
384
'npcm7xx_rng-test',
385
+ 'npcm7xx_smbus-test',
386
'npcm7xx_timer-test',
387
'npcm7xx_watchdog_timer-test']
388
qtests_arm = \
138
--
389
--
139
2.20.1
390
2.20.1
140
391
141
392
diff view generated by jsdifflib
1
From: Steffen Görtz <contrib@steffen-goertz.de>
1
From: Hao Wu <wuhaotsh@google.com>
2
2
3
Instantiates UICR, FICR, FLASH and NVMC in nRF51 SOC.
3
This patch implements the FIFO mode of the SMBus module. In FIFO, the
4
user transmits or receives at most 16 bytes at a time. The FIFO mode
5
allows the module to transmit large amount of data faster than single
6
byte mode.
4
7
5
Signed-off-by: Steffen Görtz <contrib@steffen-goertz.de>
8
Since we only added the device in a patch that is only a few commits
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
away in the same patch set. We do not increase the VMstate version
7
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
10
number in this special case.
8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
11
9
Message-id: 20190201023357.22596-3-stefanha@redhat.com
12
Reviewed-by: Doug Evans<dje@google.com>
13
Reviewed-by: Tyrong Ting<kfting@nuvoton.com>
14
Signed-off-by: Hao Wu <wuhaotsh@google.com>
15
Reviewed-by: Corey Minyard <cminyard@mvista.com>
16
Message-id: 20210210220426.3577804-6-wuhaotsh@google.com
17
Acked-by: Corey Minyard <cminyard@mvista.com>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
19
---
12
include/hw/arm/nrf51_soc.h | 2 ++
20
include/hw/i2c/npcm7xx_smbus.h | 25 +++
13
hw/arm/nrf51_soc.c | 41 +++++++++++++++++++++++++++-----------
21
hw/i2c/npcm7xx_smbus.c | 342 +++++++++++++++++++++++++++++--
14
2 files changed, 31 insertions(+), 12 deletions(-)
22
tests/qtest/npcm7xx_smbus-test.c | 149 +++++++++++++-
23
hw/i2c/trace-events | 1 +
24
4 files changed, 501 insertions(+), 16 deletions(-)
15
25
16
diff --git a/include/hw/arm/nrf51_soc.h b/include/hw/arm/nrf51_soc.h
26
diff --git a/include/hw/i2c/npcm7xx_smbus.h b/include/hw/i2c/npcm7xx_smbus.h
17
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
18
--- a/include/hw/arm/nrf51_soc.h
28
--- a/include/hw/i2c/npcm7xx_smbus.h
19
+++ b/include/hw/arm/nrf51_soc.h
29
+++ b/include/hw/i2c/npcm7xx_smbus.h
20
@@ -XXX,XX +XXX,XX @@
30
@@ -XXX,XX +XXX,XX @@
21
#include "hw/char/nrf51_uart.h"
31
*/
22
#include "hw/misc/nrf51_rng.h"
32
#define NPCM7XX_SMBUS_NR_ADDRS 10
23
#include "hw/gpio/nrf51_gpio.h"
33
24
+#include "hw/nvram/nrf51_nvm.h"
34
+/* Size of the FIFO buffer. */
25
#include "hw/timer/nrf51_timer.h"
35
+#define NPCM7XX_SMBUS_FIFO_SIZE 16
26
36
+
27
#define TYPE_NRF51_SOC "nrf51-soc"
37
typedef enum NPCM7xxSMBusStatus {
28
@@ -XXX,XX +XXX,XX @@ typedef struct NRF51State {
38
NPCM7XX_SMBUS_STATUS_IDLE,
29
39
NPCM7XX_SMBUS_STATUS_SENDING,
30
NRF51UARTState uart;
40
@@ -XXX,XX +XXX,XX @@ typedef enum NPCM7xxSMBusStatus {
31
NRF51RNGState rng;
41
* @addr: The SMBus module's own addresses on the I2C bus.
32
+ NRF51NVMState nvm;
42
* @scllt: The SCL low time register.
33
NRF51GPIOState gpio;
43
* @sclht: The SCL high time register.
34
NRF51TimerState timer[NRF51_NUM_TIMERS];
44
+ * @fif_ctl: The FIFO control register.
35
45
+ * @fif_cts: The FIFO control status register.
36
diff --git a/hw/arm/nrf51_soc.c b/hw/arm/nrf51_soc.c
46
+ * @fair_per: The fair preriod register.
47
+ * @txf_ctl: The transmit FIFO control register.
48
+ * @t_out: The SMBus timeout register.
49
+ * @txf_sts: The transmit FIFO status register.
50
+ * @rxf_sts: The receive FIFO status register.
51
+ * @rxf_ctl: The receive FIFO control register.
52
+ * @rx_fifo: The FIFO buffer for receiving in FIFO mode.
53
+ * @rx_cur: The current position of rx_fifo.
54
* @status: The current status of the SMBus.
55
*/
56
typedef struct NPCM7xxSMBusState {
57
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxSMBusState {
58
uint8_t scllt;
59
uint8_t sclht;
60
61
+ uint8_t fif_ctl;
62
+ uint8_t fif_cts;
63
+ uint8_t fair_per;
64
+ uint8_t txf_ctl;
65
+ uint8_t t_out;
66
+ uint8_t txf_sts;
67
+ uint8_t rxf_sts;
68
+ uint8_t rxf_ctl;
69
+
70
+ uint8_t rx_fifo[NPCM7XX_SMBUS_FIFO_SIZE];
71
+ uint8_t rx_cur;
72
+
73
NPCM7xxSMBusStatus status;
74
} NPCM7xxSMBusState;
75
76
diff --git a/hw/i2c/npcm7xx_smbus.c b/hw/i2c/npcm7xx_smbus.c
37
index XXXXXXX..XXXXXXX 100644
77
index XXXXXXX..XXXXXXX 100644
38
--- a/hw/arm/nrf51_soc.c
78
--- a/hw/i2c/npcm7xx_smbus.c
39
+++ b/hw/arm/nrf51_soc.c
79
+++ b/hw/i2c/npcm7xx_smbus.c
40
@@ -XXX,XX +XXX,XX @@
80
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxSMBusBank1Register {
41
* are supported in the future, add a sub-class of NRF51SoC for
81
#define NPCM7XX_ADDR_EN BIT(7)
42
* the specific variants
82
#define NPCM7XX_ADDR_A(rv) extract8((rv), 0, 6)
43
*/
83
44
-#define NRF51822_FLASH_SIZE (256 * NRF51_PAGE_SIZE)
84
+/* FIFO Mode Register Fields */
45
-#define NRF51822_SRAM_SIZE (16 * NRF51_PAGE_SIZE)
85
+/* FIF_CTL fields */
46
+#define NRF51822_FLASH_PAGES 256
86
+#define NPCM7XX_SMBFIF_CTL_FIFO_EN BIT(4)
47
+#define NRF51822_SRAM_PAGES 16
87
+#define NPCM7XX_SMBFIF_CTL_FAIR_RDY_IE BIT(2)
48
+#define NRF51822_FLASH_SIZE (NRF51822_FLASH_PAGES * NRF51_PAGE_SIZE)
88
+#define NPCM7XX_SMBFIF_CTL_FAIR_RDY BIT(1)
49
+#define NRF51822_SRAM_SIZE (NRF51822_SRAM_PAGES * NRF51_PAGE_SIZE)
89
+#define NPCM7XX_SMBFIF_CTL_FAIR_BUSY BIT(0)
50
90
+/* FIF_CTS fields */
51
#define BASE_TO_IRQ(base) ((base >> 12) & 0x1F)
91
+#define NPCM7XX_SMBFIF_CTS_STR BIT(7)
52
92
+#define NPCM7XX_SMBFIF_CTS_CLR_FIFO BIT(6)
53
@@ -XXX,XX +XXX,XX @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)
93
+#define NPCM7XX_SMBFIF_CTS_RFTE_IE BIT(3)
54
94
+#define NPCM7XX_SMBFIF_CTS_RXF_TXE BIT(1)
55
memory_region_add_subregion_overlap(&s->container, 0, s->board_memory, -1);
95
+/* TXF_CTL fields */
56
96
+#define NPCM7XX_SMBTXF_CTL_THR_TXIE BIT(6)
57
- memory_region_init_rom(&s->flash, OBJECT(s), "nrf51.flash", s->flash_size,
97
+#define NPCM7XX_SMBTXF_CTL_TX_THR(rv) extract8((rv), 0, 5)
58
- &err);
98
+/* T_OUT fields */
59
- if (err) {
99
+#define NPCM7XX_SMBT_OUT_ST BIT(7)
60
- error_propagate(errp, err);
100
+#define NPCM7XX_SMBT_OUT_IE BIT(6)
61
- return;
101
+#define NPCM7XX_SMBT_OUT_CLKDIV(rv) extract8((rv), 0, 6)
62
- }
102
+/* TXF_STS fields */
63
- memory_region_add_subregion(&s->container, NRF51_FLASH_BASE, &s->flash);
103
+#define NPCM7XX_SMBTXF_STS_TX_THST BIT(6)
64
-
104
+#define NPCM7XX_SMBTXF_STS_TX_BYTES(rv) extract8((rv), 0, 5)
65
memory_region_init_ram(&s->sram, OBJECT(s), "nrf51.sram", s->sram_size,
105
+/* RXF_STS fields */
66
&err);
106
+#define NPCM7XX_SMBRXF_STS_RX_THST BIT(6)
67
if (err) {
107
+#define NPCM7XX_SMBRXF_STS_RX_BYTES(rv) extract8((rv), 0, 5)
68
@@ -XXX,XX +XXX,XX @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)
108
+/* RXF_CTL fields */
69
qdev_get_gpio_in(DEVICE(&s->cpu),
109
+#define NPCM7XX_SMBRXF_CTL_THR_RXIE BIT(6)
70
BASE_TO_IRQ(NRF51_RNG_BASE)));
110
+#define NPCM7XX_SMBRXF_CTL_LAST BIT(5)
71
111
+#define NPCM7XX_SMBRXF_CTL_RX_THR(rv) extract8((rv), 0, 5)
72
+ /* UICR, FICR, NVMC, FLASH */
112
+
73
+ object_property_set_uint(OBJECT(&s->nvm), s->flash_size, "flash-size",
113
#define KEEP_OLD_BIT(o, n, b) (((n) & (~(b))) | ((o) & (b)))
74
+ &err);
114
#define WRITE_ONE_CLEAR(o, n, b) ((n) & (b) ? (o) & (~(b)) : (o))
75
+ if (err) {
115
76
+ error_propagate(errp, err);
116
#define NPCM7XX_SMBUS_ENABLED(s) ((s)->ctl2 & NPCM7XX_SMBCTL2_ENABLE)
117
+#define NPCM7XX_SMBUS_FIFO_ENABLED(s) ((s)->fif_ctl & \
118
+ NPCM7XX_SMBFIF_CTL_FIFO_EN)
119
120
/* VERSION fields values, read-only. */
121
#define NPCM7XX_SMBUS_VERSION_NUMBER 1
122
-#define NPCM7XX_SMBUS_VERSION_FIFO_SUPPORTED 0
123
+#define NPCM7XX_SMBUS_VERSION_FIFO_SUPPORTED 1
124
125
/* Reset values */
126
#define NPCM7XX_SMB_ST_INIT_VAL 0x00
127
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxSMBusBank1Register {
128
#define NPCM7XX_SMB_ADDR_INIT_VAL 0x00
129
#define NPCM7XX_SMB_SCLLT_INIT_VAL 0x00
130
#define NPCM7XX_SMB_SCLHT_INIT_VAL 0x00
131
+#define NPCM7XX_SMB_FIF_CTL_INIT_VAL 0x00
132
+#define NPCM7XX_SMB_FIF_CTS_INIT_VAL 0x00
133
+#define NPCM7XX_SMB_FAIR_PER_INIT_VAL 0x00
134
+#define NPCM7XX_SMB_TXF_CTL_INIT_VAL 0x00
135
+#define NPCM7XX_SMB_T_OUT_INIT_VAL 0x3f
136
+#define NPCM7XX_SMB_TXF_STS_INIT_VAL 0x00
137
+#define NPCM7XX_SMB_RXF_STS_INIT_VAL 0x00
138
+#define NPCM7XX_SMB_RXF_CTL_INIT_VAL 0x01
139
140
static uint8_t npcm7xx_smbus_get_version(void)
141
{
142
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_update_irq(NPCM7xxSMBusState *s)
143
(s->ctl1 & NPCM7XX_SMBCTL1_STASTRE &&
144
s->st & NPCM7XX_SMBST_SDAST) ||
145
(s->ctl1 & NPCM7XX_SMBCTL1_EOBINTE &&
146
- s->cst3 & NPCM7XX_SMBCST3_EO_BUSY));
147
+ s->cst3 & NPCM7XX_SMBCST3_EO_BUSY) ||
148
+ (s->rxf_ctl & NPCM7XX_SMBRXF_CTL_THR_RXIE &&
149
+ s->rxf_sts & NPCM7XX_SMBRXF_STS_RX_THST) ||
150
+ (s->txf_ctl & NPCM7XX_SMBTXF_CTL_THR_TXIE &&
151
+ s->txf_sts & NPCM7XX_SMBTXF_STS_TX_THST) ||
152
+ (s->fif_cts & NPCM7XX_SMBFIF_CTS_RFTE_IE &&
153
+ s->fif_cts & NPCM7XX_SMBFIF_CTS_RXF_TXE));
154
155
if (level) {
156
s->cst2 |= NPCM7XX_SMBCST2_INTSTS;
157
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_nack(NPCM7xxSMBusState *s)
158
s->status = NPCM7XX_SMBUS_STATUS_NEGACK;
159
}
160
161
+static void npcm7xx_smbus_clear_buffer(NPCM7xxSMBusState *s)
162
+{
163
+ s->fif_cts &= ~NPCM7XX_SMBFIF_CTS_RXF_TXE;
164
+ s->txf_sts = 0;
165
+ s->rxf_sts = 0;
166
+}
167
+
168
static void npcm7xx_smbus_send_byte(NPCM7xxSMBusState *s, uint8_t value)
169
{
170
int rv = i2c_send(s->bus, value);
171
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_send_byte(NPCM7xxSMBusState *s, uint8_t value)
172
npcm7xx_smbus_nack(s);
173
} else {
174
s->st |= NPCM7XX_SMBST_SDAST;
175
+ if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) {
176
+ s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE;
177
+ if (NPCM7XX_SMBTXF_STS_TX_BYTES(s->txf_sts) ==
178
+ NPCM7XX_SMBTXF_CTL_TX_THR(s->txf_ctl)) {
179
+ s->txf_sts = NPCM7XX_SMBTXF_STS_TX_THST;
180
+ } else {
181
+ s->txf_sts = 0;
182
+ }
183
+ }
184
}
185
trace_npcm7xx_smbus_send_byte((DEVICE(s)->canonical_path), value, !rv);
186
npcm7xx_smbus_update_irq(s);
187
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_recv_byte(NPCM7xxSMBusState *s)
188
npcm7xx_smbus_update_irq(s);
189
}
190
191
+static void npcm7xx_smbus_recv_fifo(NPCM7xxSMBusState *s)
192
+{
193
+ uint8_t expected_bytes = NPCM7XX_SMBRXF_CTL_RX_THR(s->rxf_ctl);
194
+ uint8_t received_bytes = NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts);
195
+ uint8_t pos;
196
+
197
+ if (received_bytes == expected_bytes) {
77
+ return;
198
+ return;
78
+ }
199
+ }
79
+
200
+
80
+ object_property_set_bool(OBJECT(&s->nvm), true, "realized", &err);
201
+ while (received_bytes < expected_bytes &&
81
+ if (err) {
202
+ received_bytes < NPCM7XX_SMBUS_FIFO_SIZE) {
82
+ error_propagate(errp, err);
203
+ pos = (s->rx_cur + received_bytes) % NPCM7XX_SMBUS_FIFO_SIZE;
204
+ s->rx_fifo[pos] = i2c_recv(s->bus);
205
+ trace_npcm7xx_smbus_recv_byte((DEVICE(s)->canonical_path),
206
+ s->rx_fifo[pos]);
207
+ ++received_bytes;
208
+ }
209
+
210
+ trace_npcm7xx_smbus_recv_fifo((DEVICE(s)->canonical_path),
211
+ received_bytes, expected_bytes);
212
+ s->rxf_sts = received_bytes;
213
+ if (unlikely(received_bytes < expected_bytes)) {
214
+ qemu_log_mask(LOG_GUEST_ERROR,
215
+ "%s: invalid rx_thr value: 0x%02x\n",
216
+ DEVICE(s)->canonical_path, expected_bytes);
83
+ return;
217
+ return;
84
+ }
218
+ }
85
+
219
+
86
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->nvm), 0);
220
+ s->rxf_sts |= NPCM7XX_SMBRXF_STS_RX_THST;
87
+ memory_region_add_subregion_overlap(&s->container, NRF51_NVMC_BASE, mr, 0);
221
+ if (s->rxf_ctl & NPCM7XX_SMBRXF_CTL_LAST) {
88
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->nvm), 1);
222
+ trace_npcm7xx_smbus_nack(DEVICE(s)->canonical_path);
89
+ memory_region_add_subregion_overlap(&s->container, NRF51_FICR_BASE, mr, 0);
223
+ i2c_nack(s->bus);
90
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->nvm), 2);
224
+ s->rxf_ctl &= ~NPCM7XX_SMBRXF_CTL_LAST;
91
+ memory_region_add_subregion_overlap(&s->container, NRF51_UICR_BASE, mr, 0);
225
+ }
92
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->nvm), 3);
226
+ if (received_bytes == NPCM7XX_SMBUS_FIFO_SIZE) {
93
+ memory_region_add_subregion_overlap(&s->container, NRF51_FLASH_BASE, mr, 0);
227
+ s->st |= NPCM7XX_SMBST_SDAST;
94
+
228
+ s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE;
95
/* GPIO */
229
+ } else if (!(s->rxf_ctl & NPCM7XX_SMBRXF_CTL_THR_RXIE)) {
96
object_property_set_bool(OBJECT(&s->gpio), true, "realized", &err);
230
+ s->st |= NPCM7XX_SMBST_SDAST;
97
if (err) {
231
+ } else {
98
@@ -XXX,XX +XXX,XX @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)
232
+ s->st &= ~NPCM7XX_SMBST_SDAST;
99
233
+ }
100
create_unimplemented_device("nrf51_soc.io", NRF51_IOMEM_BASE,
234
+ npcm7xx_smbus_update_irq(s);
101
NRF51_IOMEM_SIZE);
235
+}
102
- create_unimplemented_device("nrf51_soc.ficr", NRF51_FICR_BASE,
236
+
103
- NRF51_FICR_SIZE);
237
+static void npcm7xx_smbus_read_byte_fifo(NPCM7xxSMBusState *s)
104
create_unimplemented_device("nrf51_soc.private",
238
+{
105
NRF51_PRIVATE_BASE, NRF51_PRIVATE_SIZE);
239
+ uint8_t received_bytes = NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts);
106
}
240
+
107
@@ -XXX,XX +XXX,XX @@ static void nrf51_soc_init(Object *obj)
241
+ if (received_bytes == 0) {
108
sysbus_init_child_obj(obj, "rng", &s->rng, sizeof(s->rng),
242
+ npcm7xx_smbus_recv_fifo(s);
109
TYPE_NRF51_RNG);
243
+ return;
110
244
+ }
111
+ sysbus_init_child_obj(obj, "nvm", &s->nvm, sizeof(s->nvm), TYPE_NRF51_NVM);
245
+
112
+
246
+ s->sda = s->rx_fifo[s->rx_cur];
113
sysbus_init_child_obj(obj, "gpio", &s->gpio, sizeof(s->gpio),
247
+ s->rx_cur = (s->rx_cur + 1u) % NPCM7XX_SMBUS_FIFO_SIZE;
114
TYPE_NRF51_GPIO);
248
+ --s->rxf_sts;
115
249
+ npcm7xx_smbus_update_irq(s);
250
+}
251
+
252
static void npcm7xx_smbus_start(NPCM7xxSMBusState *s)
253
{
254
/*
255
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_start(NPCM7xxSMBusState *s)
256
if (available) {
257
s->st |= NPCM7XX_SMBST_MODE | NPCM7XX_SMBST_XMIT | NPCM7XX_SMBST_SDAST;
258
s->cst |= NPCM7XX_SMBCST_BUSY;
259
+ if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) {
260
+ s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE;
261
+ }
262
} else {
263
s->st &= ~NPCM7XX_SMBST_MODE;
264
s->cst &= ~NPCM7XX_SMBCST_BUSY;
265
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_send_address(NPCM7xxSMBusState *s, uint8_t value)
266
s->st |= NPCM7XX_SMBST_SDAST;
267
}
268
} else if (recv) {
269
- npcm7xx_smbus_recv_byte(s);
270
+ s->st |= NPCM7XX_SMBST_SDAST;
271
+ if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) {
272
+ npcm7xx_smbus_recv_fifo(s);
273
+ } else {
274
+ npcm7xx_smbus_recv_byte(s);
275
+ }
276
+ } else if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) {
277
+ s->st |= NPCM7XX_SMBST_SDAST;
278
+ s->fif_cts |= NPCM7XX_SMBFIF_CTS_RXF_TXE;
279
}
280
npcm7xx_smbus_update_irq(s);
281
}
282
@@ -XXX,XX +XXX,XX @@ static uint8_t npcm7xx_smbus_read_sda(NPCM7xxSMBusState *s)
283
284
switch (s->status) {
285
case NPCM7XX_SMBUS_STATUS_STOPPING_LAST_RECEIVE:
286
- npcm7xx_smbus_execute_stop(s);
287
+ if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) {
288
+ if (NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts) <= 1) {
289
+ npcm7xx_smbus_execute_stop(s);
290
+ }
291
+ if (NPCM7XX_SMBRXF_STS_RX_BYTES(s->rxf_sts) == 0) {
292
+ qemu_log_mask(LOG_GUEST_ERROR,
293
+ "%s: read to SDA with an empty rx-fifo buffer, "
294
+ "result undefined: %u\n",
295
+ DEVICE(s)->canonical_path, s->sda);
296
+ break;
297
+ }
298
+ npcm7xx_smbus_read_byte_fifo(s);
299
+ value = s->sda;
300
+ } else {
301
+ npcm7xx_smbus_execute_stop(s);
302
+ }
303
break;
304
305
case NPCM7XX_SMBUS_STATUS_RECEIVING:
306
- npcm7xx_smbus_recv_byte(s);
307
+ if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) {
308
+ npcm7xx_smbus_read_byte_fifo(s);
309
+ value = s->sda;
310
+ } else {
311
+ npcm7xx_smbus_recv_byte(s);
312
+ }
313
break;
314
315
default:
316
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write_st(NPCM7xxSMBusState *s, uint8_t value)
317
}
318
319
if (value & NPCM7XX_SMBST_STASTR &&
320
- s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) {
321
- npcm7xx_smbus_recv_byte(s);
322
+ s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) {
323
+ if (NPCM7XX_SMBUS_FIFO_ENABLED(s)) {
324
+ npcm7xx_smbus_recv_fifo(s);
325
+ } else {
326
+ npcm7xx_smbus_recv_byte(s);
327
+ }
328
}
329
330
npcm7xx_smbus_update_irq(s);
331
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write_ctl2(NPCM7xxSMBusState *s, uint8_t value)
332
s->st = 0;
333
s->cst3 = s->cst3 & (~NPCM7XX_SMBCST3_EO_BUSY);
334
s->cst = 0;
335
+ npcm7xx_smbus_clear_buffer(s);
336
}
337
}
338
339
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write_ctl3(NPCM7xxSMBusState *s, uint8_t value)
340
NPCM7XX_SMBCTL3_SCL_LVL | NPCM7XX_SMBCTL3_SDA_LVL);
341
}
342
343
+static void npcm7xx_smbus_write_fif_ctl(NPCM7xxSMBusState *s, uint8_t value)
344
+{
345
+ uint8_t new_ctl = value;
346
+
347
+ new_ctl = KEEP_OLD_BIT(s->fif_ctl, new_ctl, NPCM7XX_SMBFIF_CTL_FAIR_RDY);
348
+ new_ctl = WRITE_ONE_CLEAR(new_ctl, value, NPCM7XX_SMBFIF_CTL_FAIR_RDY);
349
+ new_ctl = KEEP_OLD_BIT(s->fif_ctl, new_ctl, NPCM7XX_SMBFIF_CTL_FAIR_BUSY);
350
+ s->fif_ctl = new_ctl;
351
+}
352
+
353
+static void npcm7xx_smbus_write_fif_cts(NPCM7xxSMBusState *s, uint8_t value)
354
+{
355
+ s->fif_cts = WRITE_ONE_CLEAR(s->fif_cts, value, NPCM7XX_SMBFIF_CTS_STR);
356
+ s->fif_cts = WRITE_ONE_CLEAR(s->fif_cts, value, NPCM7XX_SMBFIF_CTS_RXF_TXE);
357
+ s->fif_cts = KEEP_OLD_BIT(value, s->fif_cts, NPCM7XX_SMBFIF_CTS_RFTE_IE);
358
+
359
+ if (value & NPCM7XX_SMBFIF_CTS_CLR_FIFO) {
360
+ npcm7xx_smbus_clear_buffer(s);
361
+ }
362
+}
363
+
364
+static void npcm7xx_smbus_write_txf_ctl(NPCM7xxSMBusState *s, uint8_t value)
365
+{
366
+ s->txf_ctl = value;
367
+}
368
+
369
+static void npcm7xx_smbus_write_t_out(NPCM7xxSMBusState *s, uint8_t value)
370
+{
371
+ uint8_t new_t_out = value;
372
+
373
+ if ((value & NPCM7XX_SMBT_OUT_ST) || (!(s->t_out & NPCM7XX_SMBT_OUT_ST))) {
374
+ new_t_out &= ~NPCM7XX_SMBT_OUT_ST;
375
+ } else {
376
+ new_t_out |= NPCM7XX_SMBT_OUT_ST;
377
+ }
378
+
379
+ s->t_out = new_t_out;
380
+}
381
+
382
+static void npcm7xx_smbus_write_txf_sts(NPCM7xxSMBusState *s, uint8_t value)
383
+{
384
+ s->txf_sts = WRITE_ONE_CLEAR(s->txf_sts, value, NPCM7XX_SMBTXF_STS_TX_THST);
385
+}
386
+
387
+static void npcm7xx_smbus_write_rxf_sts(NPCM7xxSMBusState *s, uint8_t value)
388
+{
389
+ if (value & NPCM7XX_SMBRXF_STS_RX_THST) {
390
+ s->rxf_sts &= ~NPCM7XX_SMBRXF_STS_RX_THST;
391
+ if (s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) {
392
+ npcm7xx_smbus_recv_fifo(s);
393
+ }
394
+ }
395
+}
396
+
397
+static void npcm7xx_smbus_write_rxf_ctl(NPCM7xxSMBusState *s, uint8_t value)
398
+{
399
+ uint8_t new_ctl = value;
400
+
401
+ if (!(value & NPCM7XX_SMBRXF_CTL_LAST)) {
402
+ new_ctl = KEEP_OLD_BIT(s->rxf_ctl, new_ctl, NPCM7XX_SMBRXF_CTL_LAST);
403
+ }
404
+ s->rxf_ctl = new_ctl;
405
+}
406
+
407
static uint64_t npcm7xx_smbus_read(void *opaque, hwaddr offset, unsigned size)
408
{
409
NPCM7xxSMBusState *s = opaque;
410
@@ -XXX,XX +XXX,XX @@ static uint64_t npcm7xx_smbus_read(void *opaque, hwaddr offset, unsigned size)
411
default:
412
if (bank) {
413
/* Bank 1 */
414
- qemu_log_mask(LOG_GUEST_ERROR,
415
- "%s: read from invalid offset 0x%" HWADDR_PRIx "\n",
416
- DEVICE(s)->canonical_path, offset);
417
+ switch (offset) {
418
+ case NPCM7XX_SMB_FIF_CTS:
419
+ value = s->fif_cts;
420
+ break;
421
+
422
+ case NPCM7XX_SMB_FAIR_PER:
423
+ value = s->fair_per;
424
+ break;
425
+
426
+ case NPCM7XX_SMB_TXF_CTL:
427
+ value = s->txf_ctl;
428
+ break;
429
+
430
+ case NPCM7XX_SMB_T_OUT:
431
+ value = s->t_out;
432
+ break;
433
+
434
+ case NPCM7XX_SMB_TXF_STS:
435
+ value = s->txf_sts;
436
+ break;
437
+
438
+ case NPCM7XX_SMB_RXF_STS:
439
+ value = s->rxf_sts;
440
+ break;
441
+
442
+ case NPCM7XX_SMB_RXF_CTL:
443
+ value = s->rxf_ctl;
444
+ break;
445
+
446
+ default:
447
+ qemu_log_mask(LOG_GUEST_ERROR,
448
+ "%s: read from invalid offset 0x%" HWADDR_PRIx "\n",
449
+ DEVICE(s)->canonical_path, offset);
450
+ break;
451
+ }
452
} else {
453
/* Bank 0 */
454
switch (offset) {
455
@@ -XXX,XX +XXX,XX @@ static uint64_t npcm7xx_smbus_read(void *opaque, hwaddr offset, unsigned size)
456
value = s->scllt;
457
break;
458
459
+ case NPCM7XX_SMB_FIF_CTL:
460
+ value = s->fif_ctl;
461
+ break;
462
+
463
case NPCM7XX_SMB_SCLHT:
464
value = s->sclht;
465
break;
466
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write(void *opaque, hwaddr offset, uint64_t value,
467
default:
468
if (bank) {
469
/* Bank 1 */
470
- qemu_log_mask(LOG_GUEST_ERROR,
471
- "%s: write to invalid offset 0x%" HWADDR_PRIx "\n",
472
- DEVICE(s)->canonical_path, offset);
473
+ switch (offset) {
474
+ case NPCM7XX_SMB_FIF_CTS:
475
+ npcm7xx_smbus_write_fif_cts(s, value);
476
+ break;
477
+
478
+ case NPCM7XX_SMB_FAIR_PER:
479
+ s->fair_per = value;
480
+ break;
481
+
482
+ case NPCM7XX_SMB_TXF_CTL:
483
+ npcm7xx_smbus_write_txf_ctl(s, value);
484
+ break;
485
+
486
+ case NPCM7XX_SMB_T_OUT:
487
+ npcm7xx_smbus_write_t_out(s, value);
488
+ break;
489
+
490
+ case NPCM7XX_SMB_TXF_STS:
491
+ npcm7xx_smbus_write_txf_sts(s, value);
492
+ break;
493
+
494
+ case NPCM7XX_SMB_RXF_STS:
495
+ npcm7xx_smbus_write_rxf_sts(s, value);
496
+ break;
497
+
498
+ case NPCM7XX_SMB_RXF_CTL:
499
+ npcm7xx_smbus_write_rxf_ctl(s, value);
500
+ break;
501
+
502
+ default:
503
+ qemu_log_mask(LOG_GUEST_ERROR,
504
+ "%s: write to invalid offset 0x%" HWADDR_PRIx "\n",
505
+ DEVICE(s)->canonical_path, offset);
506
+ break;
507
+ }
508
} else {
509
/* Bank 0 */
510
switch (offset) {
511
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_write(void *opaque, hwaddr offset, uint64_t value,
512
s->scllt = value;
513
break;
514
515
+ case NPCM7XX_SMB_FIF_CTL:
516
+ npcm7xx_smbus_write_fif_ctl(s, value);
517
+ break;
518
+
519
case NPCM7XX_SMB_SCLHT:
520
s->sclht = value;
521
break;
522
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_enter_reset(Object *obj, ResetType type)
523
s->scllt = NPCM7XX_SMB_SCLLT_INIT_VAL;
524
s->sclht = NPCM7XX_SMB_SCLHT_INIT_VAL;
525
526
+ s->fif_ctl = NPCM7XX_SMB_FIF_CTL_INIT_VAL;
527
+ s->fif_cts = NPCM7XX_SMB_FIF_CTS_INIT_VAL;
528
+ s->fair_per = NPCM7XX_SMB_FAIR_PER_INIT_VAL;
529
+ s->txf_ctl = NPCM7XX_SMB_TXF_CTL_INIT_VAL;
530
+ s->t_out = NPCM7XX_SMB_T_OUT_INIT_VAL;
531
+ s->txf_sts = NPCM7XX_SMB_TXF_STS_INIT_VAL;
532
+ s->rxf_sts = NPCM7XX_SMB_RXF_STS_INIT_VAL;
533
+ s->rxf_ctl = NPCM7XX_SMB_RXF_CTL_INIT_VAL;
534
+
535
+ npcm7xx_smbus_clear_buffer(s);
536
s->status = NPCM7XX_SMBUS_STATUS_IDLE;
537
+ s->rx_cur = 0;
538
}
539
540
static void npcm7xx_smbus_hold_reset(Object *obj)
541
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_npcm7xx_smbus = {
542
VMSTATE_UINT8_ARRAY(addr, NPCM7xxSMBusState, NPCM7XX_SMBUS_NR_ADDRS),
543
VMSTATE_UINT8(scllt, NPCM7xxSMBusState),
544
VMSTATE_UINT8(sclht, NPCM7xxSMBusState),
545
+ VMSTATE_UINT8(fif_ctl, NPCM7xxSMBusState),
546
+ VMSTATE_UINT8(fif_cts, NPCM7xxSMBusState),
547
+ VMSTATE_UINT8(fair_per, NPCM7xxSMBusState),
548
+ VMSTATE_UINT8(txf_ctl, NPCM7xxSMBusState),
549
+ VMSTATE_UINT8(t_out, NPCM7xxSMBusState),
550
+ VMSTATE_UINT8(txf_sts, NPCM7xxSMBusState),
551
+ VMSTATE_UINT8(rxf_sts, NPCM7xxSMBusState),
552
+ VMSTATE_UINT8(rxf_ctl, NPCM7xxSMBusState),
553
+ VMSTATE_UINT8_ARRAY(rx_fifo, NPCM7xxSMBusState,
554
+ NPCM7XX_SMBUS_FIFO_SIZE),
555
+ VMSTATE_UINT8(rx_cur, NPCM7xxSMBusState),
556
VMSTATE_END_OF_LIST(),
557
},
558
};
559
diff --git a/tests/qtest/npcm7xx_smbus-test.c b/tests/qtest/npcm7xx_smbus-test.c
560
index XXXXXXX..XXXXXXX 100644
561
--- a/tests/qtest/npcm7xx_smbus-test.c
562
+++ b/tests/qtest/npcm7xx_smbus-test.c
563
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxSMBusBank1Register {
564
#define ADDR_EN BIT(7)
565
#define ADDR_A(rv) extract8((rv), 0, 6)
566
567
+/* FIF_CTL fields */
568
+#define FIF_CTL_FIFO_EN BIT(4)
569
+
570
+/* FIF_CTS fields */
571
+#define FIF_CTS_CLR_FIFO BIT(6)
572
+#define FIF_CTS_RFTE_IE BIT(3)
573
+#define FIF_CTS_RXF_TXE BIT(1)
574
+
575
+/* TXF_CTL fields */
576
+#define TXF_CTL_THR_TXIE BIT(6)
577
+#define TXF_CTL_TX_THR(rv) extract8((rv), 0, 5)
578
+
579
+/* TXF_STS fields */
580
+#define TXF_STS_TX_THST BIT(6)
581
+#define TXF_STS_TX_BYTES(rv) extract8((rv), 0, 5)
582
+
583
+/* RXF_CTL fields */
584
+#define RXF_CTL_THR_RXIE BIT(6)
585
+#define RXF_CTL_LAST BIT(5)
586
+#define RXF_CTL_RX_THR(rv) extract8((rv), 0, 5)
587
+
588
+/* RXF_STS fields */
589
+#define RXF_STS_RX_THST BIT(6)
590
+#define RXF_STS_RX_BYTES(rv) extract8((rv), 0, 5)
591
+
592
+
593
+static void choose_bank(QTestState *qts, uint64_t base_addr, uint8_t bank)
594
+{
595
+ uint8_t ctl3 = qtest_readb(qts, base_addr + OFFSET_CTL3);
596
+
597
+ if (bank) {
598
+ ctl3 |= CTL3_BNK_SEL;
599
+ } else {
600
+ ctl3 &= ~CTL3_BNK_SEL;
601
+ }
602
+
603
+ qtest_writeb(qts, base_addr + OFFSET_CTL3, ctl3);
604
+}
605
606
static void check_running(QTestState *qts, uint64_t base_addr)
607
{
608
@@ -XXX,XX +XXX,XX @@ static void send_byte(QTestState *qts, uint64_t base_addr, uint8_t byte)
609
qtest_writeb(qts, base_addr + OFFSET_SDA, byte);
610
}
611
612
+static bool check_recv(QTestState *qts, uint64_t base_addr)
613
+{
614
+ uint8_t st, fif_ctl, rxf_ctl, rxf_sts;
615
+ bool fifo;
616
+
617
+ st = qtest_readb(qts, base_addr + OFFSET_ST);
618
+ choose_bank(qts, base_addr, 0);
619
+ fif_ctl = qtest_readb(qts, base_addr + OFFSET_FIF_CTL);
620
+ fifo = fif_ctl & FIF_CTL_FIFO_EN;
621
+ if (!fifo) {
622
+ return st == (ST_MODE | ST_SDAST);
623
+ }
624
+
625
+ choose_bank(qts, base_addr, 1);
626
+ rxf_ctl = qtest_readb(qts, base_addr + OFFSET_RXF_CTL);
627
+ rxf_sts = qtest_readb(qts, base_addr + OFFSET_RXF_STS);
628
+
629
+ if ((rxf_ctl & RXF_CTL_THR_RXIE) && RXF_STS_RX_BYTES(rxf_sts) < 16) {
630
+ return st == ST_MODE;
631
+ } else {
632
+ return st == (ST_MODE | ST_SDAST);
633
+ }
634
+}
635
+
636
static uint8_t recv_byte(QTestState *qts, uint64_t base_addr)
637
{
638
- g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_ST), ==,
639
- ST_MODE | ST_SDAST);
640
+ g_assert_true(check_recv(qts, base_addr));
641
return qtest_readb(qts, base_addr + OFFSET_SDA);
642
}
643
644
@@ -XXX,XX +XXX,XX @@ static void send_address(QTestState *qts, uint64_t base_addr, uint8_t addr,
645
qtest_writeb(qts, base_addr + OFFSET_ST, ST_STASTR);
646
st = qtest_readb(qts, base_addr + OFFSET_ST);
647
if (recv) {
648
- g_assert_cmphex(st, ==, ST_MODE | ST_SDAST);
649
+ g_assert_true(check_recv(qts, base_addr));
650
} else {
651
g_assert_cmphex(st, ==, ST_MODE | ST_XMIT | ST_SDAST);
652
}
653
@@ -XXX,XX +XXX,XX @@ static void send_nack(QTestState *qts, uint64_t base_addr)
654
qtest_writeb(qts, base_addr + OFFSET_CTL1, ctl1);
655
}
656
657
+static void start_fifo_mode(QTestState *qts, uint64_t base_addr)
658
+{
659
+ choose_bank(qts, base_addr, 0);
660
+ qtest_writeb(qts, base_addr + OFFSET_FIF_CTL, FIF_CTL_FIFO_EN);
661
+ g_assert_true(qtest_readb(qts, base_addr + OFFSET_FIF_CTL) &
662
+ FIF_CTL_FIFO_EN);
663
+ choose_bank(qts, base_addr, 1);
664
+ qtest_writeb(qts, base_addr + OFFSET_FIF_CTS,
665
+ FIF_CTS_CLR_FIFO | FIF_CTS_RFTE_IE);
666
+ g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_FIF_CTS), ==,
667
+ FIF_CTS_RFTE_IE);
668
+ g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_TXF_STS), ==, 0);
669
+ g_assert_cmphex(qtest_readb(qts, base_addr + OFFSET_RXF_STS), ==, 0);
670
+}
671
+
672
+static void start_recv_fifo(QTestState *qts, uint64_t base_addr, uint8_t bytes)
673
+{
674
+ choose_bank(qts, base_addr, 1);
675
+ qtest_writeb(qts, base_addr + OFFSET_TXF_CTL, 0);
676
+ qtest_writeb(qts, base_addr + OFFSET_RXF_CTL,
677
+ RXF_CTL_THR_RXIE | RXF_CTL_LAST | bytes);
678
+}
679
+
680
/* Check the SMBus's status is set correctly when disabled. */
681
static void test_disable_bus(gconstpointer data)
682
{
683
@@ -XXX,XX +XXX,XX @@ static void test_single_mode(gconstpointer data)
684
qtest_quit(qts);
685
}
686
687
+/* Check the SMBus can send and receive bytes in FIFO mode. */
688
+static void test_fifo_mode(gconstpointer data)
689
+{
690
+ intptr_t index = (intptr_t)data;
691
+ uint64_t base_addr = SMBUS_ADDR(index);
692
+ int irq = SMBUS_IRQ(index);
693
+ uint8_t value = 0x60;
694
+ QTestState *qts = qtest_init("-machine npcm750-evb");
695
+
696
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
697
+ enable_bus(qts, base_addr);
698
+ start_fifo_mode(qts, base_addr);
699
+ g_assert_false(qtest_get_irq(qts, irq));
700
+
701
+ /* Sending */
702
+ start_transfer(qts, base_addr);
703
+ send_address(qts, base_addr, EVB_DEVICE_ADDR, false, true);
704
+ choose_bank(qts, base_addr, 1);
705
+ g_assert_true(qtest_readb(qts, base_addr + OFFSET_FIF_CTS) &
706
+ FIF_CTS_RXF_TXE);
707
+ qtest_writeb(qts, base_addr + OFFSET_TXF_CTL, TXF_CTL_THR_TXIE);
708
+ send_byte(qts, base_addr, TMP105_REG_CONFIG);
709
+ send_byte(qts, base_addr, value);
710
+ g_assert_true(qtest_readb(qts, base_addr + OFFSET_FIF_CTS) &
711
+ FIF_CTS_RXF_TXE);
712
+ g_assert_true(qtest_readb(qts, base_addr + OFFSET_TXF_STS) &
713
+ TXF_STS_TX_THST);
714
+ g_assert_cmpuint(TXF_STS_TX_BYTES(
715
+ qtest_readb(qts, base_addr + OFFSET_TXF_STS)), ==, 0);
716
+ g_assert_true(qtest_get_irq(qts, irq));
717
+ stop_transfer(qts, base_addr);
718
+ check_stopped(qts, base_addr);
719
+
720
+ /* Receiving */
721
+ start_fifo_mode(qts, base_addr);
722
+ start_transfer(qts, base_addr);
723
+ send_address(qts, base_addr, EVB_DEVICE_ADDR, false, true);
724
+ send_byte(qts, base_addr, TMP105_REG_CONFIG);
725
+ start_transfer(qts, base_addr);
726
+ qtest_writeb(qts, base_addr + OFFSET_FIF_CTS, FIF_CTS_RXF_TXE);
727
+ start_recv_fifo(qts, base_addr, 1);
728
+ send_address(qts, base_addr, EVB_DEVICE_ADDR, true, true);
729
+ g_assert_false(qtest_readb(qts, base_addr + OFFSET_FIF_CTS) &
730
+ FIF_CTS_RXF_TXE);
731
+ g_assert_true(qtest_readb(qts, base_addr + OFFSET_RXF_STS) &
732
+ RXF_STS_RX_THST);
733
+ g_assert_cmpuint(RXF_STS_RX_BYTES(
734
+ qtest_readb(qts, base_addr + OFFSET_RXF_STS)), ==, 1);
735
+ send_nack(qts, base_addr);
736
+ stop_transfer(qts, base_addr);
737
+ check_running(qts, base_addr);
738
+ g_assert_cmphex(recv_byte(qts, base_addr), ==, value);
739
+ g_assert_cmpuint(RXF_STS_RX_BYTES(
740
+ qtest_readb(qts, base_addr + OFFSET_RXF_STS)), ==, 0);
741
+ check_stopped(qts, base_addr);
742
+ qtest_quit(qts);
743
+}
744
+
745
static void smbus_add_test(const char *name, int index, GTestDataFunc fn)
746
{
747
g_autofree char *full_name = g_strdup_printf(
748
@@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv)
749
750
for (i = 0; i < ARRAY_SIZE(evb_bus_list); ++i) {
751
add_test(single_mode, evb_bus_list[i]);
752
+ add_test(fifo_mode, evb_bus_list[i]);
753
}
754
755
return g_test_run();
756
diff --git a/hw/i2c/trace-events b/hw/i2c/trace-events
757
index XXXXXXX..XXXXXXX 100644
758
--- a/hw/i2c/trace-events
759
+++ b/hw/i2c/trace-events
760
@@ -XXX,XX +XXX,XX @@ npcm7xx_smbus_send_byte(const char *id, uint8_t value, int success) "%s send byt
761
npcm7xx_smbus_recv_byte(const char *id, uint8_t value) "%s recv byte: 0x%02x"
762
npcm7xx_smbus_stop(const char *id) "%s stopping"
763
npcm7xx_smbus_nack(const char *id) "%s nacking"
764
+npcm7xx_smbus_recv_fifo(const char *id, uint8_t received, uint8_t expected) "%s recv fifo: received %u, expected %u"
116
--
765
--
117
2.20.1
766
2.20.1
118
767
119
768
diff view generated by jsdifflib
1
Rename the files that used to be iotkit.[ch] to
1
From: Luc Michel <luc@lmichel.fr>
2
armsse.[ch] to reflect the fact they new cover
3
multiple Arm subsystems for embedded.
4
2
3
Also add Damien as a reviewer.
4
5
Signed-off-by: Luc Michel <luc@lmichel.fr>
6
Acked-by: Damien Hedde <damien.hedde@greensocs.com>
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Message-id: 20210211085318.2507-1-luc@lmichel.fr
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20190121185118.18550-8-peter.maydell@linaro.org
9
---
10
---
10
hw/arm/Makefile.objs | 2 +-
11
MAINTAINERS | 11 +++++++++++
11
include/hw/arm/{iotkit.h => armsse.h} | 4 ++--
12
1 file changed, 11 insertions(+)
12
hw/arm/{iotkit.c => armsse.c} | 2 +-
13
hw/arm/mps2-tz.c | 2 +-
14
MAINTAINERS | 4 ++--
15
default-configs/arm-softmmu.mak | 2 +-
16
6 files changed, 8 insertions(+), 8 deletions(-)
17
rename include/hw/arm/{iotkit.h => armsse.h} (99%)
18
rename hw/arm/{iotkit.c => armsse.c} (99%)
19
13
20
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
21
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/arm/Makefile.objs
23
+++ b/hw/arm/Makefile.objs
24
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o
25
obj-$(CONFIG_MPS2) += mps2.o
26
obj-$(CONFIG_MPS2) += mps2-tz.o
27
obj-$(CONFIG_MSF2) += msf2-soc.o msf2-som.o
28
-obj-$(CONFIG_IOTKIT) += iotkit.o
29
+obj-$(CONFIG_ARMSSE) += armsse.o
30
obj-$(CONFIG_FSL_IMX7) += fsl-imx7.o mcimx7d-sabre.o
31
obj-$(CONFIG_ARM_SMMUV3) += smmu-common.o smmuv3.o
32
obj-$(CONFIG_FSL_IMX6UL) += fsl-imx6ul.o mcimx6ul-evk.o
33
diff --git a/include/hw/arm/iotkit.h b/include/hw/arm/armsse.h
34
similarity index 99%
35
rename from include/hw/arm/iotkit.h
36
rename to include/hw/arm/armsse.h
37
index XXXXXXX..XXXXXXX 100644
38
--- a/include/hw/arm/iotkit.h
39
+++ b/include/hw/arm/armsse.h
40
@@ -XXX,XX +XXX,XX @@
41
* + named GPIO outputs mscexp_ns[0..15]
42
*/
43
44
-#ifndef IOTKIT_H
45
-#define IOTKIT_H
46
+#ifndef ARMSSE_H
47
+#define ARMSSE_H
48
49
#include "hw/sysbus.h"
50
#include "hw/arm/armv7m.h"
51
diff --git a/hw/arm/iotkit.c b/hw/arm/armsse.c
52
similarity index 99%
53
rename from hw/arm/iotkit.c
54
rename to hw/arm/armsse.c
55
index XXXXXXX..XXXXXXX 100644
56
--- a/hw/arm/iotkit.c
57
+++ b/hw/arm/armsse.c
58
@@ -XXX,XX +XXX,XX @@
59
#include "trace.h"
60
#include "hw/sysbus.h"
61
#include "hw/registerfields.h"
62
-#include "hw/arm/iotkit.h"
63
+#include "hw/arm/armsse.h"
64
#include "hw/arm/arm.h"
65
66
struct ARMSSEInfo {
67
diff --git a/hw/arm/mps2-tz.c b/hw/arm/mps2-tz.c
68
index XXXXXXX..XXXXXXX 100644
69
--- a/hw/arm/mps2-tz.c
70
+++ b/hw/arm/mps2-tz.c
71
@@ -XXX,XX +XXX,XX @@
72
#include "hw/misc/mps2-fpgaio.h"
73
#include "hw/misc/tz-mpc.h"
74
#include "hw/misc/tz-msc.h"
75
-#include "hw/arm/iotkit.h"
76
+#include "hw/arm/armsse.h"
77
#include "hw/dma/pl080.h"
78
#include "hw/ssi/pl022.h"
79
#include "hw/devices.h"
80
diff --git a/MAINTAINERS b/MAINTAINERS
14
diff --git a/MAINTAINERS b/MAINTAINERS
81
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
82
--- a/MAINTAINERS
16
--- a/MAINTAINERS
83
+++ b/MAINTAINERS
17
+++ b/MAINTAINERS
84
@@ -XXX,XX +XXX,XX @@ F: hw/arm/mps2.c
18
@@ -XXX,XX +XXX,XX @@ F: pc-bios/opensbi-*
85
F: hw/arm/mps2-tz.c
19
F: .gitlab-ci.d/opensbi.yml
86
F: hw/misc/mps2-*.c
20
F: .gitlab-ci.d/opensbi/
87
F: include/hw/misc/mps2-*.h
21
88
-F: hw/arm/iotkit.c
22
+Clock framework
89
-F: include/hw/arm/iotkit.h
23
+M: Luc Michel <luc@lmichel.fr>
90
+F: hw/arm/armsse.c
24
+R: Damien Hedde <damien.hedde@greensocs.com>
91
+F: include/hw/arm/armsse.h
25
+S: Maintained
92
F: hw/misc/iotkit-secctl.c
26
+F: include/hw/clock.h
93
F: include/hw/misc/iotkit-secctl.h
27
+F: include/hw/qdev-clock.h
94
F: hw/misc/iotkit-sysctl.c
28
+F: hw/core/clock.c
95
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
29
+F: hw/core/clock-vmstate.c
96
index XXXXXXX..XXXXXXX 100644
30
+F: hw/core/qdev-clock.c
97
--- a/default-configs/arm-softmmu.mak
31
+F: docs/devel/clocks.rst
98
+++ b/default-configs/arm-softmmu.mak
32
+
99
@@ -XXX,XX +XXX,XX @@ CONFIG_MPS2_SCC=y
33
Usermode Emulation
100
CONFIG_TZ_MPC=y
34
------------------
101
CONFIG_TZ_MSC=y
35
Overall usermode emulation
102
CONFIG_TZ_PPC=y
103
-CONFIG_IOTKIT=y
104
+CONFIG_ARMSSE=y
105
CONFIG_IOTKIT_SECCTL=y
106
CONFIG_IOTKIT_SYSCTL=y
107
CONFIG_IOTKIT_SYSINFO=y
108
--
36
--
109
2.20.1
37
2.20.1
110
38
111
39
diff view generated by jsdifflib
1
The SSE-200 has a CPU_IDENTITY register block, which is a set of
1
From: Doug Evans <dje@google.com>
2
read-only registers. As well as the usual PID/CID registers, there
3
is a single CPUID register which indicates whether the CPU is CPU 0
4
or CPU 1. Implement a model of this register block.
5
2
3
This is a 10/100 ethernet device that has several features.
4
Only the ones needed by the Linux driver have been implemented.
5
See npcm7xx_emc.c for a list of unimplemented features.
6
7
Reviewed-by: Hao Wu <wuhaotsh@google.com>
8
Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Doug Evans <dje@google.com>
11
Message-id: 20210213002520.1374134-2-dje@google.com
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20190121185118.18550-20-peter.maydell@linaro.org
9
---
13
---
10
hw/misc/Makefile.objs | 1 +
14
include/hw/net/npcm7xx_emc.h | 286 ++++++++++++
11
include/hw/misc/armsse-cpuid.h | 41 ++++++++++
15
hw/net/npcm7xx_emc.c | 857 +++++++++++++++++++++++++++++++++++
12
hw/misc/armsse-cpuid.c | 134 ++++++++++++++++++++++++++++++++
16
hw/net/meson.build | 1 +
13
MAINTAINERS | 2 +
17
hw/net/trace-events | 17 +
14
default-configs/arm-softmmu.mak | 1 +
18
4 files changed, 1161 insertions(+)
15
hw/misc/trace-events | 4 +
19
create mode 100644 include/hw/net/npcm7xx_emc.h
16
6 files changed, 183 insertions(+)
20
create mode 100644 hw/net/npcm7xx_emc.c
17
create mode 100644 include/hw/misc/armsse-cpuid.h
18
create mode 100644 hw/misc/armsse-cpuid.c
19
21
20
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
22
diff --git a/include/hw/net/npcm7xx_emc.h b/include/hw/net/npcm7xx_emc.h
21
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/misc/Makefile.objs
23
+++ b/hw/misc/Makefile.objs
24
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_TZ_PPC) += tz-ppc.o
25
obj-$(CONFIG_IOTKIT_SECCTL) += iotkit-secctl.o
26
obj-$(CONFIG_IOTKIT_SYSCTL) += iotkit-sysctl.o
27
obj-$(CONFIG_IOTKIT_SYSINFO) += iotkit-sysinfo.o
28
+obj-$(CONFIG_ARMSSE_CPUID) += armsse-cpuid.o
29
30
obj-$(CONFIG_PVPANIC) += pvpanic.o
31
obj-$(CONFIG_AUX) += auxbus.o
32
diff --git a/include/hw/misc/armsse-cpuid.h b/include/hw/misc/armsse-cpuid.h
33
new file mode 100644
23
new file mode 100644
34
index XXXXXXX..XXXXXXX
24
index XXXXXXX..XXXXXXX
35
--- /dev/null
25
--- /dev/null
36
+++ b/include/hw/misc/armsse-cpuid.h
26
+++ b/include/hw/net/npcm7xx_emc.h
37
@@ -XXX,XX +XXX,XX @@
27
@@ -XXX,XX +XXX,XX @@
38
+/*
28
+/*
39
+ * ARM SSE-200 CPU_IDENTITY register block
29
+ * Nuvoton NPCM7xx EMC Module
40
+ *
30
+ *
41
+ * Copyright (c) 2019 Linaro Limited
31
+ * Copyright 2020 Google LLC
42
+ * Written by Peter Maydell
43
+ *
32
+ *
44
+ * This program is free software; you can redistribute it and/or modify
33
+ * This program is free software; you can redistribute it and/or modify it
45
+ * it under the terms of the GNU General Public License version 2 or
34
+ * under the terms of the GNU General Public License as published by the
46
+ * (at your option) any later version.
35
+ * Free Software Foundation; either version 2 of the License, or
36
+ * (at your option) any later version.
37
+ *
38
+ * This program is distributed in the hope that it will be useful, but WITHOUT
39
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
40
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
41
+ * for more details.
47
+ */
42
+ */
48
+
43
+
49
+/*
44
+#ifndef NPCM7XX_EMC_H
50
+ * This is a model of the "CPU_IDENTITY" register block which is part of the
45
+#define NPCM7XX_EMC_H
51
+ * Arm SSE-200 and documented in
46
+
52
+ * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
47
+#include "hw/irq.h"
53
+ *
54
+ * QEMU interface:
55
+ * + QOM property "CPUID": the value to use for the CPUID register
56
+ * + sysbus MMIO region 0: the system information register bank
57
+ */
58
+
59
+#ifndef HW_MISC_ARMSSE_CPUID_H
60
+#define HW_MISC_ARMSSE_CPUID_H
61
+
62
+#include "hw/sysbus.h"
48
+#include "hw/sysbus.h"
63
+
49
+#include "net/net.h"
64
+#define TYPE_ARMSSE_CPUID "armsse-cpuid"
50
+
65
+#define ARMSSE_CPUID(obj) OBJECT_CHECK(ARMSSECPUID, (obj), TYPE_ARMSSE_CPUID)
51
+/* 32-bit register indices. */
66
+
52
+enum NPCM7xxPWMRegister {
67
+typedef struct ARMSSECPUID {
53
+ /* Control registers. */
54
+ REG_CAMCMR,
55
+ REG_CAMEN,
56
+
57
+ /* There are 16 CAMn[ML] registers. */
58
+ REG_CAMM_BASE,
59
+ REG_CAML_BASE,
60
+ REG_CAMML_LAST = 0x21,
61
+
62
+ REG_TXDLSA = 0x22,
63
+ REG_RXDLSA,
64
+ REG_MCMDR,
65
+ REG_MIID,
66
+ REG_MIIDA,
67
+ REG_FFTCR,
68
+ REG_TSDR,
69
+ REG_RSDR,
70
+ REG_DMARFC,
71
+ REG_MIEN,
72
+
73
+ /* Status registers. */
74
+ REG_MISTA,
75
+ REG_MGSTA,
76
+ REG_MPCNT,
77
+ REG_MRPC,
78
+ REG_MRPCC,
79
+ REG_MREPC,
80
+ REG_DMARFS,
81
+ REG_CTXDSA,
82
+ REG_CTXBSA,
83
+ REG_CRXDSA,
84
+ REG_CRXBSA,
85
+
86
+ NPCM7XX_NUM_EMC_REGS,
87
+};
88
+
89
+/* REG_CAMCMR fields */
90
+/* Enable CAM Compare */
91
+#define REG_CAMCMR_ECMP (1 << 4)
92
+/* Complement CAM Compare */
93
+#define REG_CAMCMR_CCAM (1 << 3)
94
+/* Accept Broadcast Packet */
95
+#define REG_CAMCMR_ABP (1 << 2)
96
+/* Accept Multicast Packet */
97
+#define REG_CAMCMR_AMP (1 << 1)
98
+/* Accept Unicast Packet */
99
+#define REG_CAMCMR_AUP (1 << 0)
100
+
101
+/* REG_MCMDR fields */
102
+/* Software Reset */
103
+#define REG_MCMDR_SWR (1 << 24)
104
+/* Internal Loopback Select */
105
+#define REG_MCMDR_LBK (1 << 21)
106
+/* Operation Mode Select */
107
+#define REG_MCMDR_OPMOD (1 << 20)
108
+/* Enable MDC Clock Generation */
109
+#define REG_MCMDR_ENMDC (1 << 19)
110
+/* Full-Duplex Mode Select */
111
+#define REG_MCMDR_FDUP (1 << 18)
112
+/* Enable SQE Checking */
113
+#define REG_MCMDR_ENSEQ (1 << 17)
114
+/* Send PAUSE Frame */
115
+#define REG_MCMDR_SDPZ (1 << 16)
116
+/* No Defer */
117
+#define REG_MCMDR_NDEF (1 << 9)
118
+/* Frame Transmission On */
119
+#define REG_MCMDR_TXON (1 << 8)
120
+/* Strip CRC Checksum */
121
+#define REG_MCMDR_SPCRC (1 << 5)
122
+/* Accept CRC Error Packet */
123
+#define REG_MCMDR_AEP (1 << 4)
124
+/* Accept Control Packet */
125
+#define REG_MCMDR_ACP (1 << 3)
126
+/* Accept Runt Packet */
127
+#define REG_MCMDR_ARP (1 << 2)
128
+/* Accept Long Packet */
129
+#define REG_MCMDR_ALP (1 << 1)
130
+/* Frame Reception On */
131
+#define REG_MCMDR_RXON (1 << 0)
132
+
133
+/* REG_MIEN fields */
134
+/* Enable Transmit Descriptor Unavailable Interrupt */
135
+#define REG_MIEN_ENTDU (1 << 23)
136
+/* Enable Transmit Completion Interrupt */
137
+#define REG_MIEN_ENTXCP (1 << 18)
138
+/* Enable Transmit Interrupt */
139
+#define REG_MIEN_ENTXINTR (1 << 16)
140
+/* Enable Receive Descriptor Unavailable Interrupt */
141
+#define REG_MIEN_ENRDU (1 << 10)
142
+/* Enable Receive Good Interrupt */
143
+#define REG_MIEN_ENRXGD (1 << 4)
144
+/* Enable Receive Interrupt */
145
+#define REG_MIEN_ENRXINTR (1 << 0)
146
+
147
+/* REG_MISTA fields */
148
+/* TODO: Add error fields and support simulated errors? */
149
+/* Transmit Bus Error Interrupt */
150
+#define REG_MISTA_TXBERR (1 << 24)
151
+/* Transmit Descriptor Unavailable Interrupt */
152
+#define REG_MISTA_TDU (1 << 23)
153
+/* Transmit Completion Interrupt */
154
+#define REG_MISTA_TXCP (1 << 18)
155
+/* Transmit Interrupt */
156
+#define REG_MISTA_TXINTR (1 << 16)
157
+/* Receive Bus Error Interrupt */
158
+#define REG_MISTA_RXBERR (1 << 11)
159
+/* Receive Descriptor Unavailable Interrupt */
160
+#define REG_MISTA_RDU (1 << 10)
161
+/* DMA Early Notification Interrupt */
162
+#define REG_MISTA_DENI (1 << 9)
163
+/* Maximum Frame Length Interrupt */
164
+#define REG_MISTA_DFOI (1 << 8)
165
+/* Receive Good Interrupt */
166
+#define REG_MISTA_RXGD (1 << 4)
167
+/* Packet Too Long Interrupt */
168
+#define REG_MISTA_PTLE (1 << 3)
169
+/* Receive Interrupt */
170
+#define REG_MISTA_RXINTR (1 << 0)
171
+
172
+/* REG_MGSTA fields */
173
+/* Transmission Halted */
174
+#define REG_MGSTA_TXHA (1 << 11)
175
+/* Receive Halted */
176
+#define REG_MGSTA_RXHA (1 << 11)
177
+
178
+/* REG_DMARFC fields */
179
+/* Maximum Receive Frame Length */
180
+#define REG_DMARFC_RXMS(word) extract32((word), 0, 16)
181
+
182
+/* REG MIIDA fields */
183
+/* Busy Bit */
184
+#define REG_MIIDA_BUSY (1 << 17)
185
+
186
+/* Transmit and receive descriptors */
187
+typedef struct NPCM7xxEMCTxDesc NPCM7xxEMCTxDesc;
188
+typedef struct NPCM7xxEMCRxDesc NPCM7xxEMCRxDesc;
189
+
190
+struct NPCM7xxEMCTxDesc {
191
+ uint32_t flags;
192
+ uint32_t txbsa;
193
+ uint32_t status_and_length;
194
+ uint32_t ntxdsa;
195
+};
196
+
197
+struct NPCM7xxEMCRxDesc {
198
+ uint32_t status_and_length;
199
+ uint32_t rxbsa;
200
+ uint32_t reserved;
201
+ uint32_t nrxdsa;
202
+};
203
+
204
+/* NPCM7xxEMCTxDesc.flags values */
205
+/* Owner: 0 = cpu, 1 = emc */
206
+#define TX_DESC_FLAG_OWNER_MASK (1 << 31)
207
+/* Transmit interrupt enable */
208
+#define TX_DESC_FLAG_INTEN (1 << 2)
209
+/* CRC append */
210
+#define TX_DESC_FLAG_CRCAPP (1 << 1)
211
+/* Padding enable */
212
+#define TX_DESC_FLAG_PADEN (1 << 0)
213
+
214
+/* NPCM7xxEMCTxDesc.status_and_length values */
215
+/* Collision count */
216
+#define TX_DESC_STATUS_CCNT_SHIFT 28
217
+#define TX_DESC_STATUS_CCNT_BITSIZE 4
218
+/* SQE error */
219
+#define TX_DESC_STATUS_SQE (1 << 26)
220
+/* Transmission paused */
221
+#define TX_DESC_STATUS_PAU (1 << 25)
222
+/* P transmission halted */
223
+#define TX_DESC_STATUS_TXHA (1 << 24)
224
+/* Late collision */
225
+#define TX_DESC_STATUS_LC (1 << 23)
226
+/* Transmission abort */
227
+#define TX_DESC_STATUS_TXABT (1 << 22)
228
+/* No carrier sense */
229
+#define TX_DESC_STATUS_NCS (1 << 21)
230
+/* Defer exceed */
231
+#define TX_DESC_STATUS_EXDEF (1 << 20)
232
+/* Transmission complete */
233
+#define TX_DESC_STATUS_TXCP (1 << 19)
234
+/* Transmission deferred */
235
+#define TX_DESC_STATUS_DEF (1 << 17)
236
+/* Transmit interrupt */
237
+#define TX_DESC_STATUS_TXINTR (1 << 16)
238
+
239
+#define TX_DESC_PKT_LEN(word) extract32((word), 0, 16)
240
+
241
+/* Transmit buffer start address */
242
+#define TX_DESC_TXBSA(word) ((uint32_t) (word) & ~3u)
243
+
244
+/* Next transmit descriptor start address */
245
+#define TX_DESC_NTXDSA(word) ((uint32_t) (word) & ~3u)
246
+
247
+/* NPCM7xxEMCRxDesc.status_and_length values */
248
+/* Owner: 0b00 = cpu, 0b01 = undefined, 0b10 = emc, 0b11 = undefined */
249
+#define RX_DESC_STATUS_OWNER_SHIFT 30
250
+#define RX_DESC_STATUS_OWNER_BITSIZE 2
251
+#define RX_DESC_STATUS_OWNER_MASK (3 << RX_DESC_STATUS_OWNER_SHIFT)
252
+/* Runt packet */
253
+#define RX_DESC_STATUS_RP (1 << 22)
254
+/* Alignment error */
255
+#define RX_DESC_STATUS_ALIE (1 << 21)
256
+/* Frame reception complete */
257
+#define RX_DESC_STATUS_RXGD (1 << 20)
258
+/* Packet too long */
259
+#define RX_DESC_STATUS_PTLE (1 << 19)
260
+/* CRC error */
261
+#define RX_DESC_STATUS_CRCE (1 << 17)
262
+/* Receive interrupt */
263
+#define RX_DESC_STATUS_RXINTR (1 << 16)
264
+
265
+#define RX_DESC_PKT_LEN(word) extract32((word), 0, 16)
266
+
267
+/* Receive buffer start address */
268
+#define RX_DESC_RXBSA(word) ((uint32_t) (word) & ~3u)
269
+
270
+/* Next receive descriptor start address */
271
+#define RX_DESC_NRXDSA(word) ((uint32_t) (word) & ~3u)
272
+
273
+/* Minimum packet length, when TX_DESC_FLAG_PADEN is set. */
274
+#define MIN_PACKET_LENGTH 64
275
+
276
+struct NPCM7xxEMCState {
68
+ /*< private >*/
277
+ /*< private >*/
69
+ SysBusDevice parent_obj;
278
+ SysBusDevice parent;
70
+
71
+ /*< public >*/
279
+ /*< public >*/
280
+
72
+ MemoryRegion iomem;
281
+ MemoryRegion iomem;
73
+
282
+
74
+ /* Properties */
283
+ qemu_irq tx_irq;
75
+ uint32_t cpuid;
284
+ qemu_irq rx_irq;
76
+} ARMSSECPUID;
285
+
77
+
286
+ NICState *nic;
78
+#endif
287
+ NICConf conf;
79
diff --git a/hw/misc/armsse-cpuid.c b/hw/misc/armsse-cpuid.c
288
+
289
+ /* 0 or 1, for log messages */
290
+ uint8_t emc_num;
291
+
292
+ uint32_t regs[NPCM7XX_NUM_EMC_REGS];
293
+
294
+ /*
295
+ * tx is active. Set to true by TSDR and then switches off when out of
296
+ * descriptors. If the TXON bit in REG_MCMDR is off then this is off.
297
+ */
298
+ bool tx_active;
299
+
300
+ /*
301
+ * rx is active. Set to true by RSDR and then switches off when out of
302
+ * descriptors. If the RXON bit in REG_MCMDR is off then this is off.
303
+ */
304
+ bool rx_active;
305
+};
306
+
307
+typedef struct NPCM7xxEMCState NPCM7xxEMCState;
308
+
309
+#define TYPE_NPCM7XX_EMC "npcm7xx-emc"
310
+#define NPCM7XX_EMC(obj) \
311
+ OBJECT_CHECK(NPCM7xxEMCState, (obj), TYPE_NPCM7XX_EMC)
312
+
313
+#endif /* NPCM7XX_EMC_H */
314
diff --git a/hw/net/npcm7xx_emc.c b/hw/net/npcm7xx_emc.c
80
new file mode 100644
315
new file mode 100644
81
index XXXXXXX..XXXXXXX
316
index XXXXXXX..XXXXXXX
82
--- /dev/null
317
--- /dev/null
83
+++ b/hw/misc/armsse-cpuid.c
318
+++ b/hw/net/npcm7xx_emc.c
84
@@ -XXX,XX +XXX,XX @@
319
@@ -XXX,XX +XXX,XX @@
85
+/*
320
+/*
86
+ * ARM SSE-200 CPU_IDENTITY register block
321
+ * Nuvoton NPCM7xx EMC Module
87
+ *
322
+ *
88
+ * Copyright (c) 2019 Linaro Limited
323
+ * Copyright 2020 Google LLC
89
+ * Written by Peter Maydell
90
+ *
324
+ *
91
+ * This program is free software; you can redistribute it and/or modify
325
+ * This program is free software; you can redistribute it and/or modify it
92
+ * it under the terms of the GNU General Public License version 2 or
326
+ * under the terms of the GNU General Public License as published by the
93
+ * (at your option) any later version.
327
+ * Free Software Foundation; either version 2 of the License, or
328
+ * (at your option) any later version.
329
+ *
330
+ * This program is distributed in the hope that it will be useful, but WITHOUT
331
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
332
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
333
+ * for more details.
334
+ *
335
+ * Unsupported/unimplemented features:
336
+ * - MCMDR.FDUP (full duplex) is ignored, half duplex is not supported
337
+ * - Only CAM0 is supported, CAM[1-15] are not
338
+ * - writes to CAMEN.[1-15] are ignored, these bits always read as zeroes
339
+ * - MII is not implemented, MIIDA.BUSY and MIID always return zero
340
+ * - MCMDR.LBK is not implemented
341
+ * - MCMDR.{OPMOD,ENSQE,AEP,ARP} are not supported
342
+ * - H/W FIFOs are not supported, MCMDR.FFTCR is ignored
343
+ * - MGSTA.SQE is not supported
344
+ * - pause and control frames are not implemented
345
+ * - MGSTA.CCNT is not supported
346
+ * - MPCNT, DMARFS are not implemented
94
+ */
347
+ */
95
+
348
+
349
+#include "qemu/osdep.h"
350
+
351
+/* For crc32 */
352
+#include <zlib.h>
353
+
354
+#include "qemu-common.h"
355
+#include "hw/irq.h"
356
+#include "hw/qdev-clock.h"
357
+#include "hw/qdev-properties.h"
358
+#include "hw/net/npcm7xx_emc.h"
359
+#include "net/eth.h"
360
+#include "migration/vmstate.h"
361
+#include "qemu/bitops.h"
362
+#include "qemu/error-report.h"
363
+#include "qemu/log.h"
364
+#include "qemu/module.h"
365
+#include "qemu/units.h"
366
+#include "sysemu/dma.h"
367
+#include "trace.h"
368
+
369
+#define CRC_LENGTH 4
370
+
96
+/*
371
+/*
97
+ * This is a model of the "CPU_IDENTITY" register block which is part of the
372
+ * The maximum size of a (layer 2) ethernet frame as defined by 802.3.
98
+ * Arm SSE-200 and documented in
373
+ * 1518 = 6(dest macaddr) + 6(src macaddr) + 2(proto) + 4(crc) + 1500(payload)
99
+ * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
374
+ * This does not include an additional 4 for the vlan field (802.1q).
100
+ *
101
+ * It consists of one read-only CPUID register (set by QOM property), plus the
102
+ * usual ID registers.
103
+ */
375
+ */
104
+
376
+#define MAX_ETH_FRAME_SIZE 1518
105
+#include "qemu/osdep.h"
377
+
106
+#include "qemu/log.h"
378
+static const char *emc_reg_name(int regno)
107
+#include "trace.h"
379
+{
108
+#include "qapi/error.h"
380
+#define REG(name) case REG_ ## name: return #name;
109
+#include "sysemu/sysemu.h"
381
+ switch (regno) {
110
+#include "hw/sysbus.h"
382
+ REG(CAMCMR)
111
+#include "hw/registerfields.h"
383
+ REG(CAMEN)
112
+#include "hw/misc/armsse-cpuid.h"
384
+ REG(TXDLSA)
113
+
385
+ REG(RXDLSA)
114
+REG32(CPUID, 0x0)
386
+ REG(MCMDR)
115
+REG32(PID4, 0xfd0)
387
+ REG(MIID)
116
+REG32(PID5, 0xfd4)
388
+ REG(MIIDA)
117
+REG32(PID6, 0xfd8)
389
+ REG(FFTCR)
118
+REG32(PID7, 0xfdc)
390
+ REG(TSDR)
119
+REG32(PID0, 0xfe0)
391
+ REG(RSDR)
120
+REG32(PID1, 0xfe4)
392
+ REG(DMARFC)
121
+REG32(PID2, 0xfe8)
393
+ REG(MIEN)
122
+REG32(PID3, 0xfec)
394
+ REG(MISTA)
123
+REG32(CID0, 0xff0)
395
+ REG(MGSTA)
124
+REG32(CID1, 0xff4)
396
+ REG(MPCNT)
125
+REG32(CID2, 0xff8)
397
+ REG(MRPC)
126
+REG32(CID3, 0xffc)
398
+ REG(MRPCC)
127
+
399
+ REG(MREPC)
128
+/* PID/CID values */
400
+ REG(DMARFS)
129
+static const int sysinfo_id[] = {
401
+ REG(CTXDSA)
130
+ 0x04, 0x00, 0x00, 0x00, /* PID4..PID7 */
402
+ REG(CTXBSA)
131
+ 0x58, 0xb8, 0x0b, 0x00, /* PID0..PID3 */
403
+ REG(CRXDSA)
132
+ 0x0d, 0xf0, 0x05, 0xb1, /* CID0..CID3 */
404
+ REG(CRXBSA)
405
+ case REG_CAMM_BASE + 0: return "CAM0M";
406
+ case REG_CAML_BASE + 0: return "CAM0L";
407
+ case REG_CAMM_BASE + 2 ... REG_CAMML_LAST:
408
+ /* Only CAM0 is supported, fold the others into something simple. */
409
+ if (regno & 1) {
410
+ return "CAM<n>L";
411
+ } else {
412
+ return "CAM<n>M";
413
+ }
414
+ default: return "UNKNOWN";
415
+ }
416
+#undef REG
417
+}
418
+
419
+static void emc_reset(NPCM7xxEMCState *emc)
420
+{
421
+ trace_npcm7xx_emc_reset(emc->emc_num);
422
+
423
+ memset(&emc->regs[0], 0, sizeof(emc->regs));
424
+
425
+ /* These regs have non-zero reset values. */
426
+ emc->regs[REG_TXDLSA] = 0xfffffffc;
427
+ emc->regs[REG_RXDLSA] = 0xfffffffc;
428
+ emc->regs[REG_MIIDA] = 0x00900000;
429
+ emc->regs[REG_FFTCR] = 0x0101;
430
+ emc->regs[REG_DMARFC] = 0x0800;
431
+ emc->regs[REG_MPCNT] = 0x7fff;
432
+
433
+ emc->tx_active = false;
434
+ emc->rx_active = false;
435
+}
436
+
437
+static void npcm7xx_emc_reset(DeviceState *dev)
438
+{
439
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(dev);
440
+ emc_reset(emc);
441
+}
442
+
443
+static void emc_soft_reset(NPCM7xxEMCState *emc)
444
+{
445
+ /*
446
+ * The docs say at least MCMDR.{LBK,OPMOD} bits are not changed during a
447
+ * soft reset, but does not go into further detail. For now, KISS.
448
+ */
449
+ uint32_t mcmdr = emc->regs[REG_MCMDR];
450
+ emc_reset(emc);
451
+ emc->regs[REG_MCMDR] = mcmdr & (REG_MCMDR_LBK | REG_MCMDR_OPMOD);
452
+
453
+ qemu_set_irq(emc->tx_irq, 0);
454
+ qemu_set_irq(emc->rx_irq, 0);
455
+}
456
+
457
+static void emc_set_link(NetClientState *nc)
458
+{
459
+ /* Nothing to do yet. */
460
+}
461
+
462
+/* MISTA.TXINTR is the union of the individual bits with their enables. */
463
+static void emc_update_mista_txintr(NPCM7xxEMCState *emc)
464
+{
465
+ /* Only look at the bits we support. */
466
+ uint32_t mask = (REG_MISTA_TXBERR |
467
+ REG_MISTA_TDU |
468
+ REG_MISTA_TXCP);
469
+ if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & mask) {
470
+ emc->regs[REG_MISTA] |= REG_MISTA_TXINTR;
471
+ } else {
472
+ emc->regs[REG_MISTA] &= ~REG_MISTA_TXINTR;
473
+ }
474
+}
475
+
476
+/* MISTA.RXINTR is the union of the individual bits with their enables. */
477
+static void emc_update_mista_rxintr(NPCM7xxEMCState *emc)
478
+{
479
+ /* Only look at the bits we support. */
480
+ uint32_t mask = (REG_MISTA_RXBERR |
481
+ REG_MISTA_RDU |
482
+ REG_MISTA_RXGD);
483
+ if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & mask) {
484
+ emc->regs[REG_MISTA] |= REG_MISTA_RXINTR;
485
+ } else {
486
+ emc->regs[REG_MISTA] &= ~REG_MISTA_RXINTR;
487
+ }
488
+}
489
+
490
+/* N.B. emc_update_mista_txintr must have already been called. */
491
+static void emc_update_tx_irq(NPCM7xxEMCState *emc)
492
+{
493
+ int level = !!(emc->regs[REG_MISTA] &
494
+ emc->regs[REG_MIEN] &
495
+ REG_MISTA_TXINTR);
496
+ trace_npcm7xx_emc_update_tx_irq(level);
497
+ qemu_set_irq(emc->tx_irq, level);
498
+}
499
+
500
+/* N.B. emc_update_mista_rxintr must have already been called. */
501
+static void emc_update_rx_irq(NPCM7xxEMCState *emc)
502
+{
503
+ int level = !!(emc->regs[REG_MISTA] &
504
+ emc->regs[REG_MIEN] &
505
+ REG_MISTA_RXINTR);
506
+ trace_npcm7xx_emc_update_rx_irq(level);
507
+ qemu_set_irq(emc->rx_irq, level);
508
+}
509
+
510
+/* Update IRQ states due to changes in MIEN,MISTA. */
511
+static void emc_update_irq_from_reg_change(NPCM7xxEMCState *emc)
512
+{
513
+ emc_update_mista_txintr(emc);
514
+ emc_update_tx_irq(emc);
515
+
516
+ emc_update_mista_rxintr(emc);
517
+ emc_update_rx_irq(emc);
518
+}
519
+
520
+static int emc_read_tx_desc(dma_addr_t addr, NPCM7xxEMCTxDesc *desc)
521
+{
522
+ if (dma_memory_read(&address_space_memory, addr, desc, sizeof(*desc))) {
523
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read descriptor @ 0x%"
524
+ HWADDR_PRIx "\n", __func__, addr);
525
+ return -1;
526
+ }
527
+ desc->flags = le32_to_cpu(desc->flags);
528
+ desc->txbsa = le32_to_cpu(desc->txbsa);
529
+ desc->status_and_length = le32_to_cpu(desc->status_and_length);
530
+ desc->ntxdsa = le32_to_cpu(desc->ntxdsa);
531
+ return 0;
532
+}
533
+
534
+static int emc_write_tx_desc(const NPCM7xxEMCTxDesc *desc, dma_addr_t addr)
535
+{
536
+ NPCM7xxEMCTxDesc le_desc;
537
+
538
+ le_desc.flags = cpu_to_le32(desc->flags);
539
+ le_desc.txbsa = cpu_to_le32(desc->txbsa);
540
+ le_desc.status_and_length = cpu_to_le32(desc->status_and_length);
541
+ le_desc.ntxdsa = cpu_to_le32(desc->ntxdsa);
542
+ if (dma_memory_write(&address_space_memory, addr, &le_desc,
543
+ sizeof(le_desc))) {
544
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to write descriptor @ 0x%"
545
+ HWADDR_PRIx "\n", __func__, addr);
546
+ return -1;
547
+ }
548
+ return 0;
549
+}
550
+
551
+static int emc_read_rx_desc(dma_addr_t addr, NPCM7xxEMCRxDesc *desc)
552
+{
553
+ if (dma_memory_read(&address_space_memory, addr, desc, sizeof(*desc))) {
554
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read descriptor @ 0x%"
555
+ HWADDR_PRIx "\n", __func__, addr);
556
+ return -1;
557
+ }
558
+ desc->status_and_length = le32_to_cpu(desc->status_and_length);
559
+ desc->rxbsa = le32_to_cpu(desc->rxbsa);
560
+ desc->reserved = le32_to_cpu(desc->reserved);
561
+ desc->nrxdsa = le32_to_cpu(desc->nrxdsa);
562
+ return 0;
563
+}
564
+
565
+static int emc_write_rx_desc(const NPCM7xxEMCRxDesc *desc, dma_addr_t addr)
566
+{
567
+ NPCM7xxEMCRxDesc le_desc;
568
+
569
+ le_desc.status_and_length = cpu_to_le32(desc->status_and_length);
570
+ le_desc.rxbsa = cpu_to_le32(desc->rxbsa);
571
+ le_desc.reserved = cpu_to_le32(desc->reserved);
572
+ le_desc.nrxdsa = cpu_to_le32(desc->nrxdsa);
573
+ if (dma_memory_write(&address_space_memory, addr, &le_desc,
574
+ sizeof(le_desc))) {
575
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to write descriptor @ 0x%"
576
+ HWADDR_PRIx "\n", __func__, addr);
577
+ return -1;
578
+ }
579
+ return 0;
580
+}
581
+
582
+static void emc_set_mista(NPCM7xxEMCState *emc, uint32_t flags)
583
+{
584
+ trace_npcm7xx_emc_set_mista(flags);
585
+ emc->regs[REG_MISTA] |= flags;
586
+ if (extract32(flags, 16, 16)) {
587
+ emc_update_mista_txintr(emc);
588
+ }
589
+ if (extract32(flags, 0, 16)) {
590
+ emc_update_mista_rxintr(emc);
591
+ }
592
+}
593
+
594
+static void emc_halt_tx(NPCM7xxEMCState *emc, uint32_t mista_flag)
595
+{
596
+ emc->tx_active = false;
597
+ emc_set_mista(emc, mista_flag);
598
+}
599
+
600
+static void emc_halt_rx(NPCM7xxEMCState *emc, uint32_t mista_flag)
601
+{
602
+ emc->rx_active = false;
603
+ emc_set_mista(emc, mista_flag);
604
+}
605
+
606
+static void emc_set_next_tx_descriptor(NPCM7xxEMCState *emc,
607
+ const NPCM7xxEMCTxDesc *tx_desc,
608
+ uint32_t desc_addr)
609
+{
610
+ /* Update the current descriptor, if only to reset the owner flag. */
611
+ if (emc_write_tx_desc(tx_desc, desc_addr)) {
612
+ /*
613
+ * We just read it so this shouldn't generally happen.
614
+ * Error already reported.
615
+ */
616
+ emc_set_mista(emc, REG_MISTA_TXBERR);
617
+ }
618
+ emc->regs[REG_CTXDSA] = TX_DESC_NTXDSA(tx_desc->ntxdsa);
619
+}
620
+
621
+static void emc_set_next_rx_descriptor(NPCM7xxEMCState *emc,
622
+ const NPCM7xxEMCRxDesc *rx_desc,
623
+ uint32_t desc_addr)
624
+{
625
+ /* Update the current descriptor, if only to reset the owner flag. */
626
+ if (emc_write_rx_desc(rx_desc, desc_addr)) {
627
+ /*
628
+ * We just read it so this shouldn't generally happen.
629
+ * Error already reported.
630
+ */
631
+ emc_set_mista(emc, REG_MISTA_RXBERR);
632
+ }
633
+ emc->regs[REG_CRXDSA] = RX_DESC_NRXDSA(rx_desc->nrxdsa);
634
+}
635
+
636
+static void emc_try_send_next_packet(NPCM7xxEMCState *emc)
637
+{
638
+ /* Working buffer for sending out packets. Most packets fit in this. */
639
+#define TX_BUFFER_SIZE 2048
640
+ uint8_t tx_send_buffer[TX_BUFFER_SIZE];
641
+ uint32_t desc_addr = TX_DESC_NTXDSA(emc->regs[REG_CTXDSA]);
642
+ NPCM7xxEMCTxDesc tx_desc;
643
+ uint32_t next_buf_addr, length;
644
+ uint8_t *buf;
645
+ g_autofree uint8_t *malloced_buf = NULL;
646
+
647
+ if (emc_read_tx_desc(desc_addr, &tx_desc)) {
648
+ /* Error reading descriptor, already reported. */
649
+ emc_halt_tx(emc, REG_MISTA_TXBERR);
650
+ emc_update_tx_irq(emc);
651
+ return;
652
+ }
653
+
654
+ /* Nothing we can do if we don't own the descriptor. */
655
+ if (!(tx_desc.flags & TX_DESC_FLAG_OWNER_MASK)) {
656
+ trace_npcm7xx_emc_cpu_owned_desc(desc_addr);
657
+ emc_halt_tx(emc, REG_MISTA_TDU);
658
+ emc_update_tx_irq(emc);
659
+ return;
660
+ }
661
+
662
+ /* Give the descriptor back regardless of what happens. */
663
+ tx_desc.flags &= ~TX_DESC_FLAG_OWNER_MASK;
664
+ tx_desc.status_and_length &= 0xffff;
665
+
666
+ /*
667
+ * Despite the h/w documentation saying the tx buffer is word aligned,
668
+ * the linux driver does not word align the buffer. There is value in not
669
+ * aligning the buffer: See the description of NET_IP_ALIGN in linux
670
+ * kernel sources.
671
+ */
672
+ next_buf_addr = tx_desc.txbsa;
673
+ emc->regs[REG_CTXBSA] = next_buf_addr;
674
+ length = TX_DESC_PKT_LEN(tx_desc.status_and_length);
675
+ buf = &tx_send_buffer[0];
676
+
677
+ if (length > sizeof(tx_send_buffer)) {
678
+ malloced_buf = g_malloc(length);
679
+ buf = malloced_buf;
680
+ }
681
+
682
+ if (dma_memory_read(&address_space_memory, next_buf_addr, buf, length)) {
683
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Failed to read packet @ 0x%x\n",
684
+ __func__, next_buf_addr);
685
+ emc_set_mista(emc, REG_MISTA_TXBERR);
686
+ emc_set_next_tx_descriptor(emc, &tx_desc, desc_addr);
687
+ emc_update_tx_irq(emc);
688
+ trace_npcm7xx_emc_tx_done(emc->regs[REG_CTXDSA]);
689
+ return;
690
+ }
691
+
692
+ if ((tx_desc.flags & TX_DESC_FLAG_PADEN) && (length < MIN_PACKET_LENGTH)) {
693
+ memset(buf + length, 0, MIN_PACKET_LENGTH - length);
694
+ length = MIN_PACKET_LENGTH;
695
+ }
696
+
697
+ /* N.B. emc_receive can get called here. */
698
+ qemu_send_packet(qemu_get_queue(emc->nic), buf, length);
699
+ trace_npcm7xx_emc_sent_packet(length);
700
+
701
+ tx_desc.status_and_length |= TX_DESC_STATUS_TXCP;
702
+ if (tx_desc.flags & TX_DESC_FLAG_INTEN) {
703
+ emc_set_mista(emc, REG_MISTA_TXCP);
704
+ }
705
+ if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & REG_MISTA_TXINTR) {
706
+ tx_desc.status_and_length |= TX_DESC_STATUS_TXINTR;
707
+ }
708
+
709
+ emc_set_next_tx_descriptor(emc, &tx_desc, desc_addr);
710
+ emc_update_tx_irq(emc);
711
+ trace_npcm7xx_emc_tx_done(emc->regs[REG_CTXDSA]);
712
+}
713
+
714
+static bool emc_can_receive(NetClientState *nc)
715
+{
716
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(qemu_get_nic_opaque(nc));
717
+
718
+ bool can_receive = emc->rx_active;
719
+ trace_npcm7xx_emc_can_receive(can_receive);
720
+ return can_receive;
721
+}
722
+
723
+/* If result is false then *fail_reason contains the reason. */
724
+static bool emc_receive_filter1(NPCM7xxEMCState *emc, const uint8_t *buf,
725
+ size_t len, const char **fail_reason)
726
+{
727
+ eth_pkt_types_e pkt_type = get_eth_packet_type(PKT_GET_ETH_HDR(buf));
728
+
729
+ switch (pkt_type) {
730
+ case ETH_PKT_BCAST:
731
+ if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) {
732
+ return true;
733
+ } else {
734
+ *fail_reason = "Broadcast packet disabled";
735
+ return !!(emc->regs[REG_CAMCMR] & REG_CAMCMR_ABP);
736
+ }
737
+ case ETH_PKT_MCAST:
738
+ if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) {
739
+ return true;
740
+ } else {
741
+ *fail_reason = "Multicast packet disabled";
742
+ return !!(emc->regs[REG_CAMCMR] & REG_CAMCMR_AMP);
743
+ }
744
+ case ETH_PKT_UCAST: {
745
+ bool matches;
746
+ if (emc->regs[REG_CAMCMR] & REG_CAMCMR_AUP) {
747
+ return true;
748
+ }
749
+ matches = ((emc->regs[REG_CAMCMR] & REG_CAMCMR_ECMP) &&
750
+ /* We only support one CAM register, CAM0. */
751
+ (emc->regs[REG_CAMEN] & (1 << 0)) &&
752
+ memcmp(buf, emc->conf.macaddr.a, ETH_ALEN) == 0);
753
+ if (emc->regs[REG_CAMCMR] & REG_CAMCMR_CCAM) {
754
+ *fail_reason = "MACADDR matched, comparison complemented";
755
+ return !matches;
756
+ } else {
757
+ *fail_reason = "MACADDR didn't match";
758
+ return matches;
759
+ }
760
+ }
761
+ default:
762
+ g_assert_not_reached();
763
+ }
764
+}
765
+
766
+static bool emc_receive_filter(NPCM7xxEMCState *emc, const uint8_t *buf,
767
+ size_t len)
768
+{
769
+ const char *fail_reason = NULL;
770
+ bool ok = emc_receive_filter1(emc, buf, len, &fail_reason);
771
+ if (!ok) {
772
+ trace_npcm7xx_emc_packet_filtered_out(fail_reason);
773
+ }
774
+ return ok;
775
+}
776
+
777
+static ssize_t emc_receive(NetClientState *nc, const uint8_t *buf, size_t len1)
778
+{
779
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(qemu_get_nic_opaque(nc));
780
+ const uint32_t len = len1;
781
+ size_t max_frame_len;
782
+ bool long_frame;
783
+ uint32_t desc_addr;
784
+ NPCM7xxEMCRxDesc rx_desc;
785
+ uint32_t crc;
786
+ uint8_t *crc_ptr;
787
+ uint32_t buf_addr;
788
+
789
+ trace_npcm7xx_emc_receiving_packet(len);
790
+
791
+ if (!emc_can_receive(nc)) {
792
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Unexpected packet\n", __func__);
793
+ return -1;
794
+ }
795
+
796
+ if (len < ETH_HLEN ||
797
+ /* Defensive programming: drop unsupportable large packets. */
798
+ len > 0xffff - CRC_LENGTH) {
799
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Dropped frame of %u bytes\n",
800
+ __func__, len);
801
+ return len;
802
+ }
803
+
804
+ /*
805
+ * DENI is set if EMC received the Length/Type field of the incoming
806
+ * packet, so it will be set regardless of what happens next.
807
+ */
808
+ emc_set_mista(emc, REG_MISTA_DENI);
809
+
810
+ if (!emc_receive_filter(emc, buf, len)) {
811
+ emc_update_rx_irq(emc);
812
+ return len;
813
+ }
814
+
815
+ /* Huge frames (> DMARFC) are dropped. */
816
+ max_frame_len = REG_DMARFC_RXMS(emc->regs[REG_DMARFC]);
817
+ if (len + CRC_LENGTH > max_frame_len) {
818
+ trace_npcm7xx_emc_packet_dropped(len);
819
+ emc_set_mista(emc, REG_MISTA_DFOI);
820
+ emc_update_rx_irq(emc);
821
+ return len;
822
+ }
823
+
824
+ /*
825
+ * Long Frames (> MAX_ETH_FRAME_SIZE) are also dropped, unless MCMDR.ALP
826
+ * is set.
827
+ */
828
+ long_frame = false;
829
+ if (len + CRC_LENGTH > MAX_ETH_FRAME_SIZE) {
830
+ if (emc->regs[REG_MCMDR] & REG_MCMDR_ALP) {
831
+ long_frame = true;
832
+ } else {
833
+ trace_npcm7xx_emc_packet_dropped(len);
834
+ emc_set_mista(emc, REG_MISTA_PTLE);
835
+ emc_update_rx_irq(emc);
836
+ return len;
837
+ }
838
+ }
839
+
840
+ desc_addr = RX_DESC_NRXDSA(emc->regs[REG_CRXDSA]);
841
+ if (emc_read_rx_desc(desc_addr, &rx_desc)) {
842
+ /* Error reading descriptor, already reported. */
843
+ emc_halt_rx(emc, REG_MISTA_RXBERR);
844
+ emc_update_rx_irq(emc);
845
+ return len;
846
+ }
847
+
848
+ /* Nothing we can do if we don't own the descriptor. */
849
+ if (!(rx_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK)) {
850
+ trace_npcm7xx_emc_cpu_owned_desc(desc_addr);
851
+ emc_halt_rx(emc, REG_MISTA_RDU);
852
+ emc_update_rx_irq(emc);
853
+ return len;
854
+ }
855
+
856
+ crc = 0;
857
+ crc_ptr = (uint8_t *) &crc;
858
+ if (!(emc->regs[REG_MCMDR] & REG_MCMDR_SPCRC)) {
859
+ crc = cpu_to_be32(crc32(~0, buf, len));
860
+ }
861
+
862
+ /* Give the descriptor back regardless of what happens. */
863
+ rx_desc.status_and_length &= ~RX_DESC_STATUS_OWNER_MASK;
864
+
865
+ buf_addr = rx_desc.rxbsa;
866
+ emc->regs[REG_CRXBSA] = buf_addr;
867
+ if (dma_memory_write(&address_space_memory, buf_addr, buf, len) ||
868
+ (!(emc->regs[REG_MCMDR] & REG_MCMDR_SPCRC) &&
869
+ dma_memory_write(&address_space_memory, buf_addr + len, crc_ptr,
870
+ 4))) {
871
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bus error writing packet\n",
872
+ __func__);
873
+ emc_set_mista(emc, REG_MISTA_RXBERR);
874
+ emc_set_next_rx_descriptor(emc, &rx_desc, desc_addr);
875
+ emc_update_rx_irq(emc);
876
+ trace_npcm7xx_emc_rx_done(emc->regs[REG_CRXDSA]);
877
+ return len;
878
+ }
879
+
880
+ trace_npcm7xx_emc_received_packet(len);
881
+
882
+ /* Note: We've already verified len+4 <= 0xffff. */
883
+ rx_desc.status_and_length = len;
884
+ if (!(emc->regs[REG_MCMDR] & REG_MCMDR_SPCRC)) {
885
+ rx_desc.status_and_length += 4;
886
+ }
887
+ rx_desc.status_and_length |= RX_DESC_STATUS_RXGD;
888
+ emc_set_mista(emc, REG_MISTA_RXGD);
889
+
890
+ if (emc->regs[REG_MISTA] & emc->regs[REG_MIEN] & REG_MISTA_RXINTR) {
891
+ rx_desc.status_and_length |= RX_DESC_STATUS_RXINTR;
892
+ }
893
+ if (long_frame) {
894
+ rx_desc.status_and_length |= RX_DESC_STATUS_PTLE;
895
+ }
896
+
897
+ emc_set_next_rx_descriptor(emc, &rx_desc, desc_addr);
898
+ emc_update_rx_irq(emc);
899
+ trace_npcm7xx_emc_rx_done(emc->regs[REG_CRXDSA]);
900
+ return len;
901
+}
902
+
903
+static void emc_try_receive_next_packet(NPCM7xxEMCState *emc)
904
+{
905
+ if (emc_can_receive(qemu_get_queue(emc->nic))) {
906
+ qemu_flush_queued_packets(qemu_get_queue(emc->nic));
907
+ }
908
+}
909
+
910
+static uint64_t npcm7xx_emc_read(void *opaque, hwaddr offset, unsigned size)
911
+{
912
+ NPCM7xxEMCState *emc = opaque;
913
+ uint32_t reg = offset / sizeof(uint32_t);
914
+ uint32_t result;
915
+
916
+ if (reg >= NPCM7XX_NUM_EMC_REGS) {
917
+ qemu_log_mask(LOG_GUEST_ERROR,
918
+ "%s: Invalid offset 0x%04" HWADDR_PRIx "\n",
919
+ __func__, offset);
920
+ return 0;
921
+ }
922
+
923
+ switch (reg) {
924
+ case REG_MIID:
925
+ /*
926
+ * We don't implement MII. For determinism, always return zero as
927
+ * writes record the last value written for debugging purposes.
928
+ */
929
+ qemu_log_mask(LOG_UNIMP, "%s: Read of MIID, returning 0\n", __func__);
930
+ result = 0;
931
+ break;
932
+ case REG_TSDR:
933
+ case REG_RSDR:
934
+ qemu_log_mask(LOG_GUEST_ERROR,
935
+ "%s: Read of write-only reg, %s/%d\n",
936
+ __func__, emc_reg_name(reg), reg);
937
+ return 0;
938
+ default:
939
+ result = emc->regs[reg];
940
+ break;
941
+ }
942
+
943
+ trace_npcm7xx_emc_reg_read(emc->emc_num, result, emc_reg_name(reg), reg);
944
+ return result;
945
+}
946
+
947
+static void npcm7xx_emc_write(void *opaque, hwaddr offset,
948
+ uint64_t v, unsigned size)
949
+{
950
+ NPCM7xxEMCState *emc = opaque;
951
+ uint32_t reg = offset / sizeof(uint32_t);
952
+ uint32_t value = v;
953
+
954
+ g_assert(size == sizeof(uint32_t));
955
+
956
+ if (reg >= NPCM7XX_NUM_EMC_REGS) {
957
+ qemu_log_mask(LOG_GUEST_ERROR,
958
+ "%s: Invalid offset 0x%04" HWADDR_PRIx "\n",
959
+ __func__, offset);
960
+ return;
961
+ }
962
+
963
+ trace_npcm7xx_emc_reg_write(emc->emc_num, emc_reg_name(reg), reg, value);
964
+
965
+ switch (reg) {
966
+ case REG_CAMCMR:
967
+ emc->regs[reg] = value;
968
+ break;
969
+ case REG_CAMEN:
970
+ /* Only CAM0 is supported, don't pretend otherwise. */
971
+ if (value & ~1) {
972
+ qemu_log_mask(LOG_GUEST_ERROR,
973
+ "%s: Only CAM0 is supported, cannot enable others"
974
+ ": 0x%x\n",
975
+ __func__, value);
976
+ }
977
+ emc->regs[reg] = value & 1;
978
+ break;
979
+ case REG_CAMM_BASE + 0:
980
+ emc->regs[reg] = value;
981
+ emc->conf.macaddr.a[0] = value >> 24;
982
+ emc->conf.macaddr.a[1] = value >> 16;
983
+ emc->conf.macaddr.a[2] = value >> 8;
984
+ emc->conf.macaddr.a[3] = value >> 0;
985
+ break;
986
+ case REG_CAML_BASE + 0:
987
+ emc->regs[reg] = value;
988
+ emc->conf.macaddr.a[4] = value >> 24;
989
+ emc->conf.macaddr.a[5] = value >> 16;
990
+ break;
991
+ case REG_MCMDR: {
992
+ uint32_t prev;
993
+ if (value & REG_MCMDR_SWR) {
994
+ emc_soft_reset(emc);
995
+ /* On h/w the reset happens over multiple cycles. For now KISS. */
996
+ break;
997
+ }
998
+ prev = emc->regs[reg];
999
+ emc->regs[reg] = value;
1000
+ /* Update tx state. */
1001
+ if (!(prev & REG_MCMDR_TXON) &&
1002
+ (value & REG_MCMDR_TXON)) {
1003
+ emc->regs[REG_CTXDSA] = emc->regs[REG_TXDLSA];
1004
+ /*
1005
+ * Linux kernel turns TX on with CPU still holding descriptor,
1006
+ * which suggests we should wait for a write to TSDR before trying
1007
+ * to send a packet: so we don't send one here.
1008
+ */
1009
+ } else if ((prev & REG_MCMDR_TXON) &&
1010
+ !(value & REG_MCMDR_TXON)) {
1011
+ emc->regs[REG_MGSTA] |= REG_MGSTA_TXHA;
1012
+ }
1013
+ if (!(value & REG_MCMDR_TXON)) {
1014
+ emc_halt_tx(emc, 0);
1015
+ }
1016
+ /* Update rx state. */
1017
+ if (!(prev & REG_MCMDR_RXON) &&
1018
+ (value & REG_MCMDR_RXON)) {
1019
+ emc->regs[REG_CRXDSA] = emc->regs[REG_RXDLSA];
1020
+ } else if ((prev & REG_MCMDR_RXON) &&
1021
+ !(value & REG_MCMDR_RXON)) {
1022
+ emc->regs[REG_MGSTA] |= REG_MGSTA_RXHA;
1023
+ }
1024
+ if (!(value & REG_MCMDR_RXON)) {
1025
+ emc_halt_rx(emc, 0);
1026
+ }
1027
+ break;
1028
+ }
1029
+ case REG_TXDLSA:
1030
+ case REG_RXDLSA:
1031
+ case REG_DMARFC:
1032
+ case REG_MIID:
1033
+ emc->regs[reg] = value;
1034
+ break;
1035
+ case REG_MIEN:
1036
+ emc->regs[reg] = value;
1037
+ emc_update_irq_from_reg_change(emc);
1038
+ break;
1039
+ case REG_MISTA:
1040
+ /* Clear the bits that have 1 in "value". */
1041
+ emc->regs[reg] &= ~value;
1042
+ emc_update_irq_from_reg_change(emc);
1043
+ break;
1044
+ case REG_MGSTA:
1045
+ /* Clear the bits that have 1 in "value". */
1046
+ emc->regs[reg] &= ~value;
1047
+ break;
1048
+ case REG_TSDR:
1049
+ if (emc->regs[REG_MCMDR] & REG_MCMDR_TXON) {
1050
+ emc->tx_active = true;
1051
+ /* Keep trying to send packets until we run out. */
1052
+ while (emc->tx_active) {
1053
+ emc_try_send_next_packet(emc);
1054
+ }
1055
+ }
1056
+ break;
1057
+ case REG_RSDR:
1058
+ if (emc->regs[REG_MCMDR] & REG_MCMDR_RXON) {
1059
+ emc->rx_active = true;
1060
+ emc_try_receive_next_packet(emc);
1061
+ }
1062
+ break;
1063
+ case REG_MIIDA:
1064
+ emc->regs[reg] = value & ~REG_MIIDA_BUSY;
1065
+ break;
1066
+ case REG_MRPC:
1067
+ case REG_MRPCC:
1068
+ case REG_MREPC:
1069
+ case REG_CTXDSA:
1070
+ case REG_CTXBSA:
1071
+ case REG_CRXDSA:
1072
+ case REG_CRXBSA:
1073
+ qemu_log_mask(LOG_GUEST_ERROR,
1074
+ "%s: Write to read-only reg %s/%d\n",
1075
+ __func__, emc_reg_name(reg), reg);
1076
+ break;
1077
+ default:
1078
+ qemu_log_mask(LOG_UNIMP, "%s: Write to unimplemented reg %s/%d\n",
1079
+ __func__, emc_reg_name(reg), reg);
1080
+ break;
1081
+ }
1082
+}
1083
+
1084
+static const struct MemoryRegionOps npcm7xx_emc_ops = {
1085
+ .read = npcm7xx_emc_read,
1086
+ .write = npcm7xx_emc_write,
1087
+ .endianness = DEVICE_LITTLE_ENDIAN,
1088
+ .valid = {
1089
+ .min_access_size = 4,
1090
+ .max_access_size = 4,
1091
+ .unaligned = false,
1092
+ },
133
+};
1093
+};
134
+
1094
+
135
+static uint64_t armsse_cpuid_read(void *opaque, hwaddr offset,
1095
+static void emc_cleanup(NetClientState *nc)
136
+ unsigned size)
1096
+{
137
+{
1097
+ /* Nothing to do yet. */
138
+ ARMSSECPUID *s = ARMSSE_CPUID(opaque);
1098
+}
139
+ uint64_t r;
1099
+
140
+
1100
+static NetClientInfo net_npcm7xx_emc_info = {
141
+ switch (offset) {
1101
+ .type = NET_CLIENT_DRIVER_NIC,
142
+ case A_CPUID:
1102
+ .size = sizeof(NICState),
143
+ r = s->cpuid;
1103
+ .can_receive = emc_can_receive,
144
+ break;
1104
+ .receive = emc_receive,
145
+ case A_PID4 ... A_CID3:
1105
+ .cleanup = emc_cleanup,
146
+ r = sysinfo_id[(offset - A_PID4) / 4];
1106
+ .link_status_changed = emc_set_link,
147
+ break;
148
+ default:
149
+ qemu_log_mask(LOG_GUEST_ERROR,
150
+ "SSE CPU_IDENTITY read: bad offset 0x%x\n", (int)offset);
151
+ r = 0;
152
+ break;
153
+ }
154
+ trace_armsse_cpuid_read(offset, r, size);
155
+ return r;
156
+}
157
+
158
+static void armsse_cpuid_write(void *opaque, hwaddr offset,
159
+ uint64_t value, unsigned size)
160
+{
161
+ trace_armsse_cpuid_write(offset, value, size);
162
+
163
+ qemu_log_mask(LOG_GUEST_ERROR,
164
+ "SSE CPU_IDENTITY: write to RO offset 0x%x\n", (int)offset);
165
+}
166
+
167
+static const MemoryRegionOps armsse_cpuid_ops = {
168
+ .read = armsse_cpuid_read,
169
+ .write = armsse_cpuid_write,
170
+ .endianness = DEVICE_LITTLE_ENDIAN,
171
+ /* byte/halfword accesses are just zero-padded on reads and writes */
172
+ .impl.min_access_size = 4,
173
+ .impl.max_access_size = 4,
174
+ .valid.min_access_size = 1,
175
+ .valid.max_access_size = 4,
176
+};
1107
+};
177
+
1108
+
178
+static Property armsse_cpuid_props[] = {
1109
+static void npcm7xx_emc_realize(DeviceState *dev, Error **errp)
179
+ DEFINE_PROP_UINT32("CPUID", ARMSSECPUID, cpuid, 0),
1110
+{
180
+ DEFINE_PROP_END_OF_LIST()
1111
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(dev);
1112
+ SysBusDevice *sbd = SYS_BUS_DEVICE(emc);
1113
+
1114
+ memory_region_init_io(&emc->iomem, OBJECT(emc), &npcm7xx_emc_ops, emc,
1115
+ TYPE_NPCM7XX_EMC, 4 * KiB);
1116
+ sysbus_init_mmio(sbd, &emc->iomem);
1117
+ sysbus_init_irq(sbd, &emc->tx_irq);
1118
+ sysbus_init_irq(sbd, &emc->rx_irq);
1119
+
1120
+ qemu_macaddr_default_if_unset(&emc->conf.macaddr);
1121
+ emc->nic = qemu_new_nic(&net_npcm7xx_emc_info, &emc->conf,
1122
+ object_get_typename(OBJECT(dev)), dev->id, emc);
1123
+ qemu_format_nic_info_str(qemu_get_queue(emc->nic), emc->conf.macaddr.a);
1124
+}
1125
+
1126
+static void npcm7xx_emc_unrealize(DeviceState *dev)
1127
+{
1128
+ NPCM7xxEMCState *emc = NPCM7XX_EMC(dev);
1129
+
1130
+ qemu_del_nic(emc->nic);
1131
+}
1132
+
1133
+static const VMStateDescription vmstate_npcm7xx_emc = {
1134
+ .name = TYPE_NPCM7XX_EMC,
1135
+ .version_id = 0,
1136
+ .minimum_version_id = 0,
1137
+ .fields = (VMStateField[]) {
1138
+ VMSTATE_UINT8(emc_num, NPCM7xxEMCState),
1139
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxEMCState, NPCM7XX_NUM_EMC_REGS),
1140
+ VMSTATE_BOOL(tx_active, NPCM7xxEMCState),
1141
+ VMSTATE_BOOL(rx_active, NPCM7xxEMCState),
1142
+ VMSTATE_END_OF_LIST(),
1143
+ },
181
+};
1144
+};
182
+
1145
+
183
+static void armsse_cpuid_init(Object *obj)
1146
+static Property npcm7xx_emc_properties[] = {
184
+{
1147
+ DEFINE_NIC_PROPERTIES(NPCM7xxEMCState, conf),
185
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
1148
+ DEFINE_PROP_END_OF_LIST(),
186
+ ARMSSECPUID *s = ARMSSE_CPUID(obj);
1149
+};
187
+
1150
+
188
+ memory_region_init_io(&s->iomem, obj, &armsse_cpuid_ops,
1151
+static void npcm7xx_emc_class_init(ObjectClass *klass, void *data)
189
+ s, "armsse-cpuid", 0x1000);
190
+ sysbus_init_mmio(sbd, &s->iomem);
191
+}
192
+
193
+static void armsse_cpuid_class_init(ObjectClass *klass, void *data)
194
+{
1152
+{
195
+ DeviceClass *dc = DEVICE_CLASS(klass);
1153
+ DeviceClass *dc = DEVICE_CLASS(klass);
196
+
1154
+
197
+ /*
1155
+ set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
198
+ * This device has no guest-modifiable state and so it
1156
+ dc->desc = "NPCM7xx EMC Controller";
199
+ * does not need a reset function or VMState.
1157
+ dc->realize = npcm7xx_emc_realize;
200
+ */
1158
+ dc->unrealize = npcm7xx_emc_unrealize;
201
+
1159
+ dc->reset = npcm7xx_emc_reset;
202
+ dc->props = armsse_cpuid_props;
1160
+ dc->vmsd = &vmstate_npcm7xx_emc;
203
+}
1161
+ device_class_set_props(dc, npcm7xx_emc_properties);
204
+
1162
+}
205
+static const TypeInfo armsse_cpuid_info = {
1163
+
206
+ .name = TYPE_ARMSSE_CPUID,
1164
+static const TypeInfo npcm7xx_emc_info = {
1165
+ .name = TYPE_NPCM7XX_EMC,
207
+ .parent = TYPE_SYS_BUS_DEVICE,
1166
+ .parent = TYPE_SYS_BUS_DEVICE,
208
+ .instance_size = sizeof(ARMSSECPUID),
1167
+ .instance_size = sizeof(NPCM7xxEMCState),
209
+ .instance_init = armsse_cpuid_init,
1168
+ .class_init = npcm7xx_emc_class_init,
210
+ .class_init = armsse_cpuid_class_init,
211
+};
1169
+};
212
+
1170
+
213
+static void armsse_cpuid_register_types(void)
1171
+static void npcm7xx_emc_register_type(void)
214
+{
1172
+{
215
+ type_register_static(&armsse_cpuid_info);
1173
+ type_register_static(&npcm7xx_emc_info);
216
+}
1174
+}
217
+
1175
+
218
+type_init(armsse_cpuid_register_types);
1176
+type_init(npcm7xx_emc_register_type)
219
diff --git a/MAINTAINERS b/MAINTAINERS
1177
diff --git a/hw/net/meson.build b/hw/net/meson.build
220
index XXXXXXX..XXXXXXX 100644
1178
index XXXXXXX..XXXXXXX 100644
221
--- a/MAINTAINERS
1179
--- a/hw/net/meson.build
222
+++ b/MAINTAINERS
1180
+++ b/hw/net/meson.build
223
@@ -XXX,XX +XXX,XX @@ F: hw/misc/iotkit-sysctl.c
1181
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_I82596_COMMON', if_true: files('i82596.c'))
224
F: include/hw/misc/iotkit-sysctl.h
1182
softmmu_ss.add(when: 'CONFIG_SUNHME', if_true: files('sunhme.c'))
225
F: hw/misc/iotkit-sysinfo.c
1183
softmmu_ss.add(when: 'CONFIG_FTGMAC100', if_true: files('ftgmac100.c'))
226
F: include/hw/misc/iotkit-sysinfo.h
1184
softmmu_ss.add(when: 'CONFIG_SUNGEM', if_true: files('sungem.c'))
227
+F: hw/misc/armsse-cpuid.c
1185
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_emc.c'))
228
+F: include/hw/misc/armsse-cpuid.h
1186
229
1187
softmmu_ss.add(when: 'CONFIG_ETRAXFS', if_true: files('etraxfs_eth.c'))
230
Musicpal
1188
softmmu_ss.add(when: 'CONFIG_COLDFIRE', if_true: files('mcf_fec.c'))
231
M: Jan Kiszka <jan.kiszka@web.de>
1189
diff --git a/hw/net/trace-events b/hw/net/trace-events
232
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
233
index XXXXXXX..XXXXXXX 100644
1190
index XXXXXXX..XXXXXXX 100644
234
--- a/default-configs/arm-softmmu.mak
1191
--- a/hw/net/trace-events
235
+++ b/default-configs/arm-softmmu.mak
1192
+++ b/hw/net/trace-events
236
@@ -XXX,XX +XXX,XX @@ CONFIG_ARMSSE=y
1193
@@ -XXX,XX +XXX,XX @@ imx_fec_receive_last(int last) "rx frame flags 0x%04x"
237
CONFIG_IOTKIT_SECCTL=y
1194
imx_enet_receive(size_t size) "len %zu"
238
CONFIG_IOTKIT_SYSCTL=y
1195
imx_enet_receive_len(uint64_t addr, int len) "rx_bd 0x%"PRIx64" length %d"
239
CONFIG_IOTKIT_SYSINFO=y
1196
imx_enet_receive_last(int last) "rx frame flags 0x%04x"
240
+CONFIG_ARMSSE_CPUID=y
1197
+
241
1198
+# npcm7xx_emc.c
242
CONFIG_VERSATILE=y
1199
+npcm7xx_emc_reset(int emc_num) "Resetting emc%d"
243
CONFIG_VERSATILE_PCI=y
1200
+npcm7xx_emc_update_tx_irq(int level) "Setting tx irq to %d"
244
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
1201
+npcm7xx_emc_update_rx_irq(int level) "Setting rx irq to %d"
245
index XXXXXXX..XXXXXXX 100644
1202
+npcm7xx_emc_set_mista(uint32_t flags) "ORing 0x%x into MISTA"
246
--- a/hw/misc/trace-events
1203
+npcm7xx_emc_cpu_owned_desc(uint32_t addr) "Can't process cpu-owned descriptor @0x%x"
247
+++ b/hw/misc/trace-events
1204
+npcm7xx_emc_sent_packet(uint32_t len) "Sent %u byte packet"
248
@@ -XXX,XX +XXX,XX @@ iotkit_sysinfo_write(uint64_t offset, uint64_t data, unsigned size) "IoTKit SysI
1205
+npcm7xx_emc_tx_done(uint32_t ctxdsa) "TX done, CTXDSA=0x%x"
249
iotkit_sysctl_read(uint64_t offset, uint64_t data, unsigned size) "IoTKit SysCtl read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
1206
+npcm7xx_emc_can_receive(int can_receive) "Can receive: %d"
250
iotkit_sysctl_write(uint64_t offset, uint64_t data, unsigned size) "IoTKit SysCtl write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
1207
+npcm7xx_emc_packet_filtered_out(const char* fail_reason) "Packet filtered out: %s"
251
iotkit_sysctl_reset(void) "IoTKit SysCtl: reset"
1208
+npcm7xx_emc_packet_dropped(uint32_t len) "%u byte packet dropped"
252
+
1209
+npcm7xx_emc_receiving_packet(uint32_t len) "Receiving %u byte packet"
253
+# hw/misc/armsse-cpuid.c
1210
+npcm7xx_emc_received_packet(uint32_t len) "Received %u byte packet"
254
+armsse_cpuid_read(uint64_t offset, uint64_t data, unsigned size) "SSE-200 CPU_IDENTITY read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
1211
+npcm7xx_emc_rx_done(uint32_t crxdsa) "RX done, CRXDSA=0x%x"
255
+armsse_cpuid_write(uint64_t offset, uint64_t data, unsigned size) "SSE-200 CPU_IDENTITY write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
1212
+npcm7xx_emc_reg_read(int emc_num, uint32_t result, const char *name, int regno) "emc%d: 0x%x = reg[%s/%d]"
1213
+npcm7xx_emc_reg_write(int emc_num, const char *name, int regno, uint32_t value) "emc%d: reg[%s/%d] = 0x%x"
256
--
1214
--
257
2.20.1
1215
2.20.1
258
1216
259
1217
diff view generated by jsdifflib
1
The SSE-200 has two Cortex-M33 CPUs. These see the same view
1
From: Doug Evans <dje@google.com>
2
of memory, with the exception of the "private CPU region" which
3
has per-CPU devices. Internal device interrupts for SSE-200
4
devices are mostly wired up to both CPUs, with the exception of
5
a few per-CPU devices. External GPIO inputs on the SSE-200
6
device are provided for the second CPU's interrupts above 32,
7
as is already the case for the first CPU.
8
2
9
Refactor the code to support creation of multiple CPUs.
3
This is a 10/100 ethernet device that has several features.
10
For the moment we leave all CPUs with the same view of
4
Only the ones needed by the Linux driver have been implemented.
11
memory: this will not work in the multiple-CPU case, but
5
See npcm7xx_emc.c for a list of unimplemented features.
12
we will fix this in the following commit.
13
6
7
Reviewed-by: Hao Wu <wuhaotsh@google.com>
8
Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Doug Evans <dje@google.com>
11
Message-id: 20210213002520.1374134-3-dje@google.com
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
16
Message-id: 20190121185118.18550-12-peter.maydell@linaro.org
17
---
13
---
18
include/hw/arm/armsse.h | 21 +++-
14
docs/system/arm/nuvoton.rst | 3 ++-
19
hw/arm/armsse.c | 206 ++++++++++++++++++++++++++++++++--------
15
include/hw/arm/npcm7xx.h | 2 ++
20
2 files changed, 180 insertions(+), 47 deletions(-)
16
hw/arm/npcm7xx.c | 50 +++++++++++++++++++++++++++++++++++--
17
3 files changed, 52 insertions(+), 3 deletions(-)
21
18
22
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
19
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
23
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
24
--- a/include/hw/arm/armsse.h
21
--- a/docs/system/arm/nuvoton.rst
25
+++ b/include/hw/arm/armsse.h
22
+++ b/docs/system/arm/nuvoton.rst
23
@@ -XXX,XX +XXX,XX @@ Supported devices
24
* Analog to Digital Converter (ADC)
25
* Pulse Width Modulation (PWM)
26
* SMBus controller (SMBF)
27
+ * Ethernet controller (EMC)
28
29
Missing devices
30
---------------
31
@@ -XXX,XX +XXX,XX @@ Missing devices
32
* Shared memory (SHM)
33
* eSPI slave interface
34
35
- * Ethernet controllers (GMAC and EMC)
36
+ * Ethernet controller (GMAC)
37
* USB device (USBD)
38
* Peripheral SPI controller (PSPI)
39
* SD/MMC host
40
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
41
index XXXXXXX..XXXXXXX 100644
42
--- a/include/hw/arm/npcm7xx.h
43
+++ b/include/hw/arm/npcm7xx.h
26
@@ -XXX,XX +XXX,XX @@
44
@@ -XXX,XX +XXX,XX @@
27
* + QOM property "memory" is a MemoryRegion containing the devices provided
45
#include "hw/misc/npcm7xx_gcr.h"
28
* by the board model.
46
#include "hw/misc/npcm7xx_pwm.h"
29
* + QOM property "MAINCLK" is the frequency of the main system clock
47
#include "hw/misc/npcm7xx_rng.h"
30
- * + QOM property "EXP_NUMIRQ" sets the number of expansion interrupts
48
+#include "hw/net/npcm7xx_emc.h"
31
- * + Named GPIO inputs "EXP_IRQ" 0..n are the expansion interrupts, which
49
#include "hw/nvram/npcm7xx_otp.h"
32
- * are wired to the NVIC lines 32 .. n+32
50
#include "hw/timer/npcm7xx_timer.h"
33
+ * + QOM property "EXP_NUMIRQ" sets the number of expansion interrupts.
51
#include "hw/ssi/npcm7xx_fiu.h"
34
+ * (In hardware, the SSE-200 permits the number of expansion interrupts
52
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
35
+ * for the two CPUs to be configured separately, but we restrict it to
53
EHCISysBusState ehci;
36
+ * being the same for both, to avoid having to have separate Property
54
OHCISysBusState ohci;
37
+ * lists for different variants. This restriction can be relaxed later
55
NPCM7xxFIUState fiu[2];
38
+ * if necessary.)
56
+ NPCM7xxEMCState emc[2];
39
+ * + Named GPIO inputs "EXP_IRQ" 0..n are the expansion interrupts for CPU 0,
57
} NPCM7xxState;
40
+ * which are wired to its NVIC lines 32 .. n+32
58
41
+ * + Named GPIO inputs "EXP_CPU1_IRQ" 0..n are the expansion interrupts for
59
#define TYPE_NPCM7XX "npcm7xx"
42
+ * CPU 1, which are wired to its NVIC lines 32 .. n+32
60
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
43
* + sysbus MMIO region 0 is the "AHB Slave Expansion" which allows
44
* bus master devices in the board model to make transactions into
45
* all the devices and memory areas in the IoTKit
46
@@ -XXX,XX +XXX,XX @@
47
#error Too many SRAM banks
48
#endif
49
50
+#define SSE_MAX_CPUS 2
51
+
52
typedef struct ARMSSE {
53
/*< private >*/
54
SysBusDevice parent_obj;
55
56
/*< public >*/
57
- ARMv7MState armv7m;
58
+ ARMv7MState armv7m[SSE_MAX_CPUS];
59
IoTKitSecCtl secctl;
60
TZPPC apb_ppc0;
61
TZPPC apb_ppc1;
62
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
63
qemu_or_irq mpc_irq_orgate;
64
qemu_or_irq nmi_orgate;
65
66
+ SplitIRQ cpu_irq_splitter[32];
67
+
68
CMSDKAPBDualTimer dualtimer;
69
70
CMSDKAPBWatchdog s32kwatchdog;
71
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
72
MemoryRegion alias3;
73
MemoryRegion sram[MAX_SRAM_BANKS];
74
75
- qemu_irq *exp_irqs;
76
+ qemu_irq *exp_irqs[SSE_MAX_CPUS];
77
qemu_irq ppc0_irq;
78
qemu_irq ppc1_irq;
79
qemu_irq sec_resp_cfg;
80
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
81
index XXXXXXX..XXXXXXX 100644
61
index XXXXXXX..XXXXXXX 100644
82
--- a/hw/arm/armsse.c
62
--- a/hw/arm/npcm7xx.c
83
+++ b/hw/arm/armsse.c
63
+++ b/hw/arm/npcm7xx.c
84
@@ -XXX,XX +XXX,XX @@
64
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
85
struct ARMSSEInfo {
65
NPCM7XX_UART1_IRQ,
86
const char *name;
66
NPCM7XX_UART2_IRQ,
87
int sram_banks;
67
NPCM7XX_UART3_IRQ,
88
+ int num_cpus;
68
+ NPCM7XX_EMC1RX_IRQ = 15,
69
+ NPCM7XX_EMC1TX_IRQ,
70
NPCM7XX_TIMER0_IRQ = 32, /* Timer Module 0 */
71
NPCM7XX_TIMER1_IRQ,
72
NPCM7XX_TIMER2_IRQ,
73
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
74
NPCM7XX_SMBUS15_IRQ,
75
NPCM7XX_PWM0_IRQ = 93, /* PWM module 0 */
76
NPCM7XX_PWM1_IRQ, /* PWM module 1 */
77
+ NPCM7XX_EMC2RX_IRQ = 114,
78
+ NPCM7XX_EMC2TX_IRQ,
79
NPCM7XX_GPIO0_IRQ = 116,
80
NPCM7XX_GPIO1_IRQ,
81
NPCM7XX_GPIO2_IRQ,
82
@@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_smbus_addr[] = {
83
0xf008f000,
89
};
84
};
90
85
91
static const ARMSSEInfo armsse_variants[] = {
86
+/* Register base address for each EMC Module */
92
{
87
+static const hwaddr npcm7xx_emc_addr[] = {
93
.name = TYPE_IOTKIT,
88
+ 0xf0825000,
94
.sram_banks = 1,
89
+ 0xf0826000,
95
+ .num_cpus = 1,
96
},
97
};
98
99
/* Clock frequency in HZ of the 32KHz "slow clock" */
100
#define S32KCLK (32 * 1000)
101
102
+/* Is internal IRQ n shared between CPUs in a multi-core SSE ? */
103
+static bool irq_is_common[32] = {
104
+ [0 ... 5] = true,
105
+ /* 6, 7: per-CPU MHU interrupts */
106
+ [8 ... 12] = true,
107
+ /* 13: per-CPU icache interrupt */
108
+ /* 14: reserved */
109
+ [15 ... 20] = true,
110
+ /* 21: reserved */
111
+ [22 ... 26] = true,
112
+ /* 27: reserved */
113
+ /* 28, 29: per-CPU CTI interrupts */
114
+ /* 30, 31: reserved */
115
+};
90
+};
116
+
91
+
117
/* Create an alias region of @size bytes starting at @base
92
static const struct {
118
* which mirrors the memory starting at @orig.
93
hwaddr regs_addr;
119
*/
94
uint32_t unconnected_pins;
120
@@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj)
95
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
121
int i;
96
for (i = 0; i < ARRAY_SIZE(s->pwm); i++) {
122
97
object_initialize_child(obj, "pwm[*]", &s->pwm[i], TYPE_NPCM7XX_PWM);
123
assert(info->sram_banks <= MAX_SRAM_BANKS);
124
+ assert(info->num_cpus <= SSE_MAX_CPUS);
125
126
memory_region_init(&s->container, obj, "armsse-container", UINT64_MAX);
127
128
- sysbus_init_child_obj(obj, "armv7m", &s->armv7m, sizeof(s->armv7m),
129
- TYPE_ARMV7M);
130
- qdev_prop_set_string(DEVICE(&s->armv7m), "cpu-type",
131
- ARM_CPU_TYPE_NAME("cortex-m33"));
132
+ for (i = 0; i < info->num_cpus; i++) {
133
+ char *name = g_strdup_printf("armv7m%d", i);
134
+ sysbus_init_child_obj(obj, name, &s->armv7m[i], sizeof(s->armv7m),
135
+ TYPE_ARMV7M);
136
+ qdev_prop_set_string(DEVICE(&s->armv7m[i]), "cpu-type",
137
+ ARM_CPU_TYPE_NAME("cortex-m33"));
138
+ g_free(name);
139
+ }
140
141
sysbus_init_child_obj(obj, "secctl", &s->secctl, sizeof(s->secctl),
142
TYPE_IOTKIT_SECCTL);
143
@@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj)
144
TYPE_SPLIT_IRQ, &error_abort, NULL);
145
g_free(name);
146
}
98
}
147
+ if (info->num_cpus > 1) {
148
+ for (i = 0; i < ARRAY_SIZE(s->cpu_irq_splitter); i++) {
149
+ if (irq_is_common[i]) {
150
+ char *name = g_strdup_printf("cpu-irq-splitter%d", i);
151
+ SplitIRQ *splitter = &s->cpu_irq_splitter[i];
152
+
99
+
153
+ object_initialize_child(obj, name, splitter, sizeof(*splitter),
100
+ for (i = 0; i < ARRAY_SIZE(s->emc); i++) {
154
+ TYPE_SPLIT_IRQ, &error_abort, NULL);
101
+ object_initialize_child(obj, "emc[*]", &s->emc[i], TYPE_NPCM7XX_EMC);
155
+ g_free(name);
156
+ }
157
+ }
158
+ }
102
+ }
159
}
103
}
160
104
161
static void armsse_exp_irq(void *opaque, int n, int level)
105
static void npcm7xx_realize(DeviceState *dev, Error **errp)
162
{
106
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
163
- ARMSSE *s = ARMSSE(opaque);
107
sysbus_connect_irq(sbd, i, npcm7xx_irq(s, NPCM7XX_PWM0_IRQ + i));
164
+ qemu_irq *irqarray = opaque;
108
}
165
109
166
- qemu_set_irq(s->exp_irqs[n], level);
167
+ qemu_set_irq(irqarray[n], level);
168
}
169
170
static void armsse_mpcexp_status(void *opaque, int n, int level)
171
@@ -XXX,XX +XXX,XX @@ static void armsse_mpcexp_status(void *opaque, int n, int level)
172
qemu_set_irq(s->mpcexp_status_in[n], level);
173
}
174
175
+static qemu_irq armsse_get_common_irq_in(ARMSSE *s, int irqno)
176
+{
177
+ /*
110
+ /*
178
+ * Return a qemu_irq which can be used to signal IRQ n to
111
+ * EMC Modules. Cannot fail.
179
+ * all CPUs in the SSE.
112
+ * The mapping of the device to its netdev backend works as follows:
113
+ * emc[i] = nd_table[i]
114
+ * This works around the inability to specify the netdev property for the
115
+ * emc device: it's not pluggable and thus the -device option can't be
116
+ * used.
180
+ */
117
+ */
181
+ ARMSSEClass *asc = ARMSSE_GET_CLASS(s);
118
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_emc_addr) != ARRAY_SIZE(s->emc));
182
+ const ARMSSEInfo *info = asc->info;
119
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(s->emc) != 2);
120
+ for (i = 0; i < ARRAY_SIZE(s->emc); i++) {
121
+ s->emc[i].emc_num = i;
122
+ SysBusDevice *sbd = SYS_BUS_DEVICE(&s->emc[i]);
123
+ if (nd_table[i].used) {
124
+ qemu_check_nic_model(&nd_table[i], TYPE_NPCM7XX_EMC);
125
+ qdev_set_nic_properties(DEVICE(sbd), &nd_table[i]);
126
+ }
127
+ /*
128
+ * The device exists regardless of whether it's connected to a QEMU
129
+ * netdev backend. So always instantiate it even if there is no
130
+ * backend.
131
+ */
132
+ sysbus_realize(sbd, &error_abort);
133
+ sysbus_mmio_map(sbd, 0, npcm7xx_emc_addr[i]);
134
+ int tx_irq = i == 0 ? NPCM7XX_EMC1TX_IRQ : NPCM7XX_EMC2TX_IRQ;
135
+ int rx_irq = i == 0 ? NPCM7XX_EMC1RX_IRQ : NPCM7XX_EMC2RX_IRQ;
136
+ /*
137
+ * N.B. The values for the second argument sysbus_connect_irq are
138
+ * chosen to match the registration order in npcm7xx_emc_realize.
139
+ */
140
+ sysbus_connect_irq(sbd, 0, npcm7xx_irq(s, tx_irq));
141
+ sysbus_connect_irq(sbd, 1, npcm7xx_irq(s, rx_irq));
142
+ }
183
+
143
+
184
+ assert(irq_is_common[irqno]);
185
+
186
+ if (info->num_cpus == 1) {
187
+ /* Only one CPU -- just connect directly to it */
188
+ return qdev_get_gpio_in(DEVICE(&s->armv7m[0]), irqno);
189
+ } else {
190
+ /* Connect to the splitter which feeds all CPUs */
191
+ return qdev_get_gpio_in(DEVICE(&s->cpu_irq_splitter[irqno]), 0);
192
+ }
193
+}
194
+
195
static void armsse_realize(DeviceState *dev, Error **errp)
196
{
197
ARMSSE *s = ARMSSE(dev);
198
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
199
200
memory_region_add_subregion_overlap(&s->container, 0, s->board_memory, -1);
201
202
- qdev_prop_set_uint32(DEVICE(&s->armv7m), "num-irq", s->exp_numirq + 32);
203
- /* In real hardware the initial Secure VTOR is set from the INITSVTOR0
204
- * register in the IoT Kit System Control Register block, and the
205
- * initial value of that is in turn specifiable by the FPGA that
206
- * instantiates the IoT Kit. In QEMU we don't implement this wrinkle,
207
- * and simply set the CPU's init-svtor to the IoT Kit default value.
208
- */
209
- qdev_prop_set_uint32(DEVICE(&s->armv7m), "init-svtor", 0x10000000);
210
- object_property_set_link(OBJECT(&s->armv7m), OBJECT(&s->container),
211
- "memory", &err);
212
- if (err) {
213
- error_propagate(errp, err);
214
- return;
215
- }
216
- object_property_set_link(OBJECT(&s->armv7m), OBJECT(s), "idau", &err);
217
- if (err) {
218
- error_propagate(errp, err);
219
- return;
220
- }
221
- object_property_set_bool(OBJECT(&s->armv7m), true, "realized", &err);
222
- if (err) {
223
- error_propagate(errp, err);
224
- return;
225
+ for (i = 0; i < info->num_cpus; i++) {
226
+ DeviceState *cpudev = DEVICE(&s->armv7m[i]);
227
+ Object *cpuobj = OBJECT(&s->armv7m[i]);
228
+ int j;
229
+ char *gpioname;
230
+
231
+ qdev_prop_set_uint32(cpudev, "num-irq", s->exp_numirq + 32);
232
+ /*
233
+ * In real hardware the initial Secure VTOR is set from the INITSVTOR0
234
+ * register in the IoT Kit System Control Register block, and the
235
+ * initial value of that is in turn specifiable by the FPGA that
236
+ * instantiates the IoT Kit. In QEMU we don't implement this wrinkle,
237
+ * and simply set the CPU's init-svtor to the IoT Kit default value.
238
+ * In SSE-200 the situation is similar, except that the default value
239
+ * is a reset-time signal input. Typically a board using the SSE-200
240
+ * will have a system control processor whose boot firmware initializes
241
+ * the INITSVTOR* registers before powering up the CPUs in any case,
242
+ * so the hardware's default value doesn't matter. QEMU doesn't emulate
243
+ * the control processor, so instead we behave in the way that the
244
+ * firmware does. All boards currently known about have firmware that
245
+ * sets the INITSVTOR0 and INITSVTOR1 registers to 0x10000000, like the
246
+ * IoTKit default. We can make this more configurable if necessary.
247
+ */
248
+ qdev_prop_set_uint32(cpudev, "init-svtor", 0x10000000);
249
+ /*
250
+ * Start all CPUs except CPU0 powered down. In real hardware it is
251
+ * a configurable property of the SSE-200 which CPUs start powered up
252
+ * (via the CPUWAIT0_RST and CPUWAIT1_RST parameters), but since all
253
+ * the boards we care about start CPU0 and leave CPU1 powered off,
254
+ * we hard-code that for now. We can add QOM properties for this
255
+ * later if necessary.
256
+ */
257
+ if (i > 0) {
258
+ object_property_set_bool(cpuobj, true, "start-powered-off", &err);
259
+ if (err) {
260
+ error_propagate(errp, err);
261
+ return;
262
+ }
263
+ }
264
+ object_property_set_link(cpuobj, OBJECT(&s->container), "memory", &err);
265
+ if (err) {
266
+ error_propagate(errp, err);
267
+ return;
268
+ }
269
+ object_property_set_link(cpuobj, OBJECT(s), "idau", &err);
270
+ if (err) {
271
+ error_propagate(errp, err);
272
+ return;
273
+ }
274
+ object_property_set_bool(cpuobj, true, "realized", &err);
275
+ if (err) {
276
+ error_propagate(errp, err);
277
+ return;
278
+ }
279
+
280
+ /* Connect EXP_IRQ/EXP_CPUn_IRQ GPIOs to the NVIC's lines 32 and up */
281
+ s->exp_irqs[i] = g_new(qemu_irq, s->exp_numirq);
282
+ for (j = 0; j < s->exp_numirq; j++) {
283
+ s->exp_irqs[i][j] = qdev_get_gpio_in(cpudev, i + 32);
284
+ }
285
+ if (i == 0) {
286
+ gpioname = g_strdup("EXP_IRQ");
287
+ } else {
288
+ gpioname = g_strdup_printf("EXP_CPU%d_IRQ", i);
289
+ }
290
+ qdev_init_gpio_in_named_with_opaque(dev, armsse_exp_irq,
291
+ s->exp_irqs[i],
292
+ gpioname, s->exp_numirq);
293
+ g_free(gpioname);
294
}
295
296
- /* Connect our EXP_IRQ GPIOs to the NVIC's lines 32 and up. */
297
- s->exp_irqs = g_new(qemu_irq, s->exp_numirq);
298
- for (i = 0; i < s->exp_numirq; i++) {
299
- s->exp_irqs[i] = qdev_get_gpio_in(DEVICE(&s->armv7m), i + 32);
300
+ /* Wire up the splitters that connect common IRQs to all CPUs */
301
+ if (info->num_cpus > 1) {
302
+ for (i = 0; i < ARRAY_SIZE(s->cpu_irq_splitter); i++) {
303
+ if (irq_is_common[i]) {
304
+ Object *splitter = OBJECT(&s->cpu_irq_splitter[i]);
305
+ DeviceState *devs = DEVICE(splitter);
306
+ int cpunum;
307
+
308
+ object_property_set_int(splitter, info->num_cpus,
309
+ "num-lines", &err);
310
+ if (err) {
311
+ error_propagate(errp, err);
312
+ return;
313
+ }
314
+ object_property_set_bool(splitter, true, "realized", &err);
315
+ if (err) {
316
+ error_propagate(errp, err);
317
+ return;
318
+ }
319
+ for (cpunum = 0; cpunum < info->num_cpus; cpunum++) {
320
+ DeviceState *cpudev = DEVICE(&s->armv7m[cpunum]);
321
+
322
+ qdev_connect_gpio_out(devs, cpunum,
323
+ qdev_get_gpio_in(cpudev, i));
324
+ }
325
+ }
326
+ }
327
}
328
- qdev_init_gpio_in_named(dev, armsse_exp_irq, "EXP_IRQ", s->exp_numirq);
329
330
/* Set up the big aliases first */
331
make_alias(s, &s->alias1, "alias 1", 0x10000000, 0x10000000, 0x00000000);
332
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
333
return;
334
}
335
qdev_connect_gpio_out(DEVICE(&s->mpc_irq_orgate), 0,
336
- qdev_get_gpio_in(DEVICE(&s->armv7m), 9));
337
+ armsse_get_common_irq_in(s, 9));
338
339
/* Devices behind APB PPC0:
340
* 0x40000000: timer0
341
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
342
return;
343
}
344
sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer0), 0,
345
- qdev_get_gpio_in(DEVICE(&s->armv7m), 3));
346
+ armsse_get_common_irq_in(s, 3));
347
mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->timer0), 0);
348
object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[0]", &err);
349
if (err) {
350
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
351
return;
352
}
353
sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer1), 0,
354
- qdev_get_gpio_in(DEVICE(&s->armv7m), 4));
355
+ armsse_get_common_irq_in(s, 4));
356
mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->timer1), 0);
357
object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[1]", &err);
358
if (err) {
359
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
360
return;
361
}
362
sysbus_connect_irq(SYS_BUS_DEVICE(&s->dualtimer), 0,
363
- qdev_get_gpio_in(DEVICE(&s->armv7m), 5));
364
+ armsse_get_common_irq_in(s, 5));
365
mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->dualtimer), 0);
366
object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[2]", &err);
367
if (err) {
368
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
369
return;
370
}
371
qdev_connect_gpio_out(DEVICE(&s->ppc_irq_orgate), 0,
372
- qdev_get_gpio_in(DEVICE(&s->armv7m), 10));
373
+ armsse_get_common_irq_in(s, 10));
374
375
/* 0x40010000 .. 0x4001ffff: private CPU region: unused in IoTKit */
376
377
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
378
return;
379
}
380
sysbus_connect_irq(SYS_BUS_DEVICE(&s->s32ktimer), 0,
381
- qdev_get_gpio_in(DEVICE(&s->armv7m), 2));
382
+ armsse_get_common_irq_in(s, 2));
383
mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->s32ktimer), 0);
384
object_property_set_link(OBJECT(&s->apb_ppc1), OBJECT(mr), "port[0]", &err);
385
if (err) {
386
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
387
return;
388
}
389
sysbus_connect_irq(SYS_BUS_DEVICE(&s->nswatchdog), 0,
390
- qdev_get_gpio_in(DEVICE(&s->armv7m), 1));
391
+ armsse_get_common_irq_in(s, 1));
392
sysbus_mmio_map(SYS_BUS_DEVICE(&s->nswatchdog), 0, 0x40081000);
393
394
qdev_prop_set_uint32(DEVICE(&s->swatchdog), "wdogclk-frq", s->mainclk_frq);
395
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
396
qdev_pass_gpios(dev_secctl, dev, "mscexp_clear");
397
qdev_pass_gpios(dev_secctl, dev, "mscexp_ns");
398
qdev_connect_gpio_out_named(dev_secctl, "msc_irq", 0,
399
- qdev_get_gpio_in(DEVICE(&s->armv7m), 11));
400
+ armsse_get_common_irq_in(s, 11));
401
402
/*
144
/*
403
* Expose our container region to the board model; this corresponds
145
* Flash Interface Unit (FIU). Can fail if incorrect number of chip selects
146
* specified, but this is a programming error.
147
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
148
create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB);
149
create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB);
150
create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB);
151
- create_unimplemented_device("npcm7xx.emc1", 0xf0825000, 4 * KiB);
152
- create_unimplemented_device("npcm7xx.emc2", 0xf0826000, 4 * KiB);
153
create_unimplemented_device("npcm7xx.usbd[0]", 0xf0830000, 4 * KiB);
154
create_unimplemented_device("npcm7xx.usbd[1]", 0xf0831000, 4 * KiB);
155
create_unimplemented_device("npcm7xx.usbd[2]", 0xf0832000, 4 * KiB);
404
--
156
--
405
2.20.1
157
2.20.1
406
158
407
159
diff view generated by jsdifflib
1
From: kumar sourav <sourav.jb1988@gmail.com>
1
From: Doug Evans <dje@google.com>
2
2
3
set object owner in memory_region_init_ram() instead
3
Reviewed-by: Hao Wu <wuhaotsh@google.com>
4
of NULL.
4
Reviewed-by: Avi Fishman <avi.fishman@nuvoton.com>
5
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: kumar sourav <sourav.jb1988@gmail.com>
6
Signed-off-by: Doug Evans <dje@google.com>
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
7
Message-id: 20210213002520.1374134-4-dje@google.com
8
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
9
Message-id: 20190125155630.17430-1-sourav.jb1988@gmail.com
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
9
---
12
hw/arm/nrf51_soc.c | 3 ++-
10
tests/qtest/npcm7xx_emc-test.c | 862 +++++++++++++++++++++++++++++++++
13
1 file changed, 2 insertions(+), 1 deletion(-)
11
tests/qtest/meson.build | 1 +
12
2 files changed, 863 insertions(+)
13
create mode 100644 tests/qtest/npcm7xx_emc-test.c
14
14
15
diff --git a/hw/arm/nrf51_soc.c b/hw/arm/nrf51_soc.c
15
diff --git a/tests/qtest/npcm7xx_emc-test.c b/tests/qtest/npcm7xx_emc-test.c
16
new file mode 100644
17
index XXXXXXX..XXXXXXX
18
--- /dev/null
19
+++ b/tests/qtest/npcm7xx_emc-test.c
20
@@ -XXX,XX +XXX,XX @@
21
+/*
22
+ * QTests for Nuvoton NPCM7xx EMC Modules.
23
+ *
24
+ * Copyright 2020 Google LLC
25
+ *
26
+ * This program is free software; you can redistribute it and/or modify it
27
+ * under the terms of the GNU General Public License as published by the
28
+ * Free Software Foundation; either version 2 of the License, or
29
+ * (at your option) any later version.
30
+ *
31
+ * This program is distributed in the hope that it will be useful, but WITHOUT
32
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
34
+ * for more details.
35
+ */
36
+
37
+#include "qemu/osdep.h"
38
+#include "qemu-common.h"
39
+#include "libqos/libqos.h"
40
+#include "qapi/qmp/qdict.h"
41
+#include "qapi/qmp/qnum.h"
42
+#include "qemu/bitops.h"
43
+#include "qemu/iov.h"
44
+
45
+/* Name of the emc device. */
46
+#define TYPE_NPCM7XX_EMC "npcm7xx-emc"
47
+
48
+/* Timeout for various operations, in seconds. */
49
+#define TIMEOUT_SECONDS 10
50
+
51
+/* Address in memory of the descriptor. */
52
+#define DESC_ADDR (1 << 20) /* 1 MiB */
53
+
54
+/* Address in memory of the data packet. */
55
+#define DATA_ADDR (DESC_ADDR + 4096)
56
+
57
+#define CRC_LENGTH 4
58
+
59
+#define NUM_TX_DESCRIPTORS 3
60
+#define NUM_RX_DESCRIPTORS 2
61
+
62
+/* Size of tx,rx test buffers. */
63
+#define TX_DATA_LEN 64
64
+#define RX_DATA_LEN 64
65
+
66
+#define TX_STEP_COUNT 10000
67
+#define RX_STEP_COUNT 10000
68
+
69
+/* 32-bit register indices. */
70
+typedef enum NPCM7xxPWMRegister {
71
+ /* Control registers. */
72
+ REG_CAMCMR,
73
+ REG_CAMEN,
74
+
75
+ /* There are 16 CAMn[ML] registers. */
76
+ REG_CAMM_BASE,
77
+ REG_CAML_BASE,
78
+
79
+ REG_TXDLSA = 0x22,
80
+ REG_RXDLSA,
81
+ REG_MCMDR,
82
+ REG_MIID,
83
+ REG_MIIDA,
84
+ REG_FFTCR,
85
+ REG_TSDR,
86
+ REG_RSDR,
87
+ REG_DMARFC,
88
+ REG_MIEN,
89
+
90
+ /* Status registers. */
91
+ REG_MISTA,
92
+ REG_MGSTA,
93
+ REG_MPCNT,
94
+ REG_MRPC,
95
+ REG_MRPCC,
96
+ REG_MREPC,
97
+ REG_DMARFS,
98
+ REG_CTXDSA,
99
+ REG_CTXBSA,
100
+ REG_CRXDSA,
101
+ REG_CRXBSA,
102
+
103
+ NPCM7XX_NUM_EMC_REGS,
104
+} NPCM7xxPWMRegister;
105
+
106
+enum { NUM_CAMML_REGS = 16 };
107
+
108
+/* REG_CAMCMR fields */
109
+/* Enable CAM Compare */
110
+#define REG_CAMCMR_ECMP (1 << 4)
111
+/* Accept Unicast Packet */
112
+#define REG_CAMCMR_AUP (1 << 0)
113
+
114
+/* REG_MCMDR fields */
115
+/* Software Reset */
116
+#define REG_MCMDR_SWR (1 << 24)
117
+/* Frame Transmission On */
118
+#define REG_MCMDR_TXON (1 << 8)
119
+/* Accept Long Packet */
120
+#define REG_MCMDR_ALP (1 << 1)
121
+/* Frame Reception On */
122
+#define REG_MCMDR_RXON (1 << 0)
123
+
124
+/* REG_MIEN fields */
125
+/* Enable Transmit Completion Interrupt */
126
+#define REG_MIEN_ENTXCP (1 << 18)
127
+/* Enable Transmit Interrupt */
128
+#define REG_MIEN_ENTXINTR (1 << 16)
129
+/* Enable Receive Good Interrupt */
130
+#define REG_MIEN_ENRXGD (1 << 4)
131
+/* ENable Receive Interrupt */
132
+#define REG_MIEN_ENRXINTR (1 << 0)
133
+
134
+/* REG_MISTA fields */
135
+/* Transmit Bus Error Interrupt */
136
+#define REG_MISTA_TXBERR (1 << 24)
137
+/* Transmit Descriptor Unavailable Interrupt */
138
+#define REG_MISTA_TDU (1 << 23)
139
+/* Transmit Completion Interrupt */
140
+#define REG_MISTA_TXCP (1 << 18)
141
+/* Transmit Interrupt */
142
+#define REG_MISTA_TXINTR (1 << 16)
143
+/* Receive Bus Error Interrupt */
144
+#define REG_MISTA_RXBERR (1 << 11)
145
+/* Receive Descriptor Unavailable Interrupt */
146
+#define REG_MISTA_RDU (1 << 10)
147
+/* DMA Early Notification Interrupt */
148
+#define REG_MISTA_DENI (1 << 9)
149
+/* Maximum Frame Length Interrupt */
150
+#define REG_MISTA_DFOI (1 << 8)
151
+/* Receive Good Interrupt */
152
+#define REG_MISTA_RXGD (1 << 4)
153
+/* Packet Too Long Interrupt */
154
+#define REG_MISTA_PTLE (1 << 3)
155
+/* Receive Interrupt */
156
+#define REG_MISTA_RXINTR (1 << 0)
157
+
158
+typedef struct NPCM7xxEMCTxDesc NPCM7xxEMCTxDesc;
159
+typedef struct NPCM7xxEMCRxDesc NPCM7xxEMCRxDesc;
160
+
161
+struct NPCM7xxEMCTxDesc {
162
+ uint32_t flags;
163
+ uint32_t txbsa;
164
+ uint32_t status_and_length;
165
+ uint32_t ntxdsa;
166
+};
167
+
168
+struct NPCM7xxEMCRxDesc {
169
+ uint32_t status_and_length;
170
+ uint32_t rxbsa;
171
+ uint32_t reserved;
172
+ uint32_t nrxdsa;
173
+};
174
+
175
+/* NPCM7xxEMCTxDesc.flags values */
176
+/* Owner: 0 = cpu, 1 = emc */
177
+#define TX_DESC_FLAG_OWNER_MASK (1 << 31)
178
+/* Transmit interrupt enable */
179
+#define TX_DESC_FLAG_INTEN (1 << 2)
180
+
181
+/* NPCM7xxEMCTxDesc.status_and_length values */
182
+/* Transmission complete */
183
+#define TX_DESC_STATUS_TXCP (1 << 19)
184
+/* Transmit interrupt */
185
+#define TX_DESC_STATUS_TXINTR (1 << 16)
186
+
187
+/* NPCM7xxEMCRxDesc.status_and_length values */
188
+/* Owner: 0b00 = cpu, 0b10 = emc */
189
+#define RX_DESC_STATUS_OWNER_SHIFT 30
190
+#define RX_DESC_STATUS_OWNER_MASK 0xc0000000
191
+/* Frame Reception Complete */
192
+#define RX_DESC_STATUS_RXGD (1 << 20)
193
+/* Packet too long */
194
+#define RX_DESC_STATUS_PTLE (1 << 19)
195
+/* Receive Interrupt */
196
+#define RX_DESC_STATUS_RXINTR (1 << 16)
197
+
198
+#define RX_DESC_PKT_LEN(word) ((uint32_t) (word) & 0xffff)
199
+
200
+typedef struct EMCModule {
201
+ int rx_irq;
202
+ int tx_irq;
203
+ uint64_t base_addr;
204
+} EMCModule;
205
+
206
+typedef struct TestData {
207
+ const EMCModule *module;
208
+} TestData;
209
+
210
+static const EMCModule emc_module_list[] = {
211
+ {
212
+ .rx_irq = 15,
213
+ .tx_irq = 16,
214
+ .base_addr = 0xf0825000
215
+ },
216
+ {
217
+ .rx_irq = 114,
218
+ .tx_irq = 115,
219
+ .base_addr = 0xf0826000
220
+ }
221
+};
222
+
223
+/* Returns the index of the EMC module. */
224
+static int emc_module_index(const EMCModule *mod)
225
+{
226
+ ptrdiff_t diff = mod - emc_module_list;
227
+
228
+ g_assert_true(diff >= 0 && diff < ARRAY_SIZE(emc_module_list));
229
+
230
+ return diff;
231
+}
232
+
233
+static void packet_test_clear(void *sockets)
234
+{
235
+ int *test_sockets = sockets;
236
+
237
+ close(test_sockets[0]);
238
+ g_free(test_sockets);
239
+}
240
+
241
+static int *packet_test_init(int module_num, GString *cmd_line)
242
+{
243
+ int *test_sockets = g_new(int, 2);
244
+ int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, test_sockets);
245
+ g_assert_cmpint(ret, != , -1);
246
+
247
+ /*
248
+ * KISS and use -nic. We specify two nics (both emc{0,1}) because there's
249
+ * currently no way to specify only emc1: The driver implicitly relies on
250
+ * emc[i] == nd_table[i].
251
+ */
252
+ if (module_num == 0) {
253
+ g_string_append_printf(cmd_line,
254
+ " -nic socket,fd=%d,model=" TYPE_NPCM7XX_EMC " "
255
+ " -nic user,model=" TYPE_NPCM7XX_EMC " ",
256
+ test_sockets[1]);
257
+ } else {
258
+ g_string_append_printf(cmd_line,
259
+ " -nic user,model=" TYPE_NPCM7XX_EMC " "
260
+ " -nic socket,fd=%d,model=" TYPE_NPCM7XX_EMC " ",
261
+ test_sockets[1]);
262
+ }
263
+
264
+ g_test_queue_destroy(packet_test_clear, test_sockets);
265
+ return test_sockets;
266
+}
267
+
268
+static uint32_t emc_read(QTestState *qts, const EMCModule *mod,
269
+ NPCM7xxPWMRegister regno)
270
+{
271
+ return qtest_readl(qts, mod->base_addr + regno * sizeof(uint32_t));
272
+}
273
+
274
+static void emc_write(QTestState *qts, const EMCModule *mod,
275
+ NPCM7xxPWMRegister regno, uint32_t value)
276
+{
277
+ qtest_writel(qts, mod->base_addr + regno * sizeof(uint32_t), value);
278
+}
279
+
280
+static void emc_read_tx_desc(QTestState *qts, uint32_t addr,
281
+ NPCM7xxEMCTxDesc *desc)
282
+{
283
+ qtest_memread(qts, addr, desc, sizeof(*desc));
284
+ desc->flags = le32_to_cpu(desc->flags);
285
+ desc->txbsa = le32_to_cpu(desc->txbsa);
286
+ desc->status_and_length = le32_to_cpu(desc->status_and_length);
287
+ desc->ntxdsa = le32_to_cpu(desc->ntxdsa);
288
+}
289
+
290
+static void emc_write_tx_desc(QTestState *qts, const NPCM7xxEMCTxDesc *desc,
291
+ uint32_t addr)
292
+{
293
+ NPCM7xxEMCTxDesc le_desc;
294
+
295
+ le_desc.flags = cpu_to_le32(desc->flags);
296
+ le_desc.txbsa = cpu_to_le32(desc->txbsa);
297
+ le_desc.status_and_length = cpu_to_le32(desc->status_and_length);
298
+ le_desc.ntxdsa = cpu_to_le32(desc->ntxdsa);
299
+ qtest_memwrite(qts, addr, &le_desc, sizeof(le_desc));
300
+}
301
+
302
+static void emc_read_rx_desc(QTestState *qts, uint32_t addr,
303
+ NPCM7xxEMCRxDesc *desc)
304
+{
305
+ qtest_memread(qts, addr, desc, sizeof(*desc));
306
+ desc->status_and_length = le32_to_cpu(desc->status_and_length);
307
+ desc->rxbsa = le32_to_cpu(desc->rxbsa);
308
+ desc->reserved = le32_to_cpu(desc->reserved);
309
+ desc->nrxdsa = le32_to_cpu(desc->nrxdsa);
310
+}
311
+
312
+static void emc_write_rx_desc(QTestState *qts, const NPCM7xxEMCRxDesc *desc,
313
+ uint32_t addr)
314
+{
315
+ NPCM7xxEMCRxDesc le_desc;
316
+
317
+ le_desc.status_and_length = cpu_to_le32(desc->status_and_length);
318
+ le_desc.rxbsa = cpu_to_le32(desc->rxbsa);
319
+ le_desc.reserved = cpu_to_le32(desc->reserved);
320
+ le_desc.nrxdsa = cpu_to_le32(desc->nrxdsa);
321
+ qtest_memwrite(qts, addr, &le_desc, sizeof(le_desc));
322
+}
323
+
324
+/*
325
+ * Reset the EMC module.
326
+ * The module must be reset before, e.g., TXDLSA,RXDLSA are changed.
327
+ */
328
+static bool emc_soft_reset(QTestState *qts, const EMCModule *mod)
329
+{
330
+ uint32_t val;
331
+ uint64_t end_time;
332
+
333
+ emc_write(qts, mod, REG_MCMDR, REG_MCMDR_SWR);
334
+
335
+ /*
336
+ * Wait for device to reset as the linux driver does.
337
+ * During reset the AHB reads 0 for all registers. So first wait for
338
+ * something that resets to non-zero, and then wait for SWR becoming 0.
339
+ */
340
+ end_time = g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND;
341
+
342
+ do {
343
+ qtest_clock_step(qts, 100);
344
+ val = emc_read(qts, mod, REG_FFTCR);
345
+ } while (val == 0 && g_get_monotonic_time() < end_time);
346
+ if (val != 0) {
347
+ do {
348
+ qtest_clock_step(qts, 100);
349
+ val = emc_read(qts, mod, REG_MCMDR);
350
+ if ((val & REG_MCMDR_SWR) == 0) {
351
+ /*
352
+ * N.B. The CAMs have been reset here, so macaddr matching of
353
+ * incoming packets will not work.
354
+ */
355
+ return true;
356
+ }
357
+ } while (g_get_monotonic_time() < end_time);
358
+ }
359
+
360
+ g_message("%s: Timeout expired", __func__);
361
+ return false;
362
+}
363
+
364
+/* Check emc registers are reset to default value. */
365
+static void test_init(gconstpointer test_data)
366
+{
367
+ const TestData *td = test_data;
368
+ const EMCModule *mod = td->module;
369
+ QTestState *qts = qtest_init("-machine quanta-gsj");
370
+ int i;
371
+
372
+#define CHECK_REG(regno, value) \
373
+ do { \
374
+ g_assert_cmphex(emc_read(qts, mod, (regno)), ==, (value)); \
375
+ } while (0)
376
+
377
+ CHECK_REG(REG_CAMCMR, 0);
378
+ CHECK_REG(REG_CAMEN, 0);
379
+ CHECK_REG(REG_TXDLSA, 0xfffffffc);
380
+ CHECK_REG(REG_RXDLSA, 0xfffffffc);
381
+ CHECK_REG(REG_MCMDR, 0);
382
+ CHECK_REG(REG_MIID, 0);
383
+ CHECK_REG(REG_MIIDA, 0x00900000);
384
+ CHECK_REG(REG_FFTCR, 0x0101);
385
+ CHECK_REG(REG_DMARFC, 0x0800);
386
+ CHECK_REG(REG_MIEN, 0);
387
+ CHECK_REG(REG_MISTA, 0);
388
+ CHECK_REG(REG_MGSTA, 0);
389
+ CHECK_REG(REG_MPCNT, 0x7fff);
390
+ CHECK_REG(REG_MRPC, 0);
391
+ CHECK_REG(REG_MRPCC, 0);
392
+ CHECK_REG(REG_MREPC, 0);
393
+ CHECK_REG(REG_DMARFS, 0);
394
+ CHECK_REG(REG_CTXDSA, 0);
395
+ CHECK_REG(REG_CTXBSA, 0);
396
+ CHECK_REG(REG_CRXDSA, 0);
397
+ CHECK_REG(REG_CRXBSA, 0);
398
+
399
+#undef CHECK_REG
400
+
401
+ for (i = 0; i < NUM_CAMML_REGS; ++i) {
402
+ g_assert_cmpuint(emc_read(qts, mod, REG_CAMM_BASE + i * 2), ==,
403
+ 0);
404
+ g_assert_cmpuint(emc_read(qts, mod, REG_CAML_BASE + i * 2), ==,
405
+ 0);
406
+ }
407
+
408
+ qtest_quit(qts);
409
+}
410
+
411
+static bool emc_wait_irq(QTestState *qts, const EMCModule *mod, int step,
412
+ bool is_tx)
413
+{
414
+ uint64_t end_time =
415
+ g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND;
416
+
417
+ do {
418
+ if (qtest_get_irq(qts, is_tx ? mod->tx_irq : mod->rx_irq)) {
419
+ return true;
420
+ }
421
+ qtest_clock_step(qts, step);
422
+ } while (g_get_monotonic_time() < end_time);
423
+
424
+ g_message("%s: Timeout expired", __func__);
425
+ return false;
426
+}
427
+
428
+static bool emc_wait_mista(QTestState *qts, const EMCModule *mod, int step,
429
+ uint32_t flag)
430
+{
431
+ uint64_t end_time =
432
+ g_get_monotonic_time() + TIMEOUT_SECONDS * G_TIME_SPAN_SECOND;
433
+
434
+ do {
435
+ uint32_t mista = emc_read(qts, mod, REG_MISTA);
436
+ if (mista & flag) {
437
+ return true;
438
+ }
439
+ qtest_clock_step(qts, step);
440
+ } while (g_get_monotonic_time() < end_time);
441
+
442
+ g_message("%s: Timeout expired", __func__);
443
+ return false;
444
+}
445
+
446
+static bool wait_socket_readable(int fd)
447
+{
448
+ fd_set read_fds;
449
+ struct timeval tv;
450
+ int rv;
451
+
452
+ FD_ZERO(&read_fds);
453
+ FD_SET(fd, &read_fds);
454
+ tv.tv_sec = TIMEOUT_SECONDS;
455
+ tv.tv_usec = 0;
456
+ rv = select(fd + 1, &read_fds, NULL, NULL, &tv);
457
+ if (rv == -1) {
458
+ perror("select");
459
+ } else if (rv == 0) {
460
+ g_message("%s: Timeout expired", __func__);
461
+ }
462
+ return rv == 1;
463
+}
464
+
465
+/* Initialize *desc (in host endian format). */
466
+static void init_tx_desc(NPCM7xxEMCTxDesc *desc, size_t count,
467
+ uint32_t desc_addr)
468
+{
469
+ g_assert(count >= 2);
470
+ memset(&desc[0], 0, sizeof(*desc) * count);
471
+ /* Leave the last one alone, owned by the cpu -> stops transmission. */
472
+ for (size_t i = 0; i < count - 1; ++i) {
473
+ desc[i].flags =
474
+ (TX_DESC_FLAG_OWNER_MASK | /* owner = 1: emc */
475
+ TX_DESC_FLAG_INTEN |
476
+ 0 | /* crc append = 0 */
477
+ 0 /* padding enable = 0 */);
478
+ desc[i].status_and_length =
479
+ (0 | /* collision count = 0 */
480
+ 0 | /* SQE = 0 */
481
+ 0 | /* PAU = 0 */
482
+ 0 | /* TXHA = 0 */
483
+ 0 | /* LC = 0 */
484
+ 0 | /* TXABT = 0 */
485
+ 0 | /* NCS = 0 */
486
+ 0 | /* EXDEF = 0 */
487
+ 0 | /* TXCP = 0 */
488
+ 0 | /* DEF = 0 */
489
+ 0 | /* TXINTR = 0 */
490
+ 0 /* length filled in later */);
491
+ desc[i].ntxdsa = desc_addr + (i + 1) * sizeof(*desc);
492
+ }
493
+}
494
+
495
+static void enable_tx(QTestState *qts, const EMCModule *mod,
496
+ const NPCM7xxEMCTxDesc *desc, size_t count,
497
+ uint32_t desc_addr, uint32_t mien_flags)
498
+{
499
+ /* Write the descriptors to guest memory. */
500
+ for (size_t i = 0; i < count; ++i) {
501
+ emc_write_tx_desc(qts, desc + i, desc_addr + i * sizeof(*desc));
502
+ }
503
+
504
+ /* Trigger sending the packet. */
505
+ /* The module must be reset before changing TXDLSA. */
506
+ g_assert(emc_soft_reset(qts, mod));
507
+ emc_write(qts, mod, REG_TXDLSA, desc_addr);
508
+ emc_write(qts, mod, REG_CTXDSA, ~0);
509
+ emc_write(qts, mod, REG_MIEN, REG_MIEN_ENTXCP | mien_flags);
510
+ {
511
+ uint32_t mcmdr = emc_read(qts, mod, REG_MCMDR);
512
+ mcmdr |= REG_MCMDR_TXON;
513
+ emc_write(qts, mod, REG_MCMDR, mcmdr);
514
+ }
515
+
516
+ /* Prod the device to send the packet. */
517
+ emc_write(qts, mod, REG_TSDR, 1);
518
+}
519
+
520
+static void emc_send_verify1(QTestState *qts, const EMCModule *mod, int fd,
521
+ bool with_irq, uint32_t desc_addr,
522
+ uint32_t next_desc_addr,
523
+ const char *test_data, int test_size)
524
+{
525
+ NPCM7xxEMCTxDesc result_desc;
526
+ uint32_t expected_mask, expected_value, recv_len;
527
+ int ret;
528
+ char buffer[TX_DATA_LEN];
529
+
530
+ g_assert(wait_socket_readable(fd));
531
+
532
+ /* Read the descriptor back. */
533
+ emc_read_tx_desc(qts, desc_addr, &result_desc);
534
+ /* Descriptor should be owned by cpu now. */
535
+ g_assert((result_desc.flags & TX_DESC_FLAG_OWNER_MASK) == 0);
536
+ /* Test the status bits, ignoring the length field. */
537
+ expected_mask = 0xffff << 16;
538
+ expected_value = TX_DESC_STATUS_TXCP;
539
+ if (with_irq) {
540
+ expected_value |= TX_DESC_STATUS_TXINTR;
541
+ }
542
+ g_assert_cmphex((result_desc.status_and_length & expected_mask), ==,
543
+ expected_value);
544
+
545
+ /* Check data sent to the backend. */
546
+ recv_len = ~0;
547
+ ret = qemu_recv(fd, &recv_len, sizeof(recv_len), MSG_DONTWAIT);
548
+ g_assert_cmpint(ret, == , sizeof(recv_len));
549
+
550
+ g_assert(wait_socket_readable(fd));
551
+ memset(buffer, 0xff, sizeof(buffer));
552
+ ret = qemu_recv(fd, buffer, test_size, MSG_DONTWAIT);
553
+ g_assert_cmpmem(buffer, ret, test_data, test_size);
554
+}
555
+
556
+static void emc_send_verify(QTestState *qts, const EMCModule *mod, int fd,
557
+ bool with_irq)
558
+{
559
+ NPCM7xxEMCTxDesc desc[NUM_TX_DESCRIPTORS];
560
+ uint32_t desc_addr = DESC_ADDR;
561
+ static const char test1_data[] = "TEST1";
562
+ static const char test2_data[] = "Testing 1 2 3 ...";
563
+ uint32_t data1_addr = DATA_ADDR;
564
+ uint32_t data2_addr = data1_addr + sizeof(test1_data);
565
+ bool got_tdu;
566
+ uint32_t end_desc_addr;
567
+
568
+ /* Prepare test data buffer. */
569
+ qtest_memwrite(qts, data1_addr, test1_data, sizeof(test1_data));
570
+ qtest_memwrite(qts, data2_addr, test2_data, sizeof(test2_data));
571
+
572
+ init_tx_desc(&desc[0], NUM_TX_DESCRIPTORS, desc_addr);
573
+ desc[0].txbsa = data1_addr;
574
+ desc[0].status_and_length |= sizeof(test1_data);
575
+ desc[1].txbsa = data2_addr;
576
+ desc[1].status_and_length |= sizeof(test2_data);
577
+
578
+ enable_tx(qts, mod, &desc[0], NUM_TX_DESCRIPTORS, desc_addr,
579
+ with_irq ? REG_MIEN_ENTXINTR : 0);
580
+
581
+ /*
582
+ * It's problematic to observe the interrupt for each packet.
583
+ * Instead just wait until all the packets go out.
584
+ */
585
+ got_tdu = false;
586
+ while (!got_tdu) {
587
+ if (with_irq) {
588
+ g_assert_true(emc_wait_irq(qts, mod, TX_STEP_COUNT,
589
+ /*is_tx=*/true));
590
+ } else {
591
+ g_assert_true(emc_wait_mista(qts, mod, TX_STEP_COUNT,
592
+ REG_MISTA_TXINTR));
593
+ }
594
+ got_tdu = !!(emc_read(qts, mod, REG_MISTA) & REG_MISTA_TDU);
595
+ /* If we don't have TDU yet, reset the interrupt. */
596
+ if (!got_tdu) {
597
+ emc_write(qts, mod, REG_MISTA,
598
+ emc_read(qts, mod, REG_MISTA) & 0xffff0000);
599
+ }
600
+ }
601
+
602
+ end_desc_addr = desc_addr + 2 * sizeof(desc[0]);
603
+ g_assert_cmphex(emc_read(qts, mod, REG_CTXDSA), ==, end_desc_addr);
604
+ g_assert_cmphex(emc_read(qts, mod, REG_MISTA), ==,
605
+ REG_MISTA_TXCP | REG_MISTA_TXINTR | REG_MISTA_TDU);
606
+
607
+ emc_send_verify1(qts, mod, fd, with_irq,
608
+ desc_addr, end_desc_addr,
609
+ test1_data, sizeof(test1_data));
610
+ emc_send_verify1(qts, mod, fd, with_irq,
611
+ desc_addr + sizeof(desc[0]), end_desc_addr,
612
+ test2_data, sizeof(test2_data));
613
+}
614
+
615
+/* Initialize *desc (in host endian format). */
616
+static void init_rx_desc(NPCM7xxEMCRxDesc *desc, size_t count,
617
+ uint32_t desc_addr, uint32_t data_addr)
618
+{
619
+ g_assert_true(count >= 2);
620
+ memset(desc, 0, sizeof(*desc) * count);
621
+ desc[0].rxbsa = data_addr;
622
+ desc[0].status_and_length =
623
+ (0b10 << RX_DESC_STATUS_OWNER_SHIFT | /* owner = 10: emc */
624
+ 0 | /* RP = 0 */
625
+ 0 | /* ALIE = 0 */
626
+ 0 | /* RXGD = 0 */
627
+ 0 | /* PTLE = 0 */
628
+ 0 | /* CRCE = 0 */
629
+ 0 | /* RXINTR = 0 */
630
+ 0 /* length (filled in later) */);
631
+ /* Leave the last one alone, owned by the cpu -> stops transmission. */
632
+ desc[0].nrxdsa = desc_addr + sizeof(*desc);
633
+}
634
+
635
+static void enable_rx(QTestState *qts, const EMCModule *mod,
636
+ const NPCM7xxEMCRxDesc *desc, size_t count,
637
+ uint32_t desc_addr, uint32_t mien_flags,
638
+ uint32_t mcmdr_flags)
639
+{
640
+ /*
641
+ * Write the descriptor to guest memory.
642
+ * FWIW, IWBN if the docs said the buffer needs to be at least DMARFC
643
+ * bytes.
644
+ */
645
+ for (size_t i = 0; i < count; ++i) {
646
+ emc_write_rx_desc(qts, desc + i, desc_addr + i * sizeof(*desc));
647
+ }
648
+
649
+ /* Trigger receiving the packet. */
650
+ /* The module must be reset before changing RXDLSA. */
651
+ g_assert(emc_soft_reset(qts, mod));
652
+ emc_write(qts, mod, REG_RXDLSA, desc_addr);
653
+ emc_write(qts, mod, REG_MIEN, REG_MIEN_ENRXGD | mien_flags);
654
+
655
+ /*
656
+ * We don't know what the device's macaddr is, so just accept all
657
+ * unicast packets (AUP).
658
+ */
659
+ emc_write(qts, mod, REG_CAMCMR, REG_CAMCMR_AUP);
660
+ emc_write(qts, mod, REG_CAMEN, 1 << 0);
661
+ {
662
+ uint32_t mcmdr = emc_read(qts, mod, REG_MCMDR);
663
+ mcmdr |= REG_MCMDR_RXON | mcmdr_flags;
664
+ emc_write(qts, mod, REG_MCMDR, mcmdr);
665
+ }
666
+
667
+ /* Prod the device to accept a packet. */
668
+ emc_write(qts, mod, REG_RSDR, 1);
669
+}
670
+
671
+static void emc_recv_verify(QTestState *qts, const EMCModule *mod, int fd,
672
+ bool with_irq)
673
+{
674
+ NPCM7xxEMCRxDesc desc[NUM_RX_DESCRIPTORS];
675
+ uint32_t desc_addr = DESC_ADDR;
676
+ uint32_t data_addr = DATA_ADDR;
677
+ int ret;
678
+ uint32_t expected_mask, expected_value;
679
+ NPCM7xxEMCRxDesc result_desc;
680
+
681
+ /* Prepare test data buffer. */
682
+ const char test[RX_DATA_LEN] = "TEST";
683
+ int len = htonl(sizeof(test));
684
+ const struct iovec iov[] = {
685
+ {
686
+ .iov_base = &len,
687
+ .iov_len = sizeof(len),
688
+ },{
689
+ .iov_base = (char *) test,
690
+ .iov_len = sizeof(test),
691
+ },
692
+ };
693
+
694
+ /*
695
+ * Reset the device BEFORE sending a test packet, otherwise the packet
696
+ * may get swallowed by an active device of an earlier test.
697
+ */
698
+ init_rx_desc(&desc[0], NUM_RX_DESCRIPTORS, desc_addr, data_addr);
699
+ enable_rx(qts, mod, &desc[0], NUM_RX_DESCRIPTORS, desc_addr,
700
+ with_irq ? REG_MIEN_ENRXINTR : 0, 0);
701
+
702
+ /* Send test packet to device's socket. */
703
+ ret = iov_send(fd, iov, 2, 0, sizeof(len) + sizeof(test));
704
+ g_assert_cmpint(ret, == , sizeof(test) + sizeof(len));
705
+
706
+ /* Wait for RX interrupt. */
707
+ if (with_irq) {
708
+ g_assert_true(emc_wait_irq(qts, mod, RX_STEP_COUNT, /*is_tx=*/false));
709
+ } else {
710
+ g_assert_true(emc_wait_mista(qts, mod, RX_STEP_COUNT, REG_MISTA_RXGD));
711
+ }
712
+
713
+ g_assert_cmphex(emc_read(qts, mod, REG_CRXDSA), ==,
714
+ desc_addr + sizeof(desc[0]));
715
+
716
+ expected_mask = 0xffff;
717
+ expected_value = (REG_MISTA_DENI |
718
+ REG_MISTA_RXGD |
719
+ REG_MISTA_RXINTR);
720
+ g_assert_cmphex((emc_read(qts, mod, REG_MISTA) & expected_mask),
721
+ ==, expected_value);
722
+
723
+ /* Read the descriptor back. */
724
+ emc_read_rx_desc(qts, desc_addr, &result_desc);
725
+ /* Descriptor should be owned by cpu now. */
726
+ g_assert((result_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK) == 0);
727
+ /* Test the status bits, ignoring the length field. */
728
+ expected_mask = 0xffff << 16;
729
+ expected_value = RX_DESC_STATUS_RXGD;
730
+ if (with_irq) {
731
+ expected_value |= RX_DESC_STATUS_RXINTR;
732
+ }
733
+ g_assert_cmphex((result_desc.status_and_length & expected_mask), ==,
734
+ expected_value);
735
+ g_assert_cmpint(RX_DESC_PKT_LEN(result_desc.status_and_length), ==,
736
+ RX_DATA_LEN + CRC_LENGTH);
737
+
738
+ {
739
+ char buffer[RX_DATA_LEN];
740
+ qtest_memread(qts, data_addr, buffer, sizeof(buffer));
741
+ g_assert_cmpstr(buffer, == , "TEST");
742
+ }
743
+}
744
+
745
+static void emc_test_ptle(QTestState *qts, const EMCModule *mod, int fd)
746
+{
747
+ NPCM7xxEMCRxDesc desc[NUM_RX_DESCRIPTORS];
748
+ uint32_t desc_addr = DESC_ADDR;
749
+ uint32_t data_addr = DATA_ADDR;
750
+ int ret;
751
+ NPCM7xxEMCRxDesc result_desc;
752
+ uint32_t expected_mask, expected_value;
753
+
754
+ /* Prepare test data buffer. */
755
+#define PTLE_DATA_LEN 1600
756
+ char test_data[PTLE_DATA_LEN];
757
+ int len = htonl(sizeof(test_data));
758
+ const struct iovec iov[] = {
759
+ {
760
+ .iov_base = &len,
761
+ .iov_len = sizeof(len),
762
+ },{
763
+ .iov_base = (char *) test_data,
764
+ .iov_len = sizeof(test_data),
765
+ },
766
+ };
767
+ memset(test_data, 42, sizeof(test_data));
768
+
769
+ /*
770
+ * Reset the device BEFORE sending a test packet, otherwise the packet
771
+ * may get swallowed by an active device of an earlier test.
772
+ */
773
+ init_rx_desc(&desc[0], NUM_RX_DESCRIPTORS, desc_addr, data_addr);
774
+ enable_rx(qts, mod, &desc[0], NUM_RX_DESCRIPTORS, desc_addr,
775
+ REG_MIEN_ENRXINTR, REG_MCMDR_ALP);
776
+
777
+ /* Send test packet to device's socket. */
778
+ ret = iov_send(fd, iov, 2, 0, sizeof(len) + sizeof(test_data));
779
+ g_assert_cmpint(ret, == , sizeof(test_data) + sizeof(len));
780
+
781
+ /* Wait for RX interrupt. */
782
+ g_assert_true(emc_wait_irq(qts, mod, RX_STEP_COUNT, /*is_tx=*/false));
783
+
784
+ /* Read the descriptor back. */
785
+ emc_read_rx_desc(qts, desc_addr, &result_desc);
786
+ /* Descriptor should be owned by cpu now. */
787
+ g_assert((result_desc.status_and_length & RX_DESC_STATUS_OWNER_MASK) == 0);
788
+ /* Test the status bits, ignoring the length field. */
789
+ expected_mask = 0xffff << 16;
790
+ expected_value = (RX_DESC_STATUS_RXGD |
791
+ RX_DESC_STATUS_PTLE |
792
+ RX_DESC_STATUS_RXINTR);
793
+ g_assert_cmphex((result_desc.status_and_length & expected_mask), ==,
794
+ expected_value);
795
+ g_assert_cmpint(RX_DESC_PKT_LEN(result_desc.status_and_length), ==,
796
+ PTLE_DATA_LEN + CRC_LENGTH);
797
+
798
+ {
799
+ char buffer[PTLE_DATA_LEN];
800
+ qtest_memread(qts, data_addr, buffer, sizeof(buffer));
801
+ g_assert(memcmp(buffer, test_data, PTLE_DATA_LEN) == 0);
802
+ }
803
+}
804
+
805
+static void test_tx(gconstpointer test_data)
806
+{
807
+ const TestData *td = test_data;
808
+ GString *cmd_line = g_string_new("-machine quanta-gsj");
809
+ int *test_sockets = packet_test_init(emc_module_index(td->module),
810
+ cmd_line);
811
+ QTestState *qts = qtest_init(cmd_line->str);
812
+
813
+ /*
814
+ * TODO: For pedantic correctness test_sockets[0] should be closed after
815
+ * the fork and before the exec, but that will require some harness
816
+ * improvements.
817
+ */
818
+ close(test_sockets[1]);
819
+ /* Defensive programming */
820
+ test_sockets[1] = -1;
821
+
822
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
823
+
824
+ emc_send_verify(qts, td->module, test_sockets[0], /*with_irq=*/false);
825
+ emc_send_verify(qts, td->module, test_sockets[0], /*with_irq=*/true);
826
+
827
+ qtest_quit(qts);
828
+}
829
+
830
+static void test_rx(gconstpointer test_data)
831
+{
832
+ const TestData *td = test_data;
833
+ GString *cmd_line = g_string_new("-machine quanta-gsj");
834
+ int *test_sockets = packet_test_init(emc_module_index(td->module),
835
+ cmd_line);
836
+ QTestState *qts = qtest_init(cmd_line->str);
837
+
838
+ /*
839
+ * TODO: For pedantic correctness test_sockets[0] should be closed after
840
+ * the fork and before the exec, but that will require some harness
841
+ * improvements.
842
+ */
843
+ close(test_sockets[1]);
844
+ /* Defensive programming */
845
+ test_sockets[1] = -1;
846
+
847
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
848
+
849
+ emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/false);
850
+ emc_recv_verify(qts, td->module, test_sockets[0], /*with_irq=*/true);
851
+ emc_test_ptle(qts, td->module, test_sockets[0]);
852
+
853
+ qtest_quit(qts);
854
+}
855
+
856
+static void emc_add_test(const char *name, const TestData* td,
857
+ GTestDataFunc fn)
858
+{
859
+ g_autofree char *full_name = g_strdup_printf(
860
+ "npcm7xx_emc/emc[%d]/%s", emc_module_index(td->module), name);
861
+ qtest_add_data_func(full_name, td, fn);
862
+}
863
+#define add_test(name, td) emc_add_test(#name, td, test_##name)
864
+
865
+int main(int argc, char **argv)
866
+{
867
+ TestData test_data_list[ARRAY_SIZE(emc_module_list)];
868
+
869
+ g_test_init(&argc, &argv, NULL);
870
+
871
+ for (int i = 0; i < ARRAY_SIZE(emc_module_list); ++i) {
872
+ TestData *td = &test_data_list[i];
873
+
874
+ td->module = &emc_module_list[i];
875
+
876
+ add_test(init, td);
877
+ add_test(tx, td);
878
+ add_test(rx, td);
879
+ }
880
+
881
+ return g_test_run();
882
+}
883
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
16
index XXXXXXX..XXXXXXX 100644
884
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/arm/nrf51_soc.c
885
--- a/tests/qtest/meson.build
18
+++ b/hw/arm/nrf51_soc.c
886
+++ b/tests/qtest/meson.build
19
@@ -XXX,XX +XXX,XX @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)
887
@@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \
20
}
888
21
memory_region_add_subregion(&s->container, NRF51_FLASH_BASE, &s->flash);
889
qtests_npcm7xx = \
22
890
['npcm7xx_adc-test',
23
- memory_region_init_ram(&s->sram, NULL, "nrf51.sram", s->sram_size, &err);
891
+ 'npcm7xx_emc-test',
24
+ memory_region_init_ram(&s->sram, OBJECT(s), "nrf51.sram", s->sram_size,
892
'npcm7xx_gpio-test',
25
+ &err);
893
'npcm7xx_pwm-test',
26
if (err) {
894
'npcm7xx_rng-test',
27
error_propagate(errp, err);
28
return;
29
--
895
--
30
2.20.1
896
2.20.1
31
897
32
898
diff view generated by jsdifflib
Deleted patch
1
Currently the ARMv7M NVIC object's realize method assumes that the
2
CPU the NVIC is attached to is CPU 0, because it thinks there can
3
only ever be one CPU in the system. To allow a dual-Cortex-M33
4
setup we need to remove this assumption; instead the armv7m
5
wrapper object tells the NVIC its CPU, in the same way that it
6
already tells the CPU what the NVIC is.
7
1
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Message-id: 20190121185118.18550-2-peter.maydell@linaro.org
12
---
13
hw/arm/armv7m.c | 6 ++++--
14
hw/intc/armv7m_nvic.c | 3 +--
15
2 files changed, 5 insertions(+), 4 deletions(-)
16
17
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/arm/armv7m.c
20
+++ b/hw/arm/armv7m.c
21
@@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp)
22
}
23
}
24
25
- /* Tell the CPU where the NVIC is; it will fail realize if it doesn't
26
- * have one.
27
+ /*
28
+ * Tell the CPU where the NVIC is; it will fail realize if it doesn't
29
+ * have one. Similarly, tell the NVIC where its CPU is.
30
*/
31
s->cpu->env.nvic = &s->nvic;
32
+ s->nvic.cpu = s->cpu;
33
34
object_property_set_bool(OBJECT(s->cpu), true, "realized", &err);
35
if (err != NULL) {
36
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
37
index XXXXXXX..XXXXXXX 100644
38
--- a/hw/intc/armv7m_nvic.c
39
+++ b/hw/intc/armv7m_nvic.c
40
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
41
Error *err = NULL;
42
int regionlen;
43
44
- s->cpu = ARM_CPU(qemu_get_cpu(0));
45
-
46
+ /* The armv7m container object will have set our CPU pointer */
47
if (!s->cpu || !arm_feature(&s->cpu->env, ARM_FEATURE_M)) {
48
error_setg(errp, "The NVIC can only be used with a Cortex-M CPU");
49
return;
50
--
51
2.20.1
52
53
diff view generated by jsdifflib
Deleted patch
1
Rather than just creating the CPUs with object_new, make them child
2
objects of the armv7m container. This will allow the cluster code to
3
find the CPUs if an armv7m object is made a child of a cluster object.
4
object_new_with_props() will do the parenting for us.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20190121185118.18550-3-peter.maydell@linaro.org
10
---
11
hw/arm/armv7m.c | 7 ++++++-
12
1 file changed, 6 insertions(+), 1 deletion(-)
13
14
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/armv7m.c
17
+++ b/hw/arm/armv7m.c
18
@@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp)
19
20
memory_region_add_subregion_overlap(&s->container, 0, s->board_memory, -1);
21
22
- s->cpu = ARM_CPU(object_new(s->cpu_type));
23
+ s->cpu = ARM_CPU(object_new_with_props(s->cpu_type, OBJECT(s), "cpu",
24
+ &err, NULL));
25
+ if (err != NULL) {
26
+ error_propagate(errp, err);
27
+ return;
28
+ }
29
30
object_property_set_link(OBJECT(s->cpu), OBJECT(&s->container), "memory",
31
&error_abort);
32
--
33
2.20.1
34
35
diff view generated by jsdifflib
Deleted patch
1
Give each CPU its own container memory region. This is necessary
2
for two reasons:
3
* some devices are instantiated one per CPU and the CPU sees only
4
its own device
5
* since a memory region can only be put into one container, we must
6
give each armv7m object a different MemoryRegion as its 'memory'
7
property, or a dual-CPU configuration will assert on realize when
8
the second armv7m object tries to put the MR into a container when
9
it is already in the first armv7m object's container
10
1
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Message-id: 20190121185118.18550-13-peter.maydell@linaro.org
14
---
15
include/hw/arm/armsse.h | 10 ++++++++++
16
hw/arm/armsse.c | 22 ++++++++++++++++++++--
17
2 files changed, 30 insertions(+), 2 deletions(-)
18
19
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
20
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/arm/armsse.h
22
+++ b/include/hw/arm/armsse.h
23
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
24
IoTKitSysCtl sysctl;
25
IoTKitSysCtl sysinfo;
26
27
+ /*
28
+ * 'container' holds all devices seen by all CPUs.
29
+ * 'cpu_container[i]' is the view that CPU i has: this has the
30
+ * per-CPU devices of that CPU, plus as the background 'container'
31
+ * (or an alias of it, since we can only use it directly once).
32
+ * container_alias[i] is the alias of 'container' used by CPU i+1;
33
+ * CPU 0 can use 'container' directly.
34
+ */
35
MemoryRegion container;
36
+ MemoryRegion container_alias[SSE_MAX_CPUS - 1];
37
+ MemoryRegion cpu_container[SSE_MAX_CPUS];
38
MemoryRegion alias1;
39
MemoryRegion alias2;
40
MemoryRegion alias3;
41
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
42
index XXXXXXX..XXXXXXX 100644
43
--- a/hw/arm/armsse.c
44
+++ b/hw/arm/armsse.c
45
@@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj)
46
qdev_prop_set_string(DEVICE(&s->armv7m[i]), "cpu-type",
47
ARM_CPU_TYPE_NAME("cortex-m33"));
48
g_free(name);
49
+ name = g_strdup_printf("arm-sse-cpu-container%d", i);
50
+ memory_region_init(&s->cpu_container[i], obj, name, UINT64_MAX);
51
+ g_free(name);
52
+ if (i > 0) {
53
+ name = g_strdup_printf("arm-sse-container-alias%d", i);
54
+ memory_region_init_alias(&s->container_alias[i - 1], obj,
55
+ name, &s->container, 0, UINT64_MAX);
56
+ g_free(name);
57
+ }
58
}
59
60
sysbus_init_child_obj(obj, "secctl", &s->secctl, sizeof(s->secctl),
61
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
62
* 0x50000000..0x5fffffff alias of 0x40000000..0x4fffffff
63
*/
64
65
- memory_region_add_subregion_overlap(&s->container, 0, s->board_memory, -1);
66
+ memory_region_add_subregion_overlap(&s->container, 0, s->board_memory, -2);
67
68
for (i = 0; i < info->num_cpus; i++) {
69
DeviceState *cpudev = DEVICE(&s->armv7m[i]);
70
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
71
return;
72
}
73
}
74
- object_property_set_link(cpuobj, OBJECT(&s->container), "memory", &err);
75
+
76
+ if (i > 0) {
77
+ memory_region_add_subregion_overlap(&s->cpu_container[i], 0,
78
+ &s->container_alias[i - 1], -1);
79
+ } else {
80
+ memory_region_add_subregion_overlap(&s->cpu_container[i], 0,
81
+ &s->container, -1);
82
+ }
83
+ object_property_set_link(cpuobj, OBJECT(&s->cpu_container[i]),
84
+ "memory", &err);
85
if (err) {
86
error_propagate(errp, err);
87
return;
88
--
89
2.20.1
90
91
diff view generated by jsdifflib
Deleted patch
1
Create a cluster object to hold each CPU in the SSE. They are
2
logically distinct and may be configured differently (for instance
3
one may not have an FPU where the other does).
4
1
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20190121185118.18550-14-peter.maydell@linaro.org
8
---
9
include/hw/arm/armsse.h | 2 ++
10
hw/arm/armsse.c | 31 ++++++++++++++++++++++++++++---
11
2 files changed, 30 insertions(+), 3 deletions(-)
12
13
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
14
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/arm/armsse.h
16
+++ b/include/hw/arm/armsse.h
17
@@ -XXX,XX +XXX,XX @@
18
#include "hw/misc/iotkit-sysinfo.h"
19
#include "hw/or-irq.h"
20
#include "hw/core/split-irq.h"
21
+#include "hw/cpu/cluster.h"
22
23
#define TYPE_ARMSSE "arm-sse"
24
#define ARMSSE(obj) OBJECT_CHECK(ARMSSE, (obj), TYPE_ARMSSE)
25
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
26
27
/*< public >*/
28
ARMv7MState armv7m[SSE_MAX_CPUS];
29
+ CPUClusterState cluster[SSE_MAX_CPUS];
30
IoTKitSecCtl secctl;
31
TZPPC apb_ppc0;
32
TZPPC apb_ppc1;
33
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
34
index XXXXXXX..XXXXXXX 100644
35
--- a/hw/arm/armsse.c
36
+++ b/hw/arm/armsse.c
37
@@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj)
38
memory_region_init(&s->container, obj, "armsse-container", UINT64_MAX);
39
40
for (i = 0; i < info->num_cpus; i++) {
41
- char *name = g_strdup_printf("armv7m%d", i);
42
- sysbus_init_child_obj(obj, name, &s->armv7m[i], sizeof(s->armv7m),
43
- TYPE_ARMV7M);
44
+ /*
45
+ * We put each CPU in its own cluster as they are logically
46
+ * distinct and may be configured differently.
47
+ */
48
+ char *name;
49
+
50
+ name = g_strdup_printf("cluster%d", i);
51
+ object_initialize_child(obj, name, &s->cluster[i],
52
+ sizeof(s->cluster[i]), TYPE_CPU_CLUSTER,
53
+ &error_abort, NULL);
54
+ qdev_prop_set_uint32(DEVICE(&s->cluster[i]), "cluster-id", i);
55
+ g_free(name);
56
+
57
+ name = g_strdup_printf("armv7m%d", i);
58
+ sysbus_init_child_obj(OBJECT(&s->cluster[i]), name,
59
+ &s->armv7m[i], sizeof(s->armv7m), TYPE_ARMV7M);
60
qdev_prop_set_string(DEVICE(&s->armv7m[i]), "cpu-type",
61
ARM_CPU_TYPE_NAME("cortex-m33"));
62
g_free(name);
63
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
64
error_propagate(errp, err);
65
return;
66
}
67
+ /*
68
+ * The cluster must be realized after the armv7m container, as
69
+ * the container's CPU object is only created on realize, and the
70
+ * CPU must exist and have been parented into the cluster before
71
+ * the cluster is realized.
72
+ */
73
+ object_property_set_bool(OBJECT(&s->cluster[i]),
74
+ true, "realized", &err);
75
+ if (err) {
76
+ error_propagate(errp, err);
77
+ return;
78
+ }
79
80
/* Connect EXP_IRQ/EXP_CPUn_IRQ GPIOs to the NVIC's lines 32 and up */
81
s->exp_irqs[i] = g_new(qemu_irq, s->exp_numirq);
82
--
83
2.20.1
84
85
diff view generated by jsdifflib
Deleted patch
1
The SSE-200 has two Message Handling Units (MHUs), which sit behind
2
the APB PPC0. Wire up some unimplemented-device stubs for these,
3
since we don't yet implement a real model of this device.
4
1
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20190121185118.18550-16-peter.maydell@linaro.org
8
---
9
include/hw/arm/armsse.h | 3 +++
10
hw/arm/armsse.c | 41 +++++++++++++++++++++++++++++++++++++++++
11
2 files changed, 44 insertions(+)
12
13
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
14
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/arm/armsse.h
16
+++ b/include/hw/arm/armsse.h
17
@@ -XXX,XX +XXX,XX @@
18
#include "hw/watchdog/cmsdk-apb-watchdog.h"
19
#include "hw/misc/iotkit-sysctl.h"
20
#include "hw/misc/iotkit-sysinfo.h"
21
+#include "hw/misc/unimp.h"
22
#include "hw/or-irq.h"
23
#include "hw/core/split-irq.h"
24
#include "hw/cpu/cluster.h"
25
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
26
IoTKitSysCtl sysctl;
27
IoTKitSysCtl sysinfo;
28
29
+ UnimplementedDeviceState mhu[2];
30
+
31
/*
32
* 'container' holds all devices seen by all CPUs.
33
* 'cpu_container[i]' is the view that CPU i has: this has the
34
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
35
index XXXXXXX..XXXXXXX 100644
36
--- a/hw/arm/armsse.c
37
+++ b/hw/arm/armsse.c
38
@@ -XXX,XX +XXX,XX @@ struct ARMSSEInfo {
39
int num_cpus;
40
uint32_t sys_version;
41
SysConfigFormat sys_config_format;
42
+ bool has_mhus;
43
};
44
45
static const ARMSSEInfo armsse_variants[] = {
46
@@ -XXX,XX +XXX,XX @@ static const ARMSSEInfo armsse_variants[] = {
47
.num_cpus = 1,
48
.sys_version = 0x41743,
49
.sys_config_format = IoTKitFormat,
50
+ .has_mhus = false,
51
},
52
};
53
54
@@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj)
55
sizeof(s->sysctl), TYPE_IOTKIT_SYSCTL);
56
sysbus_init_child_obj(obj, "armsse-sysinfo", &s->sysinfo,
57
sizeof(s->sysinfo), TYPE_IOTKIT_SYSINFO);
58
+ if (info->has_mhus) {
59
+ sysbus_init_child_obj(obj, "mhu0", &s->mhu[0], sizeof(s->mhu[0]),
60
+ TYPE_UNIMPLEMENTED_DEVICE);
61
+ sysbus_init_child_obj(obj, "mhu1", &s->mhu[1], sizeof(s->mhu[1]),
62
+ TYPE_UNIMPLEMENTED_DEVICE);
63
+ }
64
object_initialize_child(obj, "nmi-orgate", &s->nmi_orgate,
65
sizeof(s->nmi_orgate), TYPE_OR_IRQ,
66
&error_abort, NULL);
67
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
68
* 0x40000000: timer0
69
* 0x40001000: timer1
70
* 0x40002000: dual timer
71
+ * 0x40003000: MHU0 (SSE-200 only)
72
+ * 0x40004000: MHU1 (SSE-200 only)
73
* We must configure and realize each downstream device and connect
74
* it to the appropriate PPC port; then we can realize the PPC and
75
* map its upstream ends to the right place in the container.
76
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
77
return;
78
}
79
80
+ if (info->has_mhus) {
81
+ for (i = 0; i < ARRAY_SIZE(s->mhu); i++) {
82
+ char *name = g_strdup_printf("MHU%d", i);
83
+ char *port = g_strdup_printf("port[%d]", i + 3);
84
+
85
+ qdev_prop_set_string(DEVICE(&s->mhu[i]), "name", name);
86
+ qdev_prop_set_uint64(DEVICE(&s->mhu[i]), "size", 0x1000);
87
+ object_property_set_bool(OBJECT(&s->mhu[i]), true,
88
+ "realized", &err);
89
+ if (err) {
90
+ error_propagate(errp, err);
91
+ return;
92
+ }
93
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->mhu[i]), 0);
94
+ object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr),
95
+ port, &err);
96
+ if (err) {
97
+ error_propagate(errp, err);
98
+ return;
99
+ }
100
+ g_free(name);
101
+ g_free(port);
102
+ }
103
+ }
104
+
105
object_property_set_bool(OBJECT(&s->apb_ppc0), true, "realized", &err);
106
if (err) {
107
error_propagate(errp, err);
108
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
109
memory_region_add_subregion(&s->container, 0x40001000, mr);
110
mr = sysbus_mmio_get_region(sbd_apb_ppc0, 2);
111
memory_region_add_subregion(&s->container, 0x40002000, mr);
112
+ if (info->has_mhus) {
113
+ mr = sysbus_mmio_get_region(sbd_apb_ppc0, 3);
114
+ memory_region_add_subregion(&s->container, 0x40003000, mr);
115
+ mr = sysbus_mmio_get_region(sbd_apb_ppc0, 4);
116
+ memory_region_add_subregion(&s->container, 0x40004000, mr);
117
+ }
118
for (i = 0; i < IOTS_APB_PPC0_NUM_PORTS; i++) {
119
qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_nonsec", i,
120
qdev_get_gpio_in_named(dev_apb_ppc0,
121
--
122
2.20.1
123
124
diff view generated by jsdifflib
Deleted patch
1
The SSE-200 gives each CPU a register bank to use to control its
2
L1 instruction cache. Put in an unimplemented-device stub for this.
3
1
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20190121185118.18550-18-peter.maydell@linaro.org
7
---
8
include/hw/arm/armsse.h | 1 +
9
hw/arm/armsse.c | 39 ++++++++++++++++++++++++++++++++++++++-
10
2 files changed, 39 insertions(+), 1 deletion(-)
11
12
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
13
index XXXXXXX..XXXXXXX 100644
14
--- a/include/hw/arm/armsse.h
15
+++ b/include/hw/arm/armsse.h
16
@@ -XXX,XX +XXX,XX @@ typedef struct ARMSSE {
17
18
UnimplementedDeviceState mhu[2];
19
UnimplementedDeviceState ppu[NUM_PPUS];
20
+ UnimplementedDeviceState cachectrl[SSE_MAX_CPUS];
21
22
/*
23
* 'container' holds all devices seen by all CPUs.
24
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
25
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/arm/armsse.c
27
+++ b/hw/arm/armsse.c
28
@@ -XXX,XX +XXX,XX @@ struct ARMSSEInfo {
29
SysConfigFormat sys_config_format;
30
bool has_mhus;
31
bool has_ppus;
32
+ bool has_cachectrl;
33
};
34
35
static const ARMSSEInfo armsse_variants[] = {
36
@@ -XXX,XX +XXX,XX @@ static const ARMSSEInfo armsse_variants[] = {
37
.sys_config_format = IoTKitFormat,
38
.has_mhus = false,
39
.has_ppus = false,
40
+ .has_cachectrl = false,
41
},
42
};
43
44
@@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj)
45
g_free(name);
46
}
47
}
48
+ if (info->has_cachectrl) {
49
+ for (i = 0; i < info->num_cpus; i++) {
50
+ char *name = g_strdup_printf("cachectrl%d", i);
51
+
52
+ sysbus_init_child_obj(obj, name, &s->cachectrl[i],
53
+ sizeof(s->cachectrl[i]),
54
+ TYPE_UNIMPLEMENTED_DEVICE);
55
+ g_free(name);
56
+ }
57
+ }
58
object_initialize_child(obj, "nmi-orgate", &s->nmi_orgate,
59
sizeof(s->nmi_orgate), TYPE_OR_IRQ,
60
&error_abort, NULL);
61
@@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp)
62
qdev_connect_gpio_out(DEVICE(&s->ppc_irq_orgate), 0,
63
armsse_get_common_irq_in(s, 10));
64
65
- /* 0x40010000 .. 0x4001ffff: private CPU region: unused in IoTKit */
66
+ /*
67
+ * 0x40010000 .. 0x4001ffff (and the 0x5001000... secure-only alias):
68
+ * private per-CPU region (all these devices are SSE-200 only):
69
+ * 0x50010000: L1 icache control registers
70
+ * 0x50011000: CPUSECCTRL (CPU local security control registers)
71
+ * 0x4001f000 and 0x5001f000: CPU_IDENTITY register block
72
+ */
73
+ if (info->has_cachectrl) {
74
+ for (i = 0; i < info->num_cpus; i++) {
75
+ char *name = g_strdup_printf("cachectrl%d", i);
76
+ MemoryRegion *mr;
77
+
78
+ qdev_prop_set_string(DEVICE(&s->cachectrl[i]), "name", name);
79
+ g_free(name);
80
+ qdev_prop_set_uint64(DEVICE(&s->cachectrl[i]), "size", 0x1000);
81
+ object_property_set_bool(OBJECT(&s->cachectrl[i]), true,
82
+ "realized", &err);
83
+ if (err) {
84
+ error_propagate(errp, err);
85
+ return;
86
+ }
87
+
88
+ mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cachectrl[i]), 0);
89
+ memory_region_add_subregion(&s->cpu_container[i], 0x50010000, mr);
90
+ }
91
+ }
92
93
/* 0x40020000 .. 0x4002ffff : ARMSSE system control peripheral region */
94
/* Devices behind APB PPC1:
95
--
96
2.20.1
97
98
diff view generated by jsdifflib
Deleted patch
1
Add a model of the SSE-200, now we have put in all
2
the code that lets us make it different from the IoTKit.
3
1
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20190121185118.18550-22-peter.maydell@linaro.org
7
---
8
include/hw/arm/armsse.h | 19 ++++++++++++++++---
9
hw/arm/armsse.c | 12 ++++++++++++
10
2 files changed, 28 insertions(+), 3 deletions(-)
11
12
diff --git a/include/hw/arm/armsse.h b/include/hw/arm/armsse.h
13
index XXXXXXX..XXXXXXX 100644
14
--- a/include/hw/arm/armsse.h
15
+++ b/include/hw/arm/armsse.h
16
@@ -XXX,XX +XXX,XX @@
17
/*
18
- * ARM SSE (Subsystems for Embedded): IoTKit
19
+ * ARM SSE (Subsystems for Embedded): IoTKit, SSE-200
20
*
21
* Copyright (c) 2018 Linaro Limited
22
* Written by Peter Maydell
23
@@ -XXX,XX +XXX,XX @@
24
/*
25
* This is a model of the Arm "Subsystems for Embedded" family of
26
* hardware, which include the IoT Kit and the SSE-050, SSE-100 and
27
- * SSE-200. Currently we model only the Arm IoT Kit which is documented in
28
+ * SSE-200. Currently we model:
29
+ * - the Arm IoT Kit which is documented in
30
* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ecm0601256/index.html
31
- * It contains:
32
+ * - the SSE-200 which is documented in
33
+ * http://infocenter.arm.com/help/topic/com.arm.doc.101104_0100_00_en/corelink_sse200_subsystem_for_embedded_technical_reference_manual_101104_0100_00_en.pdf
34
+ *
35
+ * The IoTKit contains:
36
* a Cortex-M33
37
* the IDAU
38
* some timers and watchdogs
39
@@ -XXX,XX +XXX,XX @@
40
* a security controller
41
* a bus fabric which arranges that some parts of the address
42
* space are secure and non-secure aliases of each other
43
+ * The SSE-200 additionally contains:
44
+ * a second Cortex-M33
45
+ * two Message Handling Units (MHUs)
46
+ * an optional CryptoCell (which we do not model)
47
+ * more SRAM banks with associated MPCs
48
+ * multiple Power Policy Units (PPUs)
49
+ * a control interface for an icache for each CPU
50
+ * per-CPU identity and control register blocks
51
*
52
* QEMU interface:
53
* + QOM property "memory" is a MemoryRegion containing the devices provided
54
@@ -XXX,XX +XXX,XX @@
55
* them via the ARMSSE base class, so they have no IOTKIT() etc macros.
56
*/
57
#define TYPE_IOTKIT "iotkit"
58
+#define TYPE_SSE200 "sse-200"
59
60
/* We have an IRQ splitter and an OR gate input for each external PPC
61
* and the 2 internal PPCs
62
diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c
63
index XXXXXXX..XXXXXXX 100644
64
--- a/hw/arm/armsse.c
65
+++ b/hw/arm/armsse.c
66
@@ -XXX,XX +XXX,XX @@ static const ARMSSEInfo armsse_variants[] = {
67
.has_cpusecctrl = false,
68
.has_cpuid = false,
69
},
70
+ {
71
+ .name = TYPE_SSE200,
72
+ .sram_banks = 4,
73
+ .num_cpus = 2,
74
+ .sys_version = 0x22041743,
75
+ .sys_config_format = SSE200Format,
76
+ .has_mhus = true,
77
+ .has_ppus = true,
78
+ .has_cachectrl = true,
79
+ .has_cpusecctrl = true,
80
+ .has_cpuid = true,
81
+ },
82
};
83
84
static uint32_t armsse_sys_config_value(ARMSSE *s, const ARMSSEInfo *info)
85
--
86
2.20.1
87
88
diff view generated by jsdifflib