Commit graph

271 commits

Author SHA1 Message Date
Hector Martin
76c283deba hv_vm: Delay after sync mmiotrace events
This allows the USB hardware to get a chance to deliver the packets to
the host, in case the poke would break it.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 20:12:20 +09:00
Hector Martin
1b1653dfe9 hv_vm: Simplify r31 handling, move LR adjustment to hv_exc.c
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 20:12:20 +09:00
Hector Martin
48c7fc725b cpu_regs.h: Add IPI and VM timer reg defines
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 20:12:20 +09:00
Hector Martin
e484d6df70 cpu_regs.h: Add Apple-defined exception types
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 20:12:20 +09:00
Hector Martin
b1f55015eb arm_cpu_regs.h: Add sysreg exception ISS bit defines
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 20:12:20 +09:00
Hector Martin
74b8863a7f arm_cpu_regs.h: Add timer bit defines
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 20:12:20 +09:00
Hector Martin
e99680cb1e hv: Rename HV_HOOK proxy start type to HV
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 20:12:20 +09:00
Hector Martin
25f4500cea utils.h: Do sysreg defines in a way that allows extracting the fields
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 19:51:08 +09:00
Hector Martin
0192bd6617 gxf: Add gxf_enabled()
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 19:49:12 +09:00
Hector Martin
aacbdf0949 GXF_STATUS -> GXF_STATUS_EL1
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-22 04:42:38 +09:00
Hector Martin
09cdebf08b gxf: Don't try to touch HCR_EL2 if GXF is enabled
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-22 03:21:01 +09:00
Hector Martin
76dca8c891 memory: Unbork EL0 execution
We need to make m1n1 itself EL0-executable.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-22 02:48:17 +09:00
Hector Martin
da440672a8 uartproxy: Send events without copying data to a giant buffer
We don't have 64K of stack.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-16 19:04:51 +09:00
Hector Martin
7abebaec88 iodev: Add iodev_queue() API to queue data without kicking transmission
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-16 19:04:51 +09:00
Mark Kettenis
9604907b2d pcie: minimal initialization
Minimal initialization of the PCIe hardware such that the tunable
can be applied such that they don't have to be passed along in
the devicetree.

Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
2021-05-16 02:43:44 +09:00
Hector Martin
28ab4e1611 hv_vm: Handle load/store instructions with update
These don't get instruction syndromes, so we need to stop relying on
that to determine the access size.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-15 23:57:48 +09:00
Hector Martin
afc088840d hv: Add Python-side MMIO emulation hooks
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-15 23:57:48 +09:00
Hector Martin
323b02ce1d hv: Implement basic MMIO tracing to Python
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-15 23:57:48 +09:00
Hector Martin
a1f6b2502a usb_dwc3: Send a ZLP after multiple-of-512 transfers
This fixes the stalling issue with readmem() of a multiple of 512 bytes.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-15 21:47:22 +09:00
Hector Martin
57708b529f usb_dwc3: Change xfer_in_progress to a bool
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-15 21:47:22 +09:00
Hector Martin
58489bf72c iodev, usb: Add flush() call to flush buffers to the host
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-15 21:47:22 +09:00
Hector Martin
67c7043b9a utils: In EL1, instead of rebooting, break into HV
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-15 20:42:50 +09:00
Hector Martin
03b70eed94 hv_vm: Move dprintf macro to utils.h, add more debugging
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-15 20:38:32 +09:00
Hector Martin
3de3b54b7e hv_asm: Restore all registers on return to guest
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-15 20:36:39 +09:00
Janne Grunau
a742f05532 usb/hv: add second CDC ACM interface for virtualized UART
Signed-off-by: Janne Grunau <j@jannau.net>
2021-05-15 19:47:08 +09:00
Sven Peter
4a893dc57a apple_regs: document more SPRR regs
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-05-15 16:38:45 +09:00
Hector Martin
5d3f154d0f hv_vm: Correctly split software mapped L2 blocks
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-15 01:28:44 +09:00
Hector Martin
bf34611bf4 hv_vm: Add out-of-bounds IPA check
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-15 01:15:17 +09:00
Hector Martin
e919b63a02 hv_vm: Add register-offset LDR/STR emulation, fix bugs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-15 00:43:39 +09:00
Hector Martin
1a5ba2c67e hv_vm: Fix bad asserts
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-14 21:49:11 +09:00
Hector Martin
920ff59483 exception: Unbork EL1 stack
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-13 21:14:58 +09:00
Hector Martin
9efa91bf87 gxf: Do not disable the MMU around GXF calls
We are now SPRR compatible.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-13 18:31:27 +09:00
Hector Martin
b9ed00c6f3 memory: Initialize SPRR permissions
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-13 18:16:56 +09:00
Hector Martin
8af8dadee1 memory: Support L3 mappings, map m1n1 code as RX.
This replaces the old pagetable code with an adapted version of what
hv_vm.c does, which can handle block and page mappings more
intelligently.

Then, map the m1n1 code section as RX. This allows us to work in modes
where W^X is enforced.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-13 18:14:31 +09:00
Hector Martin
3e1ea2d503 memory: Add separate mappings for EL0 data access
This unborks stack and constant pool accesses from el0_call.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-13 17:36:02 +09:00
Hector Martin
7685800b45 heapblock: Assert if not initialized
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-13 17:33:57 +09:00
Hector Martin
9ffab4ac98 hv_vm.c: Remove stray ;
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-13 17:33:48 +09:00
Sven Peter
1c604a77c5 gxf: add support for guarded exception levels
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-05-11 15:48:40 +09:00
Sven Peter
9120cb8426 memory: allow to reinit and temporarily disable the MMU
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-05-11 15:48:40 +09:00
Sven Peter
b00c5e6522 utils.h: add msr_sync convenience macros
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-05-11 15:48:40 +09:00
Sven Peter
36efdd2ac3 allow cpu_regs.h to be included in .S files
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-05-11 15:48:40 +09:00
Sven Peter
813e40f4ca exception_asm.S: skip msr hcr_el2 if not required
When guarded exception levels are enabled hcr_el2 can no longer be written to from EL2.
A future commit will however use el1_call to jump to GL1. It will setup hcr_el2 before
enabling GXF such that the write doesn't have to happen in el1_call anymore

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-05-11 15:48:40 +09:00
Sven Peter
148fe31122 exception_asm.S: correctly setup sp for EL1
The previous code switched SPSel to EL0 but then used eret to
jump to EL1h which uses SP_EL1 instead

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-05-11 15:48:40 +09:00
Hector Martin
ed32cf6328 hv_exc: Add a hacky STEP feature to interrupt guest after a while
This should eventually be a proper single step feature or something, but
for now...

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-09 03:25:51 +09:00
Hector Martin
bcdafe8d00 hv_vm: Short-circuit hv_translate when MMU is off
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-09 03:25:51 +09:00
Hector Martin
8d5596a1a1 hv_vm: Fix bug when making L2 mappings
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-09 03:25:51 +09:00
Hector Martin
52823eaab6 hv_asm: Turn off PAN on exception entry
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-09 03:25:51 +09:00
Hector Martin
4c043a0f97 memory: Move SCTLR/TCR defines to arm_cpu_regs.h
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-09 03:25:51 +09:00
Hector Martin
0203aa6d3d proxy: Add framebuffer ops
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-08 03:42:21 +09:00
Hector Martin
aad892d461 fb: Implement fb_shutdown() & friends
Clean up after ourselves before chainload

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-07 12:19:20 +09:00
Hector Martin
0ae3455d51 hv_vuart: World's stupidest virtual UART implementation
Work in progress...

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-05 04:03:44 +09:00
Hector Martin
9407dba2e0 hv_vm: Initial data abort handling
Supports software-mapping for a subset of ldr/str instructions.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-05 04:03:44 +09:00
Hector Martin
8a64441bcd hv_vm: Extend hv_translate() for stage1 and write modes
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-05 03:27:19 +09:00
Hector Martin
c0c7c57dd0 hv_vm: Fix bug inhv_pt_map_l4()
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-05 03:24:37 +09:00
Hector Martin
ce3a673413 uart: Move registers to uart_regs.h
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-05 03:23:25 +09:00
Hector Martin
27af846aae hv_vm.c: Move SPTE_TYPE to bit 50
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-05 03:23:04 +09:00
Hector Martin
0e987f031b utils: Add flush_and_reboot() to do the iodev flush dance
Use this for exceptions, asserts, etc.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-05 03:21:48 +09:00
Hector Martin
50f112c396 hv: Add support for address translation & abort decoding
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-05 00:28:39 +09:00
Hector Martin
a3440f2b48 hv: Support cleanly exiting the hypervisor from an exception
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-05 00:28:39 +09:00
Hector Martin
d35fa5e0fc iodev: Add iodev_console_kick()
This is used prior to rebooting in exception handlers, to make sure all
the exception dump data gets sent to USB if we are connected via that.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-05 00:28:39 +09:00
Hector Martin
4d64c33ca6 hv: Implement basic exception handling
Allows Python to handle hypervisor exceptions, and implements exception
info display and basic debug commands.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-04 19:36:23 +09:00
Hector Martin
315fcf36aa uartproxy: Add support for nested invocations
This allows the proxy to call back to Python for handling exceptions or
other events, passing reason information about why it was invoked and
returning normally when the exception has been handled.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-04 19:34:08 +09:00
Hector Martin
4cc0f45c9d arm_cpu_regs.h: Add SYS_ESR_EL2
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-04 19:25:46 +09:00
Hector Martin
785dba33ad exception_asm: Fix missing register restores
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-04 19:24:52 +09:00
Hector Martin
a326aca956 hv: Enable physical timer for EL1 properly
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-04 19:23:35 +09:00
Hector Martin
23304719cd hv: Move VM code to hv_vm.c
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-04 15:38:17 +09:00
Hector Martin
95542a4619 kboot: Handle missing CPUs properly
This is necessary to boot Linux in UP mode if we're in EL1 and the HV
does not support SMP yet.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-04 01:52:58 +09:00
Hector Martin
9584e7d312 uartproxy: Add IODEV_WHOAMI feature to get current iodev
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-03 21:19:35 +09:00
Hector Martin
1ae60ad715 hv: Beginnings of a hypervisor
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-01 19:21:33 +09:00
Hector Martin
1ff5b82aab iodev/usb: Do not crash if USB was not initialized
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-01 19:04:38 +09:00
Hector Martin
68156fd806 utils.h: Add alignment and field macros
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-01 19:02:49 +09:00
Hector Martin
26c4ab3888 formatting: Sort main include first
clang-format is supposed to do this, but for some reason it's "sticky"
and doesn't...

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-01 18:31:58 +09:00
Hector Martin
45a0054f63 Add build-time printf() argument checking and fix warnings
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-01 18:23:44 +09:00
Hector Martin
882610b50e cpu_regs.h: s/SYS_APL/SYS_IMP_APL/ to match Linux
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-29 15:45:44 +09:00
Hector Martin
c2e2094b95 usb_dwc3: Add missing space to product name string
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-17 19:10:41 +09:00
Hector Martin
7dfe24ee2c Rework kboot/chainload flow to shut down before calling the next stage
Next stage boots now exit back to main() after replying to the proxy
command, allowing shutdown functions to be called. Introduces a new
P_VECTOR proxy op, distinct from P_CALL. The Python side is reworked
to remain compatible with older versions that do not support this.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-17 18:12:59 +09:00
Hector Martin
bcece01769 usb: Hook up to iodev and bring up after payload boot attempt
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-17 16:47:43 +09:00
Hector Martin
4f7ae843fa usb_dwc3: Fix read/write transfer pumping, add missing funcs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-17 16:45:19 +09:00
Hector Martin
df9218582e usb_dwc3: Use new VID/PID
Not official yet, PR:
https://github.com/pidcodes/pidcodes.github.com/pull/635/files

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-17 16:45:19 +09:00
Hector Martin
108f104e96 usb_dwc3: USB compliance improvements
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-17 16:45:19 +09:00
Hector Martin
fcdf2aede9 smp: Print success message on CPU#0
SMP secondary prints only go to UART, so we need something on the main
CPU for other iodev consoles.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-17 16:45:19 +09:00
Hector Martin
34c1dc50ae iodev: Add iodev_handle_events() and iodev_console_flush()
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-17 16:45:19 +09:00
Hector Martin
d3957cc89d iodev: Fix error returns for iodev_read/write
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-17 16:45:19 +09:00
Hector Martin
565753980a iodev: Move primary core check into iodev, always use in_iodev logic
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-17 16:45:19 +09:00
Hector Martin
303118fd93 uartproxy: Convert to iodev
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-17 16:26:41 +09:00
Hector Martin
88e1612c09 uartproxy: s/CRCERR/CSUMERR/ and actually use it
It's not a CRC.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-17 16:25:48 +09:00
Hector Martin
8104ec02c4 iodev: Add proxy ops
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-15 23:18:57 +09:00
Hector Martin
c8f59566eb fb: Remove unused enable/disable code
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-15 23:18:57 +09:00
Hector Martin
f8c1c65cf9 Revert "proxy: add fb console console ops"
This reverts commit de0456b9a5.

These ops become redundant with the new iodev control op.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-15 23:18:57 +09:00
Hector Martin
cc4a5d312d iodev: Add new framework for I/O and console devices
This replaces the earlier earlycon with a single shared console buffer
for all output devices.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-15 23:18:57 +09:00
Hector Martin
1c518ded09 types.h: Include stdbool.h, define ssize_t
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-15 23:18:57 +09:00
Hector Martin
d63e84d2f7 fb: add fb_console_reserve_lines()
This is like fb_console_scroll(), but only scrolls if necessary to
ensure that enough free space is available at the end of the console.
This avoids spuriously scrolling during shutdown if we still have space.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-15 23:18:57 +09:00
Hector Martin
151c601b2a Revert "fb: add earlycon to capture messages before fb_init"
This is being replaced with a global buffer in iodev.

This reverts commit 5d4067642e.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-15 23:18:57 +09:00
Sven Peter
add04246e7 usb: add clock/power/phy bringup
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-15 18:39:33 +09:00
Sven Peter
59ba266b11 usb: add DWC3 CDC ACM code
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-15 18:39:33 +09:00
Sven Peter
ea362ea8f9 ringbuffer: add a simple ringbuffer data structure
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-15 18:39:33 +09:00
Sven Peter
00e862238c usb: add usb_types.h
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-15 18:39:33 +09:00
Sven Peter
50afcd1ffe usb: add more registers and removed linux-specific code from usb_dwc3_regs.h
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-15 18:39:33 +09:00
Sven Peter
ac13c3b17f usb: add drivers/usb/dwc3/core.h from linux
This file is taken from commit 7bc5a6ba369217e0137833f5955cf0b0f08b0712 before
the license was changed to GPLv2-only.

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/dwc3/core.h?id=7bc5a6ba369217e0137833f5955cf0b0f08b0712

core.h is copyright:
  Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
  Authors: Felipe Balbi <balbi@ti.com>,
	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
and dual-licensed under the GPLv2 and BSD3.

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-15 18:39:33 +09:00
Sven Peter
17fdc79c13 utils.h: add mdelay
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-15 18:39:33 +09:00