Commit graph

770 commits

Author SHA1 Message Date
Hector Martin
77074b9098 hv_aic: Support AICv2
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-04 03:52:42 +09:00
Hector Martin
8fa422c0d3 fb: Map the framebuffer uncached, and use a shadow FB for speed
Turns out AMCC on t600x throws errors when DISP0 real-time memory
requests hit the CPU cache, and then macOS panics.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-04 03:52:30 +09:00
Hector Martin
dc3806252b aic: Basic AICv2 support
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-04 03:52:30 +09:00
Hector Martin
f824f60f5c utils: Unbork udelay()
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-02 12:36:07 +09:00
Hector Martin
6765bc3ff6 hv_vm: Support >36-bit PAs
This needs an extra L1 translation level, but only on SoCs with support
for >36-bit PAs. On M1, we bypass it and keep starting at L2.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-02 02:35:26 +09:00
Hector Martin
d7983c7173 arm_cpu_regs.h: Add SYS_ID_AA64MMFR0_EL1
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-02 02:23:07 +09:00
Hector Martin
e99138710a smp: Handle IRQ enable reg properly (maybe)
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 21:00:56 +09:00
Hector Martin
87613dc208 smp: Support more clusters/CPUs properly
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 21:00:56 +09:00
Hector Martin
9b6e5fbc52 cpufreq: Add preliminary T6000 support
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 21:00:56 +09:00
Hector Martin
d7bd21d51c usb: Use new DART code to autoselect compatible mode
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 21:00:56 +09:00
Hector Martin
1edb18ac44 pmgr: Do not try to fix up virtual devs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 21:00:56 +09:00
Hector Martin
84902062c9 dart: T6000 support
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 21:00:56 +09:00
Hector Martin
68aec75918 memory: Larger PA support & dynamically map MMIO
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 21:00:56 +09:00
Hector Martin
326ba6fb33 utils: Fix BIT() signedness
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 19:00:34 +09:00
Hector Martin
425daaedbd utils: Use CPU timer instead of AIC timer
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 19:00:34 +09:00
Hector Martin
95dd7b90a4 chickens: Add preliminary T6000 support
P-core chickens need checking.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 19:00:34 +09:00
Hector Martin
ed21a80bc3 chickens: Refactor and update M1 bits
This adds some missing fixes for M1/T8103 and reworks the code to split
off common parts, and also handle per-revision bits.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 13:41:12 +09:00
Hector Martin
7ff48f6201 memory: Make the RAM base dynamic
For now we compute this as phys_base aligned down to a 4GiB boundary.
Hopefully that works for future SoCs too.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 13:39:40 +09:00
Hector Martin
38fc7a0780 Configure early debug features by SoC type
To build a version with early UART support, set it in config.h

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-11-01 13:36:42 +09:00
Vincent Duvert
b15be6bcd7 Remove hardcoded UART/WDT addresses
The M1 Pro/Max Macs use a different base address for the UART and the
WDT than earlier models.

Remove hardcoded base addresses constants and replace them with loads
from the ADT.

- The base address of the WDT is already retrieved in wdt_disable; also
use this address when triggering a reboot.
- Retrieve the base address of uart0 in uart_init. If the operation
fails, the error will be signaled on the early uart (if not disabled).
- The early debug UART can’t use the ADT (or shouldn’t) so it is now
disabled by default. To enable it, add
-DEARLY_UART -DEARLY_UART_BASE=0xuart_address
to the CFLAGS.

Signed-off-by: Vincent Duvert <vincent@duvert.net>
2021-11-01 11:27:29 +09:00
Hector Martin
39d1d9a904 payload: Only load DTs that are compatible with this device
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-18 18:26:27 +09:00
Hector Martin
120ac16493 payload: Support setting boot-args as a payload.
Just use "boot-args=foo bar baz\n" as a payload

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-18 18:18:01 +09:00
Hector Martin
097c2f752a payload: Make vars static
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-18 18:17:42 +09:00
Hector Martin
ef83f62d0e cpufreq: New module to initialize CPU p-states
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-18 17:34:40 +09:00
Hector Martin
4fa0200053 main: Export chip_id as a global
Some things need to be chip-specific, as the ADT isn't generic enough.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-18 17:33:49 +09:00
Hector Martin
6d9bc7fa8f pmgr: Unify defs with Linux, clean up device relationships.
This enables parent devices that are required by active child devices,
because iBoot leaves behind some broken dependencies.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-18 16:52:59 +09:00
Hector Martin
5787eb2d64 hv_exc: Fix global IPIs
Reported-by: Joey Gouly <joey.gouly@arm.com>

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-18 13:26:28 +09:00
Hector Martin
72788291e6 memory: Map all RAM to the top, minus carveouts
This unbreaks dcp.py and other things that need to access reserved
regions. This way we don't have to start doing manual MMU maps, but
we're still safe from SErrors caused by hitting TZ carveouts.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-16 01:00:33 +09:00
Hector Martin
1444c93a24 proxy: Add P_MMU_INIT_SECONDARY
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-15 23:44:12 +09:00
Hector Martin
da024ffbd8 memory: Only map available RAM
We saw some crazy speculation running in the HV breaking things by
reading from invalid RAM, so let's actually map only what's available.
For now we do map all lowmem as we haven't seen SErrors there yet, but
we stop at the high boundary.

Fixes: #97

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-15 23:44:12 +09:00
Danny Lin
37e8f425bf smp: Fix smp_call macros with fewer than 4 arguments
The full 4-argument version of smp_call is smp_call4; smp_call doesn't
exist.

Signed-off-by: Danny Lin <danny@kdrag0n.dev>
2021-10-11 12:42:31 +09:00
Hector Martin
e1515b4376 i2c: Make error paths wait for bus in i2c_smbus_read
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-10 23:49:51 +09:00
Hector Martin
64cb9892b1 tps6598x: Correctly clear all IRQ flags
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-10 23:18:04 +09:00
Hector Martin
675f11dc59 tps6598x: Get rid of TPS_WRITE_DELAY
This was a poor workaround for the broken i2c code.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-10 23:16:26 +09:00
Hector Martin
d20a79435c i2c: Fix waiting for read transactions
We weren't waiting until the STOP after reads, causing borkage.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-10 23:15:32 +09:00
Hector Martin
11ba4a0aac hv: format fix
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-03 00:30:42 +09:00
Hector Martin
b9f1eb29e9 kboot: Only try to parse actual CPUs in /cpus
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-10-03 00:28:08 +09:00
Hector Martin
2736f0dd07 hv: Transfer ACTLR_EL1 (not just EL2) to secondaries
Also capture config at cpu0 guest entry time, to make sure we don't
carry over guest changes to EL1 regs after that.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-24 10:57:27 +09:00
Hector Martin
5eed8f674d hv_vm: Fix guest SError handling
This was broken, but somewhat masked by another bug in hv_vm.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 22:17:52 +09:00
Hector Martin
56c3d93787 hv_exc: Enable SErrors in the hypervisor
This finally works properly now

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 21:18:13 +09:00
Hector Martin
78cf104b1f hv_vm: Guard emulated read/writes to catch SErrors/aborts
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 21:18:13 +09:00
Hector Martin
4f92a77efd exception: Allow guarding SError exceptions
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 21:18:13 +09:00
Hector Martin
25bc815821 hv: Store exception info regs on entry, and use it
This is the second part of allowing nested exceptions

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 21:18:13 +09:00
Hector Martin
607464f8b0 proxy/uartproxy/hv_asm: Add syncs to flush SErrors
This makes sure any pending memory ops that might trigger an
asynchronous SError do so here, and not later. This fixes SErrors
breaking proxy ops.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 20:31:52 +09:00
Hector Martin
d44d0a4f16 Revert "hv_asm: Unmask SErrors inside the HV"
This reverts commit bb7c8ad3c5.

This is broken.
2021-09-21 20:30:07 +09:00
Hector Martin
bce239b36f exception: Make space in the stack for full exception context
This is step 1 of the rework to make reentrant exceptions work

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 20:29:19 +09:00
Hector Martin
a16731e8b3 hv_exc: Avoid delivering spurious HV-triggered IPIs to the guest
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 17:13:03 +09:00
Hector Martin
098d394a5c exception: Handle Fast IPIs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 13:33:23 +09:00
Hector Martin
0e3770ca47 hv, m1n1.hv: Add cpu() command to switch CPU contexts
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 13:18:06 +09:00
Hector Martin
977cbdf4f8 hv_exc: New time accounting around Python callbacks
This does an explicit hypervisor rendezvous. It's not great because it
introduces spurious guest IPIs, but xnu doesn't seem to care...

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 13:17:00 +09:00
Hector Martin
64dab94821 hv_aic: Use aic.h instead of just declaring aic_base
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 00:42:19 +09:00
Hector Martin
945b75a0f8 hv_aic: Fix regression introduced by 4b4ae3ab
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-21 00:40:04 +09:00
Hector Martin
ffacef41ee iodev, exception: Remove gratuitous UART usage
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-19 22:33:20 +09:00
Hector Martin
edb32c48a2 smp: Allow switching back to wfe for the smp spinloop
This is what Linux expects, so we'd better do it in kboot.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-19 02:17:04 +09:00
Hector Martin
c3ba77ce16 hv_exc: Handle SYS_IMP_APL_CYC_OVRD in the fast path
m1n1 now uses this for SMP, and due to wfi FIQ leakage from the HV
timer this gets spammed thousands of times per second. Handle it in
the HV directly.

Fixes: #107

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-18 22:33:28 +09:00
Hector Martin
2d952752db proxy: Add smp_wait() to the proxy
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-17 15:25:34 +09:00
Hector Martin
b1bc4023dc smp: Use wfi and put idle CPUs in deep sleep
This allows a single active P-Core to boost to 3.2GHz.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-17 00:15:52 +09:00
Hector Martin
10880ca1a6 hv_vm: Unbork >32bit mmiotrace
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-16 03:01:10 +09:00
Hector Martin
09a44e5a92 hv_exc: Disable stolen time accounting
This doesn't work with SMP.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:32:57 +09:00
Hector Martin
509481d5d5 hv: Add SMP support
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:32:57 +09:00
Hector Martin
184a516367 hv_exc: Make IPI/IRQ/timer/PMC emulation storage per-CPU
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:26:14 +09:00
Hector Martin
56b54a6641 hv_vm/hv_exc: Add cpu_id to exception & mmiotrace structs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:24:37 +09:00
Hector Martin
a13a23d5fa iodev: Add a spinlock and allow console for secondaries
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:24:37 +09:00
Hector Martin
cd59d39686 memory.h: Add mmu_active() function
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:24:37 +09:00
Hector Martin
c690eb1c9d utils: Make spinlocks reentrant
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:24:37 +09:00
Hector Martin
787c46e8c7 hv_exc: Add a Big Hypervisor Lock
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:24:37 +09:00
Hector Martin
d53b40da48 memory: Add mmu_init_secondary() to init MMU for secondaries
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:24:37 +09:00
Hector Martin
52f432f0f6 memory: Add guard pages at the end of stacks
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:24:37 +09:00
Hector Martin
2f8beb02b4 cpu_regs.h: Add more registers needed for HV config
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:24:37 +09:00
Hector Martin
8752d5fbba gxf: Per-CPU gxf stack
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:24:37 +09:00
Hector Martin
368b48a365 hv_wdt: Make HV WDT CPU configurable and WDT optional
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:24:37 +09:00
Hector Martin
6c186f8468 hv_asm: Move SP saving to a variable, per-CPU
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:24:37 +09:00
Hector Martin
c317b73b8c utils: Add a basic spinlock implementation
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:19:37 +09:00
Hector Martin
bb7c8ad3c5 hv_asm: Unmask SErrors inside the HV
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:19:37 +09:00
Hector Martin
90b10ef9f7 smp: Add smp_id() and use TPIDR_EL[12] to keep the SMP ID
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 23:19:37 +09:00
Hector Martin
571a19c9a3 smp: Align secondary_stacks & export to header
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 22:00:29 +09:00
Hector Martin
4acc3d7c7f hv_vm: Mask off operand size for store emulation
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-09-15 17:42:03 +09:00
Mark Kettenis
4e88360eb1 main: Fix compiler error
Older versions of GCC throw a "initializer element is not contstant"
error.  Fix this.

Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
2021-09-03 10:59:46 +09:00
Hector Martin
fa50bb6474 fb: Do not restore logo when using kboot
Also don't clear the whole screen, only the console section so the logo
is glitchless.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-08-31 14:10:52 +09:00
Mark Kettenis
77b0cdb7c9 pcie: Only initialize ports that are actually present
The macbook pro and macbook air only have a single PCIe port

Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
2021-08-31 02:07:24 +09:00
Hector Martin
56799d34e8 usb_dwc3: Properly handle CDC status separately per pipe
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-08-30 23:53:05 +09:00
Pip Cet
b7ad368158 uart: avoid relying on UTRSTAT_RXD == 1
Signed-off-by: Pip Cet <pipcet@gmail.com>
2021-08-24 22:11:19 +09:00
Pip Cet
6a92a3e71a iodev, usb_dwc3: cosmetic fixes
Signed-off-by: Pip Cet <pipcet@gmail.com>
2021-08-24 22:11:19 +09:00
Pip Cet
9a5707889a hv_vuart: Avoid reporting bytes in the RX buffer when it's empty.
Signed-off-by: Pip Cet <pipcet@gmail.com>
2021-08-24 21:07:43 +09:00
Hector Martin
19b16f77d8 startup: Split density field from depth print
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-08-24 21:00:50 +09:00
Hector Martin
017f050fff hv_vuart: Implement RX & enough to support Linux
This works to get to a serial shell on Linux, and to use m1n1-as-LV1
proxyclient with M1N1DEVICE=/dev/m1n1-sec

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-08-23 17:02:28 +09:00
Hector Martin
4b4ae3ab90 aic: Add trivial AIC scaffolding, move regs to aic_regs.h
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-08-23 17:01:33 +09:00
Hector Martin
18eb02fa92 uart: Add more UART reg defines and use them
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-08-23 17:00:53 +09:00
Hector Martin
31bf2b5ac9 iodev: Make iodev_can_read() return the queued byte count
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-08-23 17:00:14 +09:00
Hector Martin
3bdf036161 Revert "cpio: add functions to create cpio images"
This reverts commit cd4b563a31.
2021-08-23 15:27:37 +09:00
Hector Martin
68c1f1c1a6 Revert "kboot: move SEPFW to initrd before booting"
We've decided this needs to go via reserved-ranges, not in the
initramfs.

This reverts commit 6afe9ebaf9.
2021-08-23 15:27:20 +09:00
Hector Martin
f8110dd409 hv_exc: Handle M1RACLES mitigation here due to 12.0 spam
macOS 12.0 added a silly ineffective "mitigation" that clears the
register on every context switch. This doesn't actually mitigate
anything, but it does make this sysreg trap performance-critical,
so we have to move its handling into the C side.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-08-14 16:30:18 +09:00
Hector Martin
a18033e569 main: Add a searchable tag to find the m1n1 version
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-08-12 16:13:33 +09:00
Alyssa Rosenzweig
a52330809b startup: Prettyify video depth dump
Use the right unit. for rgb10x2, this prints "30bpp" instead of "0x1E".

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
2021-08-03 13:48:28 +09:00
Sven Peter
856a9dbd1b usb: don't initialize more than once
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-07-10 16:29:05 +09:00
Sven Peter
5d2315a865 uartproxy: flush iodev before shutting down
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-07-10 16:29:05 +09:00
Sven Peter
e0d889fac1 hv: add proper single stepping support
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-07-09 15:52:40 +09:00
Sven Peter
6afe9ebaf9 kboot: move SEPFW to initrd before booting
Bootstrapping SEPOS requires to setup a scratch buffer and
will have to be handled by the final OS. We pass along
the firmware image by appending it to the initramfs.

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-07-09 15:40:11 +09:00
Sven Peter
cd4b563a31 cpio: add functions to create cpio images
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-07-09 15:40:11 +09:00
Hector Martin
95aeb7bb83 hv: Use hv_write_hcr() for initial configuration
This might make things work if GXF is already enabled, maybe.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-06-22 01:15:00 +09:00
Janne Grunau
98076ef693 usb: disable tps6598x interrupts
Restore the interrupt masks on chainload or HV guest start. The
interrupt mask is not restored on the USB-C port used by the hypervisor.
This prevents an interrupt storm in the guest when the other USB-C port
is exposed to the guest. Both tps6598x share unfortunately an interrupt
line.

Signed-off-by: Janne Grunau <j@jannau.net>
2021-06-18 14:26:54 +09:00
Hector Martin
7e5054548a hv_vm: Rename SPTE_SYNC_TRACE to SPTE_TRACE_UNBUF
It's not really synchronous, it just flushes USB buffering.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-06-15 16:10:06 +09:00
Hector Martin
a664bd5d55 hv_vm: Minor fixes to pagetable code
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-06-15 15:47:44 +09:00
Hector Martin
7ff613665b hv_asm.S: Add comments to the vectors
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-06-15 15:47:24 +09:00
Hector Martin
5751fa0019 hv_vm: Remove broken hv_max_proxy_hook
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-06-15 15:47:07 +09:00
Mark Kettenis
d33d7ba89d kboot: Provide MAC addresses in device tree
Read the MAC addresses from the ADT and store them in
"local-mac-address" properties on the relevant nodes in the FDT.
This relies on appropriate aliases in the provided FDT, which
matches how U-Boot provides MAC addresses on embedded targets.

Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
2021-06-15 15:27:18 +09:00
Sven Peter
9e061c2b50 usb_dwc3: shutdown the DART as well when shutting down usb
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-06-10 15:41:33 +09:00
Janne Grunau
88275b5cb5 hv: add AIC interrupt tracing
Implemented by MMIO tracing of AIC's event register. Proposed by pipcet.

Signed-off-by: Janne Grunau <j@jannau.net>
2021-06-10 15:41:02 +09:00
Sven Peter
3e807d6686 dart: shutdown to bypass mode
This allows payloads to use DMA for anything that's not PCIe
even without a DART driver. It also restores the DART registers
the state the were left by iBoot.

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-06-10 00:00:37 +09:00
Janne Grunau
4b5c016368 hv: disable PMU counters inside the hypervisor
Signed-off-by: Janne Grunau <j@jannau.net>
2021-06-09 19:47:20 +09:00
Janne Grunau
d61bf13cb0 hv: shadow perf monitor IRQ mode and state
The development Mac OS kernel panics if the PMCR0 sysreg is in an
unexpected state. To avoid that the hypervisor needs to shadow the
interrupt mode and interrupt active flag after it mask the PM FIQ.
Mac OS reads and writes frequently from PMCR0 and PMC 0/1 so handling
in m1n1 is preferred over Python.

Signed-off-by: Janne Grunau <j@jannau.net>
2021-06-09 19:47:20 +09:00
Sven Peter
9529ec2b4f usb: add hpm_init and split usb_init and usb_iodev_init
This allows to bringup the USB PHY and the HPM for the
payload without having to initialize the CDC ACM driver
at the same time.

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-06-09 19:45:38 +09:00
Sven Peter
d2b619957c tps6598x: add support for the USB PD chip
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-06-09 19:45:38 +09:00
Sven Peter
103100bb42 i2c: add i2c support
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-06-09 19:45:38 +09:00
Hector Martin
a175b6d159 proxy: Add reboot() call to hard reboot the system
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-06-04 15:09:11 +09:00
Hector Martin
393089f076 hv_exc: Also pass through (E)HID4, since it's noisy
This seems to be poked every time the kernel does a specific kind of
dcache flush...

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-30 03:37:12 +09:00
Hector Martin
f1cfe27e31 hv: Use AFSR_GL1 when in guarded mode.
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-30 03:34:17 +09:00
Hector Martin
cd5a00ec87 uartproxy: Use only appropriate iodevs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-30 02:11:10 +09:00
Hector Martin
c794ea6dc2 hv_vuart: Make compatible with xnu and enable
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-30 01:39:26 +09:00
Hector Martin
ccc2d0b450 usb_dwc3: Implement CLEAR FEATURE, tweak things
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-28 17:52:48 +09:00
Hector Martin
4195b09c41 hv_wdt: Remove dead include
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-28 04:30:13 +09:00
Hector Martin
775902112d hv.py: Add M1RACLES mitigation
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-28 02:41:17 +09:00
Hector Martin
fe651cb9d7 hv_vm: Add more load/store emulation
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-28 02:13:23 +09:00
Hector Martin
12a7a0f1bb hv_exc: Allow the guest to see a bit of stolen time
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-28 02:13:23 +09:00
Hector Martin
fe2e89573e hv: Move break handling to hv_tick(), properly poll
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-28 02:13:23 +09:00
Hector Martin
66fc157e94 fb: Improve visuals
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-28 00:45:05 +09:00
Hector Martin
db0252a1d6 hv_exc: Steal time from the guest during HV exceptions
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-28 00:38:42 +09:00
Hector Martin
dd443d2c2c cpu_regs: Fix missing IMP_APL prefixes
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-28 00:38:11 +09:00
Hector Martin
0265edebba hv_exc: Add ACTLR_EL1 sysreg forwarding
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-28 00:37:48 +09:00
Hector Martin
a21e46031e kboot: Only initialize PCIe when booting a kernel payload
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-28 00:04:52 +09:00
Hector Martin
bd8ae6f4f6 pcie: Add a pcie_shutdown() function and call it on hv init
Guests don't like it if PCIe is initialized already

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-28 00:03:11 +09:00
Hector Martin
77a36a7d34 utils,proxy: Add basic SIMD register fetch and mutation support
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-27 22:57:25 +09:00
Hector Martin
ae55e1c5dc hv_vm: Add debug breadcrumbs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-27 22:05:23 +09:00
Hector Martin
f792b128c5 hv_vm: Suspend watchdog around mmiotrace event writes
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-27 22:05:23 +09:00
Vincent Duvert
3d1747466b Add an option to disable checksumming if possible
* Introduce feature flags which allows the proxy and m1n1 to determine which
features they have in common.
* Add a feature flag that disables checksumming (by replacing checksums with
constant values) for the data packets exchanged by REQ_MEMREAD, REQ_MEMWRITE
and REQ_EVENT. The feature is enabled if m1n1 supports it; checksumming is kept
enabled for UART communication.
* To ensure no packet loss when checksumming is disabled, an extra sentinel
value is added after the exchanged data for memory read/write operations.

Signed-off-by: Vincent Duvert <vincent@duvert.net>
2021-05-27 21:34:37 +09:00
Hector Martin
85411d1714 hv_vm: Add support for 128-bit ops, stp/ldp, fix some emu bugs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-27 21:29:58 +09:00
Hector Martin
bfe8c94c47 hv_wdt: Add hypervisor watchdog on secondary core
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-27 21:28:43 +09:00
Hector Martin
c93f856c92 exception: Only enable IRQs on the primary core
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-27 21:28:43 +09:00
Hector Martin
0a91cc2b08 gxf: Make gl_call work with GXF or SPRR locked
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-27 21:28:43 +09:00
Hector Martin
a5a974791b hv: Support handling GL2 exceptions
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-27 21:28:43 +09:00
Hector Martin
b1e09ad509 exception,gxf: Turn off PAN on exception entry
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-27 21:11:14 +09:00
Hector Martin
aa72f50e50 iodev: Do not print leading * for empty buffer prints on alt path
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-27 21:10:00 +09:00
Hector Martin
0786894201 uart: Add uart_printf()
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-27 21:09:48 +09:00
Hector Martin
532b43f0a4 utils: debug_printf: Use vsnprintf instead of vsprintf
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-27 21:09:15 +09:00
Hector Martin
81808da562 hv_exc: Set the step timer to 100 cycles
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 20:12:20 +09:00
Hector Martin
e92e075fba hv_exc: Add IPI and guest timer FIQ virtualization
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 20:12:20 +09:00
Hector Martin
75f206e65c hv_exc, hv.py: Add support for interrupting guest with ^C
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 20:12:20 +09:00
Hector Martin
1ce8d8b706 hv: Add hv_write_hcr() to handle GXF
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 20:12:20 +09:00
Hector Martin
2e014f58fa hv: Implement a periodic hypervisor ptimer and use vtimer for stepping
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-05-25 20:12:20 +09:00
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
Sven Peter
35007b700e proxy: add dart ops
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-15 01:36:29 +09:00
Sven Peter
de0456b9a5 proxy: add fb console console ops
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-14 18:11:37 +09:00
Sven Peter
5d4067642e fb: add earlycon to capture messages before fb_init
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-14 18:11:37 +09:00
Sven Peter
2873aed75a memory: speed hack: scroll fb console before shutting down the MMU
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-14 18:11:37 +09:00
Sven Peter
fd2deed39b fb: add framebuffer console
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-14 18:11:37 +09:00
Sven Peter
819b16fbe4 fb.c: minor cleanup
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-14 18:11:37 +09:00
Sven Peter
05e7306bf9 fb console: add Source Code Pro font
This font is licensed under the OFL-1.1 License and copyright:

Copyright 2010-2019 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'.
All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries.

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-14 18:11:37 +09:00
Sven Peter
f80933a7d3 utils.h: add is_primary_core
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-14 18:11:37 +09:00
Sven Peter
1a04590ed3 utils.h: add min and max
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-14 18:11:37 +09:00
Hector Martin
9fc3f0c230 exception: Print exception context for FIQ
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-14 17:48:02 +09:00
Hector Martin
0df6db324b timer_test.py: More exhaustive tests
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-04-14 17:48:02 +09:00
Sven Peter
8efff1b0ab dart: add code to setup the DART iommu
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-14 17:40:07 +09:00
Sven Peter
1e247107aa types: add SZ_2K/SZ_16K/SZ_1M
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-14 17:40:07 +09:00
Sven Peter
1314a426e2 proxyclient: add PMGR ops
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-11 05:26:29 +09:00
Sven Peter
b31e1265ff pmgr: add functions to enable/disable clocks
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-11 05:26:29 +09:00
Sven Peter
95b1cb39fc utils.h: add poll32
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-11 05:26:29 +09:00
Sven Peter
bf3830ee6d utils.h: add dma_mb,dma_rmb,dma_wmb
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-11 05:26:29 +09:00
Sven Peter
8aa3c69a2d tunables: add tunables_apply_local_addr
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-08 20:32:12 +09:00
Sven Peter
a17e64f1e2 tunables: add proxy ops
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-08 20:32:12 +09:00
Sven Peter
d73276b0bc tunables: add initial version.
There are at least two types in the ADT related to USB,
but there's a decent chance that there are even more
required for other devices:

 * A simple tunable that applies to a whole device node
   and all its MMIO ranges specified in the "reg" property.
   This one seems to just be mask32.

 * A slightly more complex tunable that applies to a single
   MMIO range specified in the "reg" property. So far I've
   only seen 32 bit masks but the format looks like it should
   also support 8,16 and 64 bit masks.

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-04-08 20:32:12 +09:00
Hector Martin
35f2b2435e kboot: reserve m1n1 in memory
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-03-15 02:26:13 +09:00
Hector Martin
efa4452a47 Fix libc header dependencies
Turns out we had a bunch of silly dependencies on libc headers that are
not included with freestanding compilers. Fix all this and change the
CFLAGS to exclude libc headers and only include the built-in compiler
path.

Add our own versions of assert.h, errno.h, limits.h, and move malloc.h
and string.h together into a new path used as -isystem, so these headers
can be included using #include <>.

Remove a bunch of other dependencies in third-party code.

Add a strnlen function.

Disable building the libfdt overlay code for now, as it needs a strtoul
implementation. We can throw that in if/when we decide to use overlays.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-03-08 01:31:14 +09:00
Hector Martin
ce2038c59c memory: use tlbi vmalle1is
This works at both EL1 and EL2(with VHE) and seems to do the right
thing.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-03-04 22:39:26 +09:00
Hector Martin
b8349819fe Implement calling code as EL1
This works by clearing HCR_EL2.TGE, and then doing essentially the same
thunk/return dance as for EL0 calls. However, since most EL1 exceptions
are not routed to EL2, we install hypercall vectors in EL1 to forward
them to EL2, and then short circuit the exception return to whatever
triggered the original exception.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-03-04 22:10:37 +09:00
Hector Martin
f669237c2a start.S: clean up some junk
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-03-04 21:27:25 +09:00
Hector Martin
16cff51bd4 exception,memory: s/EL2/EL1/
Since we're in VHE mode, we can pretend to be in EL1 - but this will
allow us to really run in EL1 if we want to in the future.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-03-04 20:31:36 +09:00
Hector Martin
4282cd0578 exception: size tables properly, work around overeager clang-format
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-03-04 19:52:53 +09:00
Hector Martin
d5acb000f2 kboot: add support for KASLR and bootloader randomness
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-03-04 19:47:39 +09:00
Hector Martin
8e4b99d75a memory: reformat and shorten MAIR_INDEX to MAIR_IDX
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-03-04 19:47:37 +09:00
Hector Martin
3872b1a7da exception: implement el0_call to run code as EL0
This lets us test register access and other features from EL0.

No serious attempt at security is made, but at least EL0 runs off of a
separate stack and can return to EL2 at any time with `brk`; we can
easily implement a guard mode to break straight to EL2 on exception
later if needed.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-24 21:48:12 +09:00
Hector Martin
73a85be2b8 memory: prepare for EL0 support
Enable EL0 access to MMIO/etc, but not main RAM, because AArch64
architecturally enforces EL0w ^ EL2x.

Instead, create an alias of main RAM to grant EL0 full permissions,
at 0x80_0000_0000.

Grant EL0 full access to MMIO stuff, since EL2 will never execute
from there.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-24 21:48:12 +09:00
Hector Martin
b5cbf7360e exception: handle PMC FIQs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-18 17:55:55 +09:00
Hector Martin
cf640de6db utils.h: add BIT() macro
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-18 17:55:55 +09:00
Hector Martin
17aca31498 utils.h: move reg_{clr,set,mask} here from chickens.c
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-18 17:55:55 +09:00
Hector Martin
86a7d9c0f3 cpu_regs.h: s/SYS_/SYS_APL_/
This synchronizes the register naming convention with Linux

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-18 17:55:55 +09:00
Sven Peter
f3eed1c7d7 MMU: correctly map MMIO/PCIe ranges
Previously all MMIO was mapped twice with different attributes
which may or may not lead to strange behaviour when the same
physical range is accessed from both mappings.

We now have a better idea which ranges require nGnRE and nGnRnE
and can just do it correctly instead.

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-02-18 16:16:55 +09:00
Sven Peter
870fead39c proxyclient: add ops for writeread{8,16,32,64}
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-02-18 16:12:28 +09:00
Sven Peter
1ccf2e2af5 utils.h: add writeread{8,16,32,64}
These functions all perform a store direcly followed by a load.
This is useful to e.g. useful to find busy bits which might
already be cleared a few cycles after a write.

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-02-18 16:12:28 +09:00
Sven Peter
24938db17a MMU: use alle2 instead of vmalls12e1is to invalidate TLBs
I can't remember why I used vmalls12e1is but this leads to
the following bug:

  1. Load m1n1 with normal MMU setup
  2. Disable all mappings, recompile and chainload to that m1n1
  3. Everything will work fine for a while even though it should explode
     when enabling the MMU.

This happens becuse there are still stale TLB entries in some cache.

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-02-15 01:37:39 +09:00
Hector Martin
d46d51d7ed exception: fix vtimer FIQ masking
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-11 01:35:23 +09:00
Hector Martin
063b9a1d27 exception: Add GUARD_SILENT feature to suppress logs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-11 00:55:59 +09:00
Hector Martin
eab71ee92b fb, kboot: handle Retina flag correctly
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-06 22:27:45 +09:00
Hector Martin
5dbc82a9ee payload: add support for booting in-line payloads
Usage:

$ cat m1n1.macho Image.gz apple-j274.dtb initramfs.gz \
    > m1n1-payload.macho

That's it.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-06 16:44:10 +09:00
Hector Martin
93bad96311 minilzlib: fix support for non-CRC32 checksum types
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-06 16:44:10 +09:00
Hector Martin
61e2c36ef5 tinf, minzllib: support unknown input sizes
This can be used when the input file size is unknown: the decompression
functions will keep track of it and return it to the caller instead.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-06 16:44:10 +09:00
Hector Martin
0cd328214c exception: handle all 4 available timer FIQs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-06 16:44:10 +09:00
Hector Martin
5aff13c404 proxy: add missing SPDX header
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-06 16:44:10 +09:00
Hector Martin
5e5627cd0b clang-format: Add include block configs, reformat
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-06 16:44:10 +09:00
Ariel Machado
476182e1f8 utils.h: Fix 'asm-operand-widths' warnings with clang
Signed-off-by: Ariel Machado <ariel@fe.up.pt>
2021-02-06 12:13:29 +09:00
Hector Martin
8691fcee8a kboot: fix fb debug print
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-05 03:49:20 +09:00
Hector Martin
234a511e35 kboot: add spin-table and SMP support
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-05 02:58:08 +09:00
Hector Martin
aaab2c6ca1 chickens: set WFI mode to clockgate only
This preserves CPU registers.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-05 02:58:08 +09:00
Hector Martin
e35ef6eb8c smp: fix IRQs on secondary CPUs
Seems one of the registers is some kind of system-level CPU spinup flag,
without which the CPU runs but the rest of the system thinks it's still
dead.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-05 02:58:08 +09:00
Hector Martin
cb7e7f7918 exception.c: print MPIDR with IRQs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-02-05 02:58:08 +09:00
Hector Martin
96d133e854 mmu: map device memory as non-executable
This fixes the random SErrors after returning from a page fault. Turns
out the M1 was randomly deciding to speculate an instruction fetch from
address 0, triggering a fabric error.

Quoting the ARM ARM:

"Hardware does not prevent speculative instruction fetches from a memory
location with any of the Device memory attributes unless the memory
location is also marked as Execute-never for all Exception levels.

This means that to prevent speculative instruction fetches from memory
locations with Device memory attributes, any location that is assigned
any Device memory type must also be marked as execute-never for all
Exception levels. Failure to mark a memory location with any Device
memory attribute as execute-never for all Exception levels is a
programming error."

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-31 13:42:48 +09:00
Hector Martin
b65e2ca0e4 mmu: also set up high-VA translation
Just an alias

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
b2ef461114 get rid of another warning pragma
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
919e3fb64a exception: use 64bit print types
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
65c0632ae7 exception: do not reboot on SError
This may or may not go well depending on the problem... but let's see
what happens.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
201d7d9a1e exception: also print FAR_EL2
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
040cb9d6fd exception: enable SError
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
bbe47b2f75 Move Apple ARM register definitions to cpu_regs.h
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
7807dad7bc exception: add barriers around stuff
This CPU really likes to speculate...

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
1f99c17fef exception: clear L2C error status after exception
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
5dd63e41a1 exception: decode exception type on dumps
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
6dde40b05c exception: introduce recovery from synchronous exceptions
Use this to recover from address faults in the proxy. Also print out L2
subsystem fault info.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
d31eab5f87 chickens: do not disable L2 subsystem errors
These mean real problems, let's actually fix them instead of shoving
them under the carpet.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
4167a18a64 utils: move sys_reg and is_ecore() to utils.h
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 22:00:00 +09:00
Hector Martin
2df212bf5c adt: use ADT_FOREACH macros internally
This fixes some bugs too.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 03:15:00 +09:00
Hector Martin
dc2b7b3bb4 startup: clear bss section
iBoot does this for us, but this is for the benefit of chainload.py and
other dump loaders that may not.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 03:03:03 +09:00
Hector Martin
b673db78c3 minilzlib/xzstream.h: get rid of warning pragma
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 03:03:03 +09:00
Hector Martin
74307af0df kboot: add proper kernel boot & DT manipulation code
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 01:37:09 +09:00
Hector Martin
ad93d14ee5 chickens: clear SYS_L2C_ERR_STS
It's unclear why this is necessary, but it fixes some strange crashes

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 01:37:09 +09:00
Hector Martin
c057775ab9 adt: add ADT_FOREACH_PROPERTY
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 01:37:09 +09:00
Hector Martin
891bc5592e utils.h: fix msr/mrs macro expansion
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 01:37:09 +09:00
Hector Martin
46a46da111 string: add memmove, strrchr, strncmp
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 01:37:09 +09:00
Hector Martin
b82c0072e7 utils.h: mark reboot() noreturn
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 01:37:09 +09:00
Hector Martin
d280157289 libfdt: actually add libfdt
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-30 01:37:09 +09:00
Hector Martin
986c6730e9 Add heapblock and dlmalloc for managing memory
heapblock is a simple `sbrk` style implementation, also useful as an
"endless" decompression buffer. dlmalloc is used on top as a malloc
implementation.

This also changes how the Python side manages its heap. We still use a
python-side malloc implementation (since this is faster), and we put the
Python heap at the m1n1 heap + 128MB, without allocating it.
Hopefully this should never step on anything m1n1 neads, and avoids
having to manage freeing across Python script calls.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-29 16:25:15 +09:00
Hector Martin
f3d0a58f42 proxy: add mmu_shutdown call, use it for linux.py
I saw at least one SError crash on Linux after doing this, but can't
repro; unclear if related to the MMU changes or not...

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-29 00:36:46 +09:00
Hector Martin
c3c6e4e8f9 smp: add scaffolding and proxy funcs for cross-CPU calls
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-29 00:36:46 +09:00
Hector Martin
e97b104125 main: do not spin up SMP
This breaks reloads, we shouldn't do this until we need to.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-28 23:48:35 +09:00
Hector Martin
eae3d06e85 smp: fix totally broken stack setup
This worked by accident before...

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-28 23:48:35 +09:00
Hector Martin
11753f9983 start.S: probe the stack after init
This makes it obvious when the stack is broken.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-28 23:48:35 +09:00
Hector Martin
cffc423024 smp: use ADT data instead of hardcoded info
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-28 23:48:35 +09:00
Hector Martin
b4822eb02c adt: improve APIs for iterating through child nodes
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-28 23:48:35 +09:00
Hector Martin
db902ce01f wdt: move WDT disable code to wdt.c & use ADT regs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-28 23:48:35 +09:00
Hector Martin
3733ea153f smp: fix broken spin-table routine
Only read target_cpu once, then keep a pointer our spin table.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-28 23:48:35 +09:00
Hector Martin
ba1162e322 adt: add an API for resolving reg properties
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-28 23:48:35 +09:00
Sven Peter
9242c820ae MMU: clean and invalidate all caches after shutdown
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-01-28 23:20:15 +09:00
Sven Peter
2f84b33ba8 MMU: add cache operations by set/way
this embeds a slightly modified file taken from
arm-trusted-firmware.

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-01-28 23:20:15 +09:00
Sven Peter
f244919c98 MMU: add initial support
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-01-28 23:20:15 +09:00
Sven Peter
63fad7e3e2 utils.h: add panic() macro
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-01-28 23:20:15 +09:00
Hector Martin
d762391a68 Add code to spin up secondary CPUs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-28 16:06:12 +09:00
Hector Martin
65276fdd3f utils.h: add memory clobbers
We mostly use read32/write32 and friends to poke hardware registers,
which might have side effects on RAM, so just make everything a memory
clobber to avoid potential issues.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-28 16:06:12 +09:00
Hector Martin
0145830772 chickens: add firestorm chicken bits
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-28 16:06:12 +09:00
Hector Martin
344c84da17 clang-format everything
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-28 16:06:12 +09:00
Ariel Machado
51bf5c870a adt: replaces int to u32 and size_t for unsigned values.
Makefile: increases compiler warnings

Signed-off-by: Ariel Machado <ariel@fe.up.pt>
2021-01-25 19:18:30 +09:00
Hector Martin
cc34ace39a startup: Implement setting CPU chicken bits for Icestorm
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-25 19:11:54 +09:00
Hector Martin
58b643df77 clang-format a few missed things
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-25 17:25:49 +09:00
Hector Martin
a637b77816 Move minlzma.h -> src/minilzlib
This stops clang-format from running on this header.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-25 17:25:44 +09:00
Hector Martin
14db0224af Add config.h for build-time config options
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-25 17:24:29 +09:00
Hector Martin
674a82a2bb aic_test: UART IRQ testing stuff
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-23 22:42:59 +09:00
Hector Martin
63319ed348 utils: implement udelay()
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-23 22:42:25 +09:00
Hector Martin
009f04775e utils: add __assert_fail function to make assert() work
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-23 22:42:25 +09:00
Hector Martin
ee12d053a9 proxy: add XZ and GZ decompression functions and code
This embeds tinf and minlzma.

Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-23 22:42:23 +09:00
Ferdinand Bachmann
afc5813635 exceptions: fix clang warning for msr arg
Signed-off-by: Ferdinand Bachmann <theferdi265@gmail.com>
2021-01-23 22:09:22 +09:00
Ferdinand Bachmann
8511d9ff74 start.S: clang compat, don't use '\r' in asm files
Signed-off-by: Ferdinand Bachmann <theferdi265@gmail.com>
2021-01-23 22:09:22 +09:00
Ferdinand Bachmann
75c3cd39d4 start.S: don't use caller-saved registers accross calls
Signed-off-by: Ferdinand Bachmann <theferdi265@gmail.com>
2021-01-23 22:09:22 +09:00
Ferdinand Bachmann
6ecf5d9fb5 types.h: remove redundant definition of NULL (defined in stddef.h)
Signed-off-by: Ferdinand Bachmann <theferdi265@gmail.com>
2021-01-23 22:05:37 +09:00
Ferdinand Bachmann
274ea2baf2 exceptions: remove unused push_hi_regs symbol, make _exc_entry a function
Signed-off-by: Ferdinand Bachmann <theferdi265@gmail.com>
2021-01-23 22:05:24 +09:00
Hector Martin
31b6af14b2 exception.c: fix sp calculation in print_regs
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-18 01:57:27 +09:00
Hector Martin
81aaf2ed35 Basic exceptions, irq, cache mgmt support
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-17 00:49:22 +09:00
Ferdinand Bachmann
d49d0b781b adt: fix ignored qualifiers in adt_getprop_copy function prototype
Signed-off-by: Ferdinand Bachmann <theferdi265@gmail.com>
2021-01-16 05:12:48 +09:00
Sven Peter
3268aabb91 add missing const to src/adt.h
Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-01-16 02:48:22 +09:00
Sven Peter
4c4850935f change #include <string.h> to #include "string.h"
this is required to fix the following error when compiling with clang:

  CC    build/string.o
src/string.c:3:10: error: 'string.h' file not found with <angled> include; use "quotes" instead
         ^~~~~~~~~~
         "string.h"

Signed-off-by: Sven Peter <sven@svenpeter.dev>
2021-01-16 02:48:08 +09:00
Clay Freeman
b0b3548f1d Error codes should be returned as negative values
Signed-off-by: Clay Freeman <git@clayfreeman.com>
2021-01-15 12:52:34 +09:00
Hector Martin
5175c7a31b Chainloading, ADT support, misc fixes
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-15 04:04:12 +09:00
Hector Martin
b8fd8363cd Make UART proxy work
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-15 04:04:12 +09:00
Hector Martin
152c96a34a Import UART proxy
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-15 04:04:12 +09:00
Hector Martin
8af9f1eb95 Initial commit
Signed-off-by: Hector Martin <marcan@marcan.st>
2021-01-15 04:03:35 +09:00