Commit graph

65 commits

Author SHA1 Message Date
cinap_lenrek 6f9838a6a5 kernel: make Page.txtflush into an array
To avoid a MAXMACH limit of 32 and make
txtflush into an array for the bitmap.

Provide portable macros for testing and clearing
the bits: needtxtflush(), donetxtflush().

On pc/pc64, define inittxtflush()/settxtflush()
as no-op macros, avoiding the storage overhead of
the txtflush array alltogether.
2022-01-16 19:25:11 +00:00
Ori Bernstein 7efbea82c6 devssl, cpu, import, oexportfs: delete
SSL is implemented by devssl. It's extremely
obsolete by now, and is not used anywhere but
cpu, import, and oexportfs.

This change strips out the devssl bits, but
does not (yet) remove the code from libsec.
2021-12-13 02:17:02 +00:00
cinap_lenrek 20ea113790 kernel: support large 64-bit pci membars, increase pc64 VMAPSIZE to 1TB
This makes vmap()/vunmap() take a vlong size argument,
and change the type of Pci.mem[].size to vlong as well.

Even if vmap() wont support large mappings, it is nice to
get the original unruncated value for error checking.

pc64 needs a bigger VMAP window, as system76 pangolin
puts the framebuffer at a physical address > 512GB.
2021-11-26 20:51:45 +00:00
cinap_lenrek 80268af29e bcm64/sdhc: add *emmc2bus kernel parameter to set dma dram bus address
On the raspberry pi 4, depending on the chip revision,
the emmc2 controller has different dram bus address window,
so make it configurable.
2021-11-07 17:47:09 +00:00
cinap_lenrek 5484260b42 kernel: move waserror() macro to port/portfns.h 2021-10-11 11:52:37 +00:00
cinap_lenrek 8a8329ad95 bcm64: make the kernel use virtual timer counter register for cycles() 2021-07-25 14:12:17 +00:00
cinap_lenrek b7e67e9e36 kernel: page counts a ulong, not usize 2021-07-25 14:03:12 +00:00
cinap_lenrek c38fcb5dc3 arm64: use generic timer virtual counter for cycles()
We used to use performance cycle counter for cycles(),
but it is kind of useless in userspace as each core
has its own counter and hence not comparable between
cores. Also, the cycle counter stops counting when
the cores are idle.

Most callers expect cycles() to return a high resolution
timestamp instead, so do the best we can do here
and enable the userspace generic timer virtual counter.
2021-07-23 15:10:01 +00:00
cinap_lenrek c0d4498ab8 kernel: clean up Mach structure
Remove unused fields and factor common fields into a
new PMach struct in port/portdat.h.

The fields machno, splpc and proc are not moved to
PMach as they are part of the known offsets from
assembly (l.s).
2021-04-25 17:41:34 +02:00
cinap_lenrek a0404ff582 devpccard, pci: fix pccard support and handle pci expansion roms
let pci.c deal with the special cardbus controller bar0 and
expansion roms.

handle apic interrupt routing for devices behind a cardbus slot.

do not free the pcidev on card removal, as the drivers
most certanly are not prepared to handle this yet.
instead, we provide a pcidevfree() function that just unlinks
the device from pcilist and the parent bridge.
2021-03-01 17:24:54 +01:00
cinap_lenrek efcfdd23d7 bcm64: get inbound and outbound pci window base address from device tree
On the pi400, the xhci reset firmware mailbox request
assumes that the pci windows match the ones specified
in the device tree. The inbound window (pcidmawin)
also varies now depending on the amount of memory
installed.

It is all pretty ridiculous, as the firmware could as
well just read the pci controllers hardware register
to determine the window configuration and the os could
keep a nice simple 1:1 mapping (with pci dma addresses
== physical addresses).
2021-02-06 13:47:45 +01:00
cinap_lenrek 29f60cace1 kernel: avoid palloc lock during mmurelease()
Previously, mmurelease() was always called with
palloc spinlock held.

This is unneccesary for some mmurelease()
implementations as they wont release pages
to the palloc pool.

This change removes pagechainhead() and
pagechaindone() and replaces them with just
freepages() call, which aquires the palloc
lock internally as needed.

freepages() avoids holding the palloc lock
while walking the linked list of pages,
avoding some lock contention.
2020-12-22 16:29:55 +01:00
cinap_lenrek e4ce6aadac kernel: handle tos and per process pcycle counters in port/
we might as well handle the per process cycle
counter in the portable part instead of duplicating the code
in every arch and have inconsistent implementations.

we now have a portable kenter() and kexit() function,
that is ment to be used in trap/syscall from user,
which updates the counters.

some kernels missed initializing Mach.cyclefreq.
2020-12-20 22:34:41 +01:00
cinap_lenrek 1376d39ef1 kernel: add portable pcimsienable()/pcimsidisable(), disable MSI/MSI-X on pcidisable()/pcireset()
This avoids some duplication in the pci support code and
allows pcireset() to diable MSI and MSI-X interrupts
when disabling or reseting a device.
2020-11-21 16:02:21 +01:00
cinap_lenrek 4f85115526 kernel: massive pci code rewrite
The new pci code is moved to port/pci.[hc] and shared by
all ports.

Each port has its own PCI controller implementation,
providing the pcicfgrw*() functions for low level pci
config space access. The locking for pcicfgrw*() is now
done by the caller (only port/pci.c).

Device drivers now need to include "../port/pci.h" in
addition to "io.h".

The new code now checks bridge windows and membars,
while enumerating the bus, giving the pc driver a chance
to re-assign them. This is needed because some UEFI
implementations fail to assign the bars for some devices,
so we need to do it outselfs. (See pcireservemem()).

While working on this, it was discovered that the pci
code assimed the smallest I/O bar size is 16 (pcibarsize()),
which is wrong. I/O bars can be as small as 4 bytes.
Bit 1 in an I/O bar is also reserved and should be masked off,
making the port mask: port = bar & ~3;
2020-09-13 20:33:17 +02:00
cinap_lenrek 03852d9408 bcm64: increase maximum segment size to 8GB
make it possible for one process to use all
of physical memory.
2020-07-03 01:17:38 +02:00
cinap_lenrek 91994dc5d8 bcm64: handle 8GB of physical memory for raspberry pi4
widen and move the KMAP window to a new address so we can
handle the 8GB of physical memory of the new raspberry pi4.

the new memory map on pi4 uses the following 4 banks:

0x000000000	0x03e600000
0x040000000	0x0fc000000 <- soc.dramsize (only < 4GB)
0x100000000	0x180000000
0x180000000 0x200000000
2020-07-02 21:12:40 +02:00
cinap_lenrek bd23963c8f bcm64: fix usb xhci controller on pi4 8GB variant (thanks richard miller)
On the 8GB variant of the raspberry pi 4,
the eeprom chip for the xhci controller is missing and
instead loaded from sdram (by the gpu firmware).

for this, the gpu firmware needs to be notified of
the xhci controllers pci bus address (after reset)
that was assigned by our pci enumeration code.
2020-07-02 21:04:01 +02:00
cinap_lenrek 7bf5c61ea5 bcm64: bring pci code in line with the pc/pc64 2020-06-06 15:06:07 +02:00
cinap_lenrek 142bb6d5cf bcm64: use uvlong for ISAConf.port 2020-06-06 15:01:56 +02:00
cinap_lenrek c7d9da8f5a bcm64: use 64-bit uvlong physical address in vmap() 2020-06-06 15:01:20 +02:00
cinap_lenrek 04066fe973 bcm64: fix kernels cmpswap() function
spectacular bug. cmpswap() had a sign extension bug
using sign extending MOV to load the old compare
value and LDXRW using zero extension while the CMP
instruction compared 64 bit registers.

this caused cmpswap with negative old value always
to fail.

interestingly, libc's version of this function was
fine.
2020-05-07 23:27:27 +02:00
cinap_lenrek 77a7e3f8fc kernel: cleanup makefile for $CONF.$O target 2020-02-02 20:46:58 +01:00
cinap_lenrek 8d51e7fa1a kernel: implement portable userinit() and simplify process creation
replace machine specific userinit() by a portable
implemntation that uses kproc() to create the first
process. the initcode text is mapped using kmap(),
so there is no need for machine specific tmpmap()
functions.

initcode stack preparation should be done in init0()
where the stack is mapped and can be accessed directly.

replacing the machine specific userinit() allows some
big simplifications as sysrfork() and kproc() are now
the only callers of newproc() and we can avoid initializing
fields that we know are being initialized by these
callers.

rename autogenerated init.h and reboot.h headers.
the initcode[] and rebootcode[] blobs are now in *.i
files and hex generation was moved to portmkfile. the
machine specific mkfile only needs to specify how to
build rebootcode.out and initcode.out.
2020-01-26 19:01:36 +01:00
cinap_lenrek fc4bfd57d2 bcm64: add addarchfile() prototype to fns.h (for qeed) 2019-09-15 04:53:45 +02:00
cinap_lenrek acab8881bc bcm64: enter page tables in mmutop *AFTER* switching asid in mmuswitch()
there was a small window between modifying mmutop and switching the
asid where the core could bring in the new entries under the old asid
into the tlb due to speculation / prefetching.

this change moves the entering of the page tables into mmutop after
setttbr() to prevent this scenario.

due to us switching to the resereved asid 0 on procsave()->putasid(),
the only asid that could have potentially been poisoned would be asid 0
which does not have any user mappings. so this did not show any noticable
effect.
2019-09-14 14:02:34 +02:00
cinap_lenrek e4a57c8b8a bcm64: enable devgpio in kernel configuration (thanks qeed) 2019-09-02 19:38:44 +02:00
cinap_lenrek 2149600d12 kernel: catch execution read fault on SG_NOEXEC segment
fault() now has an additional pc argument that is
used to detect fault on a non-executable segment.
that is, we check on read fault if the segment
has the SG_NOEXEC attribute and the program counter
is within faulting page.
2019-08-27 03:47:18 +02:00
cinap_lenrek 128ea44a89 kernel: expose no execute bit to portable mmu code as SG_NOEXEC / PTENOEXEC, add PTECACHED bits
a portable SG_NOEXEC segment attribute was added to allow
non-executable (physical) segments. which will set the
PTENOEXEC bits for putmmu().

in the future, this can be used to make non-executable
stack / bss segments.

the SG_DEVICE attribute was added to distinguish between
mmio regions and uncached memory. only matterns on arm64.

on arm, theres the issue that PTEUNCACHED would have
no bits set when using the hardware bit definitions.
this is the reason bcm, kw, teg2 and omap kernels use
arteficial PTE constants. on zynq, the XN bit was used
as a hack to give PTEUNCACHED a non-zero value and when
the bit is clear then cache attributes where added to
the pte.

to fix this, PTECACHED constant was added.

the portable mmu code in fault.c will now explicitely set
PTECACHED bits for cached memory and PTEUNCACHED for
uncached memory. that way the hardware bit definitions
can be used everywhere.
2019-08-26 22:34:38 +02:00
cinap_lenrek 51cfe763a4 emmc: 50MHz highspeed support (from richard miller) 2019-08-25 20:02:53 +02:00
cinap_lenrek a8c50a7943 bcm64: replace emmc2 driver with richard millers sdhc driver
the new driver supports 50MHz highspeed bus mode
and uses ADMA instead of SDMA.
2019-08-25 18:45:29 +02:00
cinap_lenrek bcf988aff1 bcm64: deal with discontinuous memory regions, avoid virtual memory aliasing, implement vmap() proper
on the 2GB and 4GB raspberry pi 4 variants, there are two
memory regions for ram:

[0x00000000..0x3e600000)
[0x40000000..0xfc000000)

the framebuffer is somewhere at the end of the first
GB of memory.

to handle these, we append the region base and limit
of the second region to *maxmem= like:

*maxmem=0x3e600000 0x40000000 0xfc000000

the mmu code has been changed to have non-existing
ram unmapped and mmukmap() now uses small 64K pages
instead of 512GB pages to avoid aliasing (framebuffer).

the VIRTPCI mapping has been removed as we now have
a proper vmap() implementation which assigns vritual
addresses automatically.
2019-08-23 21:39:20 +02:00
cinap_lenrek 6280c0f17b bcm64: do not use OTP_BOOTMODE_REG to determine OSC frequency (thanks richard miller)
the register does not seem to be accessible on the Rpi 3b.
so instead hardcode oscfreq in the Soc structure.
2019-08-19 16:42:20 +02:00
cinap_lenrek f35d5ee5b0 bcm64: add support for more than 1GB of ram (untested)
this adds a 4GB KMAP window into the kernel address space
so we can access all physical ram on raspberry pi 4 for
user pages.

note that kernel memory above KZERO is still limited
to 1GB because of DMA restrictions.
2019-08-18 21:16:30 +02:00
cinap_lenrek 3fc8d1bdae bcm64: add driver for emmc2 controller 2019-08-18 18:50:24 +02:00
cinap_lenrek 031f5756ab bcm64: poll gisb arbiter for asynchronous bus errors 2019-08-16 19:24:00 +02:00
cinap_lenrek 54becb8466 ethergenet: remove debugging
the hangs where caused by missing NX bits on the mmio mappings,
so the debug code is not needed anymore.
2019-08-16 19:22:28 +02:00
cinap_lenrek 3bf49f1814 bcm64: set XN bits for kernel device mappings 2019-08-16 19:05:04 +02:00
cinap_lenrek 05f9a66fd4 bcm, bcm64: add vcore support for raspberry pi 3 GPIO expander 2019-07-28 11:39:57 +02:00
cinap_lenrek ea2a5a33ca bcm64: fix wrong prescaler for generic timer on rpi4
the raspberry pi 4 uses 54 instead of 19.2 MHz crystal.
detect which frequency is used by reading OTP bootmode
register:

https://www.raspberrypi.org/documentation/hardware/raspberrypi/otpbits.md

Bit 1: sets the oscillator frequency to 19.2MHz
2019-07-27 17:59:25 +02:00
cinap_lenrek 834f670349 ethergenet: fix flow control negotiation 2019-07-25 17:44:47 +02:00
cinap_lenrek 706926f818 bcm64: add config for raspberry pi 4 2019-07-25 09:12:40 +02:00
cinap_lenrek 3bc4e5a6d5 bcm64: work in progress genet ethernet driver for raspberry pi 4 2019-07-25 09:11:53 +02:00
cinap_lenrek 2a4c767c41 bcm64: reorganize virtual memory map for rapberry pi4 2019-07-25 09:10:07 +02:00
cinap_lenrek 4200778861 bcm64: update io.h for pci express and raspberry pi 4 2019-07-25 09:08:35 +02:00
cinap_lenrek 6d9edeeb67 bcm64: add pci express driver for raspberry pi 4 2019-07-25 09:04:50 +02:00
cinap_lenrek 676ef0ca0b bcm64: add gic interrupt controller driver for raspberry pi 4 2019-07-25 09:02:47 +02:00
cinap_lenrek 10b456ff44 bcm64: add gisb arbiter driver to catch bus timeouts 2019-07-25 09:01:44 +02:00
cinap_lenrek 811b80cae1 bcm, bcm64: make irq.$O optional and add intrdisable(), use intrenable()
the raspberry pi 4 has a new interrupt controller and
pci support, so get rid of intrenable() macro and
properly make intrenable function with tbdf argument.
2019-07-25 08:58:58 +02:00
cinap_lenrek dfea95b3c2 bcm64: strip debug symbols to make sure .img file is multiple of 4 bytes
the raspberry pi4 firmware refuses to enable the GIC interrup controller
for arm64 when the .img file is not a multiple of 4 bytes. yes, this
is insane and nowhere documented.
2019-07-25 08:52:46 +02:00