History log of /openbsd-current/sys/arch/octeon/octeon/machdep.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.137 24-Oct-2023 claudio

Normally context switches happen in mi_switch() but there are 3 cases
where a switch happens outside. Cleanup these code paths and make the
machine independent.

- when a process forks (fork, tfork, kthread), the new proc needs to
somehow be scheduled for the first time. This is done by proc_trampoline.
Since proc_trampoline is machine dependent assembler code change
the MP specific proc_trampoline_mp() to proc_trampoline_mi() and make
sure it is now always called.
- cpu_hatch: when booting APs the code needs to jump to the first proc
running on that CPU. This should be the idle thread for that CPU.
- sched_exit: when a proc exits it needs to switch away from itself and
then instruct the reaper to clean up the rest. This is done by switching
to the idle loop.

Since the last two cases require a context switch to the idle proc factor
out the common code to sched_toidle() and use it in those places.

Tested by many on all archs.
OK miod@ mpi@ cheloha@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.136 04-Feb-2023 cheloha

timecounting: remove incomplete PPS support

The timecounting code has had stubs for pulse-per-second (PPS) polling
since it was imported in 2004. At this point it seems unlikely that
anyone is going to finish adding PPS support, so let's remove the stubs:

- Delete the dead tc_poll_pps() call from tc_windup().
- Remove all tc_poll_pps symbols from the kernel.

Link: https://marc.info/?l=openbsd-tech&m=167519035723210&w=2

ok miod@


# 1.135 11-Jan-2023 visa

Enable TLB read inhibit on OCTEON Plus and newer SoCs.

OK deraadt@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.134 24-Jul-2021 visa

Replace cpus_running with CPU_IS_RUNNING().


# 1.133 12-Jul-2021 visa

Remember to set CPUF_RUNNING on secondary CPUs.


# 1.132 12-Jul-2021 visa

Make hw_cpu_hatch() more similar on loongson and octeon.


# 1.131 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_9_BASE
# 1.130 09-Mar-2021 visa

Add initial bits for Check Point UTM-1 EDGE N.

From Thaison Nguyen


# 1.129 04-Feb-2021 visa

Handle Netgear ProSecure UTM25

This makes the system recognize and configure Netgear ProSecure UTM25.
Of the network ports, LAN1-4 and WAN1 are functional. WAN2 does not work
for some reason. Even though WAN1 has a separate link to the SoC, the
connection appears to go through the same switch that the LAN ports use.
At the moment, the system relies on U-Boot to set up the switch so that
the LAN and WAN segments stay separate.

Initial diff and input from Thaison Nguyen, thank you!


# 1.128 30-Jan-2021 visa

Abstract octeon board handling a little

Detect octeon board model in one place, and replace firmware-supplied
board_type with an abstract model identifier in driver code. This makes
it easier to manage with different products, and board flavours, that
happen to use the same model information, such as board_type.


Revision tags: OPENBSD_6_8_BASE
# 1.127 18-Jul-2020 visa

Userland timecounter implementation for octeon

OK naddy@; no objections from kettenis@


# 1.126 11-Jul-2020 visa

Synchronize each core's CP0 cycle counter using the IO clock counter.
This makes the cycle counter usable as timecounter on multiprocessor
machines.

Idea from Linux.

Tested on CN5020, CN6120, CN7130 and CN7360.

Looks reasonable to kettenis@


# 1.125 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.136 04-Feb-2023 cheloha

timecounting: remove incomplete PPS support

The timecounting code has had stubs for pulse-per-second (PPS) polling
since it was imported in 2004. At this point it seems unlikely that
anyone is going to finish adding PPS support, so let's remove the stubs:

- Delete the dead tc_poll_pps() call from tc_windup().
- Remove all tc_poll_pps symbols from the kernel.

Link: https://marc.info/?l=openbsd-tech&m=167519035723210&w=2

ok miod@


# 1.135 11-Jan-2023 visa

Enable TLB read inhibit on OCTEON Plus and newer SoCs.

OK deraadt@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.134 24-Jul-2021 visa

Replace cpus_running with CPU_IS_RUNNING().


# 1.133 12-Jul-2021 visa

Remember to set CPUF_RUNNING on secondary CPUs.


# 1.132 12-Jul-2021 visa

Make hw_cpu_hatch() more similar on loongson and octeon.


# 1.131 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_9_BASE
# 1.130 09-Mar-2021 visa

Add initial bits for Check Point UTM-1 EDGE N.

From Thaison Nguyen


# 1.129 04-Feb-2021 visa

Handle Netgear ProSecure UTM25

This makes the system recognize and configure Netgear ProSecure UTM25.
Of the network ports, LAN1-4 and WAN1 are functional. WAN2 does not work
for some reason. Even though WAN1 has a separate link to the SoC, the
connection appears to go through the same switch that the LAN ports use.
At the moment, the system relies on U-Boot to set up the switch so that
the LAN and WAN segments stay separate.

Initial diff and input from Thaison Nguyen, thank you!


# 1.128 30-Jan-2021 visa

Abstract octeon board handling a little

Detect octeon board model in one place, and replace firmware-supplied
board_type with an abstract model identifier in driver code. This makes
it easier to manage with different products, and board flavours, that
happen to use the same model information, such as board_type.


Revision tags: OPENBSD_6_8_BASE
# 1.127 18-Jul-2020 visa

Userland timecounter implementation for octeon

OK naddy@; no objections from kettenis@


# 1.126 11-Jul-2020 visa

Synchronize each core's CP0 cycle counter using the IO clock counter.
This makes the cycle counter usable as timecounter on multiprocessor
machines.

Idea from Linux.

Tested on CN5020, CN6120, CN7130 and CN7360.

Looks reasonable to kettenis@


# 1.125 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.135 11-Jan-2023 visa

Enable TLB read inhibit on OCTEON Plus and newer SoCs.

OK deraadt@


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.134 24-Jul-2021 visa

Replace cpus_running with CPU_IS_RUNNING().


# 1.133 12-Jul-2021 visa

Remember to set CPUF_RUNNING on secondary CPUs.


# 1.132 12-Jul-2021 visa

Make hw_cpu_hatch() more similar on loongson and octeon.


# 1.131 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_9_BASE
# 1.130 09-Mar-2021 visa

Add initial bits for Check Point UTM-1 EDGE N.

From Thaison Nguyen


# 1.129 04-Feb-2021 visa

Handle Netgear ProSecure UTM25

This makes the system recognize and configure Netgear ProSecure UTM25.
Of the network ports, LAN1-4 and WAN1 are functional. WAN2 does not work
for some reason. Even though WAN1 has a separate link to the SoC, the
connection appears to go through the same switch that the LAN ports use.
At the moment, the system relies on U-Boot to set up the switch so that
the LAN and WAN segments stay separate.

Initial diff and input from Thaison Nguyen, thank you!


# 1.128 30-Jan-2021 visa

Abstract octeon board handling a little

Detect octeon board model in one place, and replace firmware-supplied
board_type with an abstract model identifier in driver code. This makes
it easier to manage with different products, and board flavours, that
happen to use the same model information, such as board_type.


Revision tags: OPENBSD_6_8_BASE
# 1.127 18-Jul-2020 visa

Userland timecounter implementation for octeon

OK naddy@; no objections from kettenis@


# 1.126 11-Jul-2020 visa

Synchronize each core's CP0 cycle counter using the IO clock counter.
This makes the cycle counter usable as timecounter on multiprocessor
machines.

Idea from Linux.

Tested on CN5020, CN6120, CN7130 and CN7360.

Looks reasonable to kettenis@


# 1.125 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.134 24-Jul-2021 visa

Replace cpus_running with CPU_IS_RUNNING().


# 1.133 12-Jul-2021 visa

Remember to set CPUF_RUNNING on secondary CPUs.


# 1.132 12-Jul-2021 visa

Make hw_cpu_hatch() more similar on loongson and octeon.


# 1.131 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_9_BASE
# 1.130 09-Mar-2021 visa

Add initial bits for Check Point UTM-1 EDGE N.

From Thaison Nguyen


# 1.129 04-Feb-2021 visa

Handle Netgear ProSecure UTM25

This makes the system recognize and configure Netgear ProSecure UTM25.
Of the network ports, LAN1-4 and WAN1 are functional. WAN2 does not work
for some reason. Even though WAN1 has a separate link to the SoC, the
connection appears to go through the same switch that the LAN ports use.
At the moment, the system relies on U-Boot to set up the switch so that
the LAN and WAN segments stay separate.

Initial diff and input from Thaison Nguyen, thank you!


# 1.128 30-Jan-2021 visa

Abstract octeon board handling a little

Detect octeon board model in one place, and replace firmware-supplied
board_type with an abstract model identifier in driver code. This makes
it easier to manage with different products, and board flavours, that
happen to use the same model information, such as board_type.


Revision tags: OPENBSD_6_8_BASE
# 1.127 18-Jul-2020 visa

Userland timecounter implementation for octeon

OK naddy@; no objections from kettenis@


# 1.126 11-Jul-2020 visa

Synchronize each core's CP0 cycle counter using the IO clock counter.
This makes the cycle counter usable as timecounter on multiprocessor
machines.

Idea from Linux.

Tested on CN5020, CN6120, CN7130 and CN7360.

Looks reasonable to kettenis@


# 1.125 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.133 12-Jul-2021 visa

Remember to set CPUF_RUNNING on secondary CPUs.


# 1.132 12-Jul-2021 visa

Make hw_cpu_hatch() more similar on loongson and octeon.


# 1.131 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_9_BASE
# 1.130 09-Mar-2021 visa

Add initial bits for Check Point UTM-1 EDGE N.

From Thaison Nguyen


# 1.129 04-Feb-2021 visa

Handle Netgear ProSecure UTM25

This makes the system recognize and configure Netgear ProSecure UTM25.
Of the network ports, LAN1-4 and WAN1 are functional. WAN2 does not work
for some reason. Even though WAN1 has a separate link to the SoC, the
connection appears to go through the same switch that the LAN ports use.
At the moment, the system relies on U-Boot to set up the switch so that
the LAN and WAN segments stay separate.

Initial diff and input from Thaison Nguyen, thank you!


# 1.128 30-Jan-2021 visa

Abstract octeon board handling a little

Detect octeon board model in one place, and replace firmware-supplied
board_type with an abstract model identifier in driver code. This makes
it easier to manage with different products, and board flavours, that
happen to use the same model information, such as board_type.


Revision tags: OPENBSD_6_8_BASE
# 1.127 18-Jul-2020 visa

Userland timecounter implementation for octeon

OK naddy@; no objections from kettenis@


# 1.126 11-Jul-2020 visa

Synchronize each core's CP0 cycle counter using the IO clock counter.
This makes the cycle counter usable as timecounter on multiprocessor
machines.

Idea from Linux.

Tested on CN5020, CN6120, CN7130 and CN7360.

Looks reasonable to kettenis@


# 1.125 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.131 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_9_BASE
# 1.130 09-Mar-2021 visa

Add initial bits for Check Point UTM-1 EDGE N.

From Thaison Nguyen


# 1.129 04-Feb-2021 visa

Handle Netgear ProSecure UTM25

This makes the system recognize and configure Netgear ProSecure UTM25.
Of the network ports, LAN1-4 and WAN1 are functional. WAN2 does not work
for some reason. Even though WAN1 has a separate link to the SoC, the
connection appears to go through the same switch that the LAN ports use.
At the moment, the system relies on U-Boot to set up the switch so that
the LAN and WAN segments stay separate.

Initial diff and input from Thaison Nguyen, thank you!


# 1.128 30-Jan-2021 visa

Abstract octeon board handling a little

Detect octeon board model in one place, and replace firmware-supplied
board_type with an abstract model identifier in driver code. This makes
it easier to manage with different products, and board flavours, that
happen to use the same model information, such as board_type.


Revision tags: OPENBSD_6_8_BASE
# 1.127 18-Jul-2020 visa

Userland timecounter implementation for octeon

OK naddy@; no objections from kettenis@


# 1.126 11-Jul-2020 visa

Synchronize each core's CP0 cycle counter using the IO clock counter.
This makes the cycle counter usable as timecounter on multiprocessor
machines.

Idea from Linux.

Tested on CN5020, CN6120, CN7130 and CN7360.

Looks reasonable to kettenis@


# 1.125 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.130 09-Mar-2021 visa

Add initial bits for Check Point UTM-1 EDGE N.

From Thaison Nguyen


# 1.129 04-Feb-2021 visa

Handle Netgear ProSecure UTM25

This makes the system recognize and configure Netgear ProSecure UTM25.
Of the network ports, LAN1-4 and WAN1 are functional. WAN2 does not work
for some reason. Even though WAN1 has a separate link to the SoC, the
connection appears to go through the same switch that the LAN ports use.
At the moment, the system relies on U-Boot to set up the switch so that
the LAN and WAN segments stay separate.

Initial diff and input from Thaison Nguyen, thank you!


# 1.128 30-Jan-2021 visa

Abstract octeon board handling a little

Detect octeon board model in one place, and replace firmware-supplied
board_type with an abstract model identifier in driver code. This makes
it easier to manage with different products, and board flavours, that
happen to use the same model information, such as board_type.


Revision tags: OPENBSD_6_8_BASE
# 1.127 18-Jul-2020 visa

Userland timecounter implementation for octeon

OK naddy@; no objections from kettenis@


# 1.126 11-Jul-2020 visa

Synchronize each core's CP0 cycle counter using the IO clock counter.
This makes the cycle counter usable as timecounter on multiprocessor
machines.

Idea from Linux.

Tested on CN5020, CN6120, CN7130 and CN7360.

Looks reasonable to kettenis@


# 1.125 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.129 04-Feb-2021 visa

Handle Netgear ProSecure UTM25

This makes the system recognize and configure Netgear ProSecure UTM25.
Of the network ports, LAN1-4 and WAN1 are functional. WAN2 does not work
for some reason. Even though WAN1 has a separate link to the SoC, the
connection appears to go through the same switch that the LAN ports use.
At the moment, the system relies on U-Boot to set up the switch so that
the LAN and WAN segments stay separate.

Initial diff and input from Thaison Nguyen, thank you!


# 1.128 30-Jan-2021 visa

Abstract octeon board handling a little

Detect octeon board model in one place, and replace firmware-supplied
board_type with an abstract model identifier in driver code. This makes
it easier to manage with different products, and board flavours, that
happen to use the same model information, such as board_type.


Revision tags: OPENBSD_6_8_BASE
# 1.127 18-Jul-2020 visa

Userland timecounter implementation for octeon

OK naddy@; no objections from kettenis@


# 1.126 11-Jul-2020 visa

Synchronize each core's CP0 cycle counter using the IO clock counter.
This makes the cycle counter usable as timecounter on multiprocessor
machines.

Idea from Linux.

Tested on CN5020, CN6120, CN7130 and CN7360.

Looks reasonable to kettenis@


# 1.125 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.128 30-Jan-2021 visa

Abstract octeon board handling a little

Detect octeon board model in one place, and replace firmware-supplied
board_type with an abstract model identifier in driver code. This makes
it easier to manage with different products, and board flavours, that
happen to use the same model information, such as board_type.


Revision tags: OPENBSD_6_8_BASE
# 1.127 18-Jul-2020 visa

Userland timecounter implementation for octeon

OK naddy@; no objections from kettenis@


# 1.126 11-Jul-2020 visa

Synchronize each core's CP0 cycle counter using the IO clock counter.
This makes the cycle counter usable as timecounter on multiprocessor
machines.

Idea from Linux.

Tested on CN5020, CN6120, CN7130 and CN7360.

Looks reasonable to kettenis@


# 1.125 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.127 18-Jul-2020 visa

Userland timecounter implementation for octeon

OK naddy@; no objections from kettenis@


# 1.126 11-Jul-2020 visa

Synchronize each core's CP0 cycle counter using the IO clock counter.
This makes the cycle counter usable as timecounter on multiprocessor
machines.

Idea from Linux.

Tested on CN5020, CN6120, CN7130 and CN7360.

Looks reasonable to kettenis@


# 1.125 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.126 11-Jul-2020 visa

Synchronize each core's CP0 cycle counter using the IO clock counter.
This makes the cycle counter usable as timecounter on multiprocessor
machines.

Idea from Linux.

Tested on CN5020, CN6120, CN7130 and CN7360.

Looks reasonable to kettenis@


# 1.125 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.125 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.124 05-Jun-2020 visa

cpu_rnd_messybits() for mips64

Use CP0 Count as a basis. Also take noise from virtual memory activity
by including BadVAddr.

OK deraadt@ dlg@


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.123 31-May-2020 dlg

introduce "cpu_rnd_messybits" for use instead of nanotime in dev/rnd.c.

rnd.c uses nanotime to get access to some bits that change quickly
between events that it can mix into the entropy pool. it doesn't
use nanotime to get a monotonically increasing set or ordered and
accurate timestamps, it just wants something with bits that change.

there's been discussions for years about letting rnd use a clock
that's super fast to read, but not necessarily accurate, but it
wasn't until recently that i figured out it wasn't interested in
time at all, so things like keeping a fast clock coherent between
cpu cores or correct according to ntp is unecessary. this means we
can just let rnd read the cycle counters on cpus and things will
be fine. cpus with cycle counters that vary in their speed and
arent kept consistent between cores may even be desirable in this
context.

so this is the first step in converting rnd.c to reading cycle
counter. it copies the nanotime backend to each arch, and they can
replace it with something MD as a second step later on.

djm@ suggested rnd_messybytes, but we landed on cpu_rnd_messybits.
thanks to visa for his eyes.
ok deraadt@ visa@
deraadt@ says he will help handle any MD fallout that occurs.


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.122 29-May-2020 deraadt

dev/rndvar.h no longer has statistical interfaces (removed during various
conversion steps). it only contains kernel prototypes for 4 interfaces,
all of which legitimately belong in sys/systm.h, which are already included
by all enqueue_randomness() users.


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.121 25-May-2020 visa

Pass boothowto from the bootloader to the kernel on octeon.

OK deraadt@


# 1.120 25-May-2020 visa

Mix board information into the entropy pool.

The data are static but they introduce differences between systems.

OK deraadt@


Revision tags: OPENBSD_6_7_BASE
# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.119 20-Dec-2019 visa

Convert various boolean_t/TRUE/FALSE to int/1/0 in mips64 memory code.

OK mpi@


Revision tags: OPENBSD_6_6_BASE
# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.118 28-Sep-2019 deraadt

rename the 'cn30xx' drivers to just 'oct', because digits inside devices
drivers is gross. discussed with visa.


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.117 31-Jul-2019 visa

Fix kmem access on octeon. Currently, mem_layout lists segments that
were free after the kernel was loaded. The memory occupied by the kernel
image is not included. To let libkvm access the image through /dev/kmem,
return true from is_memory_range() if the physical address is within
the kernel.


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.116 17-Jul-2019 visa

Adjust search of symbol table pointers to match with the bootloader.


# 1.115 17-Jul-2019 visa

Add a bootloader for octeon.

The firmware on OCTEON machines usually does not provide an interface
for accessing devices, which has made it tricky to implement an OpenBSD
bootloader. To solve this device access problem, this new loader has
been built on top of a small kernel. The kernel provides all the
necessary devices drivers, while most of the usual bootloader logic
is in a userspace program in a ramdisk.

The loader program is accompanied by a special device, octboot(4).
The main purpose of this device is to implement a mechanism for
loading and launching kernels. The mechanism has been inspired by Linux'
kexec(2) system call.

The bootloader will be enabled later when it is ready for general use.

Discussed with deraadt@


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.114 12-Jul-2019 visa

Remove unnecessary extern declarations.


# 1.113 12-Jul-2019 visa

Make rootdev parsing a little saner. The "rootdev=" prefix can be
removed already in process_bootargs(). Pass the value as a parameter
to parse_uboot_root(). Set uboot_rootdev only if parsing succeeds.


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.112 20-Jun-2019 visa

Fix misleading code. The kernel keeps using the original boot
descriptors even after bootstrap.


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.111 18-May-2019 visa

Add parsing for standard boot options.


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.110 05-May-2019 visa

Use the .bss for the bootstrap stack of mips_init(). This way the memory
region is properly allocated by the firmware.

Move the .bss clearing to locore.S because the section has to be ready
when the stack is taken into use. This additionally makes the
C environment more consistent at the start of mips_init().


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


Revision tags: OPENBSD_6_5_BASE
# 1.109 01-Apr-2019 tedu

fast track ddb> reboot command to skip anything which might panic again.
ok deraadt


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.108 18-Dec-2018 visa

Figure out the number of available CPUs using system fuse registers.
This makes `ncpusfound' independent of kernel boot parameters.

The kernel still needs the help of the firmware to spin up secondary
CPUs, so the `coremask' or `numcores' boot parameter is still needed
for multicore operation.

Tested on CN5020, CN6120, CN7130 and CN7360.


# 1.107 04-Dec-2018 visa

Add processor IDs for several OCTEON II and III SoCs.


Revision tags: OPENBSD_6_4_BASE
# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.106 13-Jun-2018 visa

Make octeon kernels compile with DEBUG.

Based on a diff from jj@. Thank you!


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.105 09-Apr-2018 visa

Add a driver for the OCTEON cryptographic unit. It provides
a hardware-accelerated implementation of several encryption
and authentication algorithms for ipsec(4):

AES-CBC
AES-CTR
AES-GCM
AES-GMAC
HMAC-MD5
HMAC-SHA1
HMAC-SHA2-256
HMAC-SHA2-384
HMAC-SHA2-512

Please note that the driver is currently disabled.

OK deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision


# 1.104 18-Jan-2018 visa

Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that
the value matches with the number of cores that GENERIC.MP uses.

OK deraadt@, krw@, pirofti@


# 1.103 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


# 1.102 11-Dec-2017 deraadt

In uvm Chuck decided backing store would not be allocated proactively
for blocks re-fetchable from the filesystem. However at reboot time,
filesystems are unmounted, and since processes lack backing store they
are killed. Since the scheduler is still running, in some cases init is
killed... which drops us to ddb [noted by bluhm]. Solution is to convert
filesystems to read-only [proposed by kettenis]. The tale follows:
sys_reboot() should pass proc * to MD boot() to vfs_shutdown() which
completes current IO with vfs_busy VB_WRITE|VB_WAIT, then calls VFS_MOUNT()
with MNT_UPDATE | MNT_RDONLY, soon teaching us that *fs_mount() calls a
copyin() late... so store the sizes in vfsconflist[] and move the copyin()
to sys_mount()... and notice nfs_mount copyin() is size-variant, so kill
legacy struct nfs_args3. Next we learn ffs_mount()'s MNT_UPDATE code is
sharp and rusty especially wrt softdep, so fix some bugs adn add
~MNT_SOFTDEP to the downgrade. Some vnodes need a little more help,
so tie them to &dead_vnops.

ffs_mount calling DIOCCACHESYNC is causing a bit of grief still but
this issue is seperate and will be dealt with in time.
couple hundred reboots by bluhm and myself, advice from guenther and
others at the hut


# 1.101 01-Nov-2017 visa

Add readiness to utilize LMTDMA operations.


Revision tags: OPENBSD_6_2_BASE
# 1.100 17-Sep-2017 visa

Do not print "cpuX launched" any longer. This reduces dmesg spam
on multicore systems.


# 1.99 02-Sep-2017 visa

Let the kernel utilize the FPU if one is available, even when the
FPUEMUL option is enabled. This benefits OCTEON III systems which can
run floating-point operations natively.

Feedback from and OK miod@; he also helped with testing.

Tested on octeon without FPU (CN5020, CN6120) and with FPU (CN7130),
as well as on sgi/IP27 (MP R16000), sgi/IP32 (R5000), and
loongson (3A1000).


# 1.98 26-Aug-2017 visa

Use macros for Config1 bits.


# 1.97 31-Jul-2017 visa

Replace OCTEON_MAXCPUS with MAXCPUS to avoid redundancy.


# 1.96 03-Jul-2017 visa

Attach com(4) using fdt on octeon.

The relevant part of uartbus(4) is made part of the com(4) glue
to avoid extra maneuvers in the code.


# 1.95 19-Jun-2017 visa

Fix the timecounter register on CN72xx/CN73xx.


# 1.94 19-Jun-2017 visa

Use octeon_model_family() for SoC identification as in the rest
of the code.


# 1.93 19-Jun-2017 visa

Use type register_t instead of __register_t. Drop unneeded __unused.


# 1.92 18-Jun-2017 visa

Move IPI control entry points into octeon_intr.c.
Needed by upcoming driver changes.


# 1.91 18-Jun-2017 visa

Drop unnecessary call to octeon_setintrmask(). The function gets called
by the splx() handler.


# 1.90 11-Jun-2017 visa

Fix TLB size computation on OCTEON II and III. The CPUs have utilized
the whole TLB space even before this. However, TLB initialization on
boot and TLB flush on ASID wraparound have been incomplete. These have
caused crashes of processes.


# 1.89 11-Jun-2017 visa

Add a memory barrier to ensure that stores become visible
in a proper order.


# 1.88 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.87 24-Apr-2017 visa

Add an fdt blob for octeon systems whose firmware does not provide
a device-tree. It will be needed later when more device drivers
are attached using fdt.

OK kettenis@


# 1.86 20-Apr-2017 visa

Make TCB address available to userspace via the UserLocal register.
This lets programs get the address without a system call on OCTEON II
and later.

Add UserLocal load emulation for systems that do not implement
the RDHWR instruction or the UserLocal register.

OK guenther@


# 1.85 07-Apr-2017 visa

Add prid for CN72xx/CN73xx.


# 1.84 07-Apr-2017 visa

Make SoC version available in a simple form.


# 1.83 02-Apr-2017 visa

printf format strings should be literals. Reminded by clang.


Revision tags: OPENBSD_6_1_BASE
# 1.82 06-Jan-2017 fcambus

Ansify cpu_sysctl() on mips64 platforms.

OK patrick@, visa@, jasper@, mpi@


# 1.81 17-Dec-2016 visa

Fix IO clock speed and system reset on Octeon III.


# 1.80 17-Dec-2016 visa

On some systems, the firmware advertises multiple tiny and disjoint
regions of free memory whose size is no more than a few page frames.
Ignore them in order not to clutter uvm with fragments.


# 1.79 26-Nov-2016 martijn

Start process_bootargs at 0 instead of 1.
When using endbootargs in U-Boot arguments start at position 0.

OK visa@


# 1.78 27-Oct-2016 visa

Revert previous `ncpus' change because the percpu code now works
without it.


# 1.77 26-Oct-2016 visa

Increment `ncpus' to its final value already during autoconfiguration so
that percpu data areas get allocated properly on mips64 platforms. It is
too late to set the value during launch of secondary CPUs.

ok jasper@ kettenis@ dlg@


# 1.76 09-Oct-2016 tom

Apply consistency to forever loops with continue and NOTREACHED

Same thought from kettenis@, ok krw@ phessler@ millert@


# 1.75 14-Aug-2016 visa

Utilize the TLB Execute-Inhibit bit with non-executable mappings on CPUs
that support the Execute-Inhibit exception. This makes user space W^X
effective on Octeon Plus and later Octeon versions.

Feedback from miod@, thanks!
No objection from deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.74 01-Jul-2016 visa

Add fdt init for octeon.


# 1.73 21-Mar-2016 visa

On Octeon systems, U-Boot provides a list of usable memory regions. Use
the list instead of hardcoded regions in memory setup. Works on
EdgeRouter Lite, EdgeRouter Pro, Lanner MR326b and Movidis 16x.

Tested by jj@
Tested by and ok jmatthew@


# 1.72 06-Mar-2016 mpi

Rename mips64's trap_frame into trapframe.

For coherency with other archs and in order to use it in MI code.

ok visa@, tobiasu@


Revision tags: OPENBSD_5_9_BASE
# 1.71 16-Jan-2016 visa

Panic if someone boots the kernel by force without CPU 0. The system
will not work without that core.


# 1.70 02-Dec-2015 visa

Enable the DR1 region even with 32-bit page table entries. Those have
enough bits for addressing the region.


# 1.69 02-Dec-2015 visa

Clean up octeon memory region setup.

Diff by miod@ during c2k15
Tested by jbg@, jasper@, pirofti@
OK jasper@, pirofti@


# 1.68 20-Aug-2015 visa

Use the IPD Clock Count register as a timecounter, making the clock
tick in Octeon MP land.

ok pirofti@, miod@, uebayasi@


Revision tags: OPENBSD_5_8_BASE
# 1.67 19-Jul-2015 visa

Register the IPI handler early enough for the correct idle_mask to
propagate to all threads. Otherwise early-started kernel threads run
IPIs disabled, which will lead to a deadlock soon after other cores
have started.

ok miod@ pirofti@


# 1.66 15-Jul-2015 pirofti

Ditch the octeon simulator non-sense.

Discussed with miod@.


# 1.65 15-Jul-2015 pirofti

Refix memory handling for machines with less than 256M broken by revision 1.64.

Allows my DSR-500 to boot again.

Okay miod@.


# 1.64 25-Jun-2015 jmatthew

Re-enable memory above 256mb now that uvm_pmr_get1page() has been fixed.
From Visa Hankala.


Revision tags: OPENBSD_5_7_BASE
# 1.63 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.62 20-Sep-2014 kettenis

Use config_suspend_all(9).

ok mpi@, uebayasi@, dlg@


# 1.61 11-Aug-2014 miod

Do not use CKSEG0 to quickly map physical addresses, but XKPHYS, for we are
not limited to 512MB physmem.


Revision tags: OPENBSD_5_6_BASE
# 1.60 21-Jul-2014 uebayasi

boot(9): Reduce annoying style diffs

- Always use either: ((x & RB_XXX) != 0) or ((x & RB_XXX) == 0) in boolean
context (mostly if (x), or x ? y : z)
- prom_halt() in alpha is confirmed to take int as boolean

Converted by coccinelle. No functional change intended.


# 1.59 13-Jul-2014 uebayasi

boot(9): Cosmetic changes to improve diff'ability.


# 1.58 13-Jul-2014 uebayasi

Cosmetic changes to reduce diffs.


# 1.57 13-Jul-2014 jasper

consistency with upcoming bootloader device parsing of the uboot arguments,
root= becomes rootdev=


# 1.56 13-Jul-2014 jasper

print leading '0x' for addresses and masks with DUMP_BOOT_{DESC,INFO}

ok pirofti@


# 1.55 13-Jul-2014 jasper

- fix off-by-one in getting the number of cores in the system
- unbreak GENERIC.MP build


# 1.54 11-Jul-2014 uebayasi

boot(9): Undo curproc-overriding hacks

Some (not all) boot(9) implementations have ancient hacks which overrides if
(curproc == NULL). This was probably made in a hope to forcibly proceed
various clean-shutdown related code, including VFS shutdown. Let's clarify
that clean-shutdown needs process context; it is impossible to cleanly shutdown
VFS from within e.g. a panic in SPL_HIGH.

OK kettenis@


# 1.53 10-Jul-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.52 10-Jul-2014 uebayasi

boot(9): Remove comments about RB_*, "cold", and savectx()

Again remove slightly different comments to reduce diffs. These will be
re-added once boot() become MI and its specification is clearly re-defined.

OK miod@


# 1.51 10-Jul-2014 uebayasi

boot(): Remove comments about RB_TIMEBAD to reduce diffs

RB_TIMEBAD is documented well enough that the comment is not needed. sparc64
does slightly different and its comment is left with XXX.

OK deraadt@ miod@


# 1.50 10-Jul-2014 uebayasi

boot(): Unify declarations

OK deraadt@


# 1.49 17-Jun-2014 jmatthew

The io clock on Octeon II (CN6xxx) runs at a different rate to the cpu clock.
Program the uarts based on the io clock rate on these platforms.

ok jasper@ pirofti@ yasuoka@


# 1.48 31-May-2014 mpi

Revert previous diff setting cold to 1 on shutdown because it breaks machine
with softraid(4) disks.

softraid(4) is the last real consumer of the doshutdownhooks(9) API and it is
not trivial to convert its hook to a DVACT_POWERDOWN handler since the latter
does not allow to sleep.


# 1.47 30-May-2014 mpi

Set cold to 1 before executing the DVACT_POWERDOWN handlers when halting or
rebooting a machine, like it is done in the hibernate case.

At least some USB host controller drivers rely on this to busy way instead
of sleeping. Avoid a panic on macppc with an uhci(4) cardbus plugged in.

ok deraadt@, uebayashi@


# 1.46 10-May-2014 jasper

spello in comment and tweak DUMP_BOOT_DESC a tad


# 1.45 10-May-2014 jasper

various format string fixes and remove -Wno-format from octeon

feedback/ok miod@


# 1.44 03-Apr-2014 mpi

Moar <uvm/uvm.h> -> <uvm/uvm_extern.h> love.


# 1.43 13-Mar-2014 dlg

get rid of the assumption that the head of the alldevs list is the
"mainbus" device. this breaks when mpath is enabled because it
attaches before mainbus and therefore takes the head position.

have autoconf provide device_mainbus() which looks up mainbus_cd,
and use that instead.

discussed with deraadt who just wants mpath stuff to move forward
despite there being many ways to shine this particular turd.


# 1.42 09-Mar-2014 miod

Rework the per-cpu cache information. Use a common struct to store the line
size, the number of sets, and the total size (and the set size, for convenience)
per cache (I$, D$, L2, L3).
This allows cpu.c to print the number of ways (sets) of L2 and L3 caches from
the cache information, rather than hardcoding this from the processor type.


Revision tags: OPENBSD_5_5_BASE
# 1.41 28-Sep-2013 miod

In boot(), do not iterate over alldevs if it's empty (i.e. halting from ddb
with ddb entered early with boot -d or from UKC).


# 1.40 23-Aug-2013 pirofti

Fix memory initialization for octeon's with less than 256MB.

Don't substract the 256MB upperbound from realmem_bytes if the current
available memory is less than that.

Makes my DSR-500 kernel reach userland.

Okay miod@


# 1.39 21-Aug-2013 pirofti

Missed a spot in my last commit.


# 1.38 20-Aug-2013 pirofti

Have some style(9).


Revision tags: OPENBSD_5_4_BASE
# 1.37 05-Jun-2013 jasper

whitespace


# 1.36 02-Jun-2013 jasper

move octeonreg.h to a more generic location and add multiple inclusion
guards while here.

ok uebayasi@


# 1.35 01-Jun-2013 jasper

- remove more backward compat code and switch the callers over to the new function

ok uebayasi@


# 1.34 01-Jun-2013 jasper

corectly initialize the number of cores/cpus on the board. this fixes a NULL
deref in cpuattach() since we advertised only a single CPU, but tried to
attach two.

with this diff bsd.mp boots up on the ERL.

discussed with pirofti@
ok miod@ pirofti@


# 1.33 08-Apr-2013 jasper

allow octeon to find it's root device, based on the flags passed by U-Boot. The ${bootcmd}
needs to be something like 'bootoctlinux root=/dev/octcf0'.

This will be temporary untill we have proper bootblocks, but for now, this (in combination)
with an upcoming installer diff allows my CAM-0100 to autoboot straight of the disk, without
having to load the kernel via TFTP.

ok bcallah@ yasuoka@


# 1.32 06-Apr-2013 jasper

allow GENERIC.MP to compile again...just for shits and giggles.


# 1.31 03-Apr-2013 jasper

fix comment detailing the memory map

from syuu@


# 1.30 27-Mar-2013 jasper

fill in cpu_model.


# 1.29 19-Mar-2013 jasper

implement octeon_cpuspeed()

ok yasuoka@


# 1.28 19-Mar-2013 jasper

instead of treating boot_info->cf_common_addr special, save the whole of boot_info
for future use.

ok yasuoka@


# 1.27 15-Mar-2013 jasper

print a dump of structs boot_info/boot_desc which contain useful information
to have in the dmesg, for the time being

ok bcallah@ yasuoka@


# 1.26 15-Mar-2013 jasper

add some board types which will be used later to identify particular boards

ok yasuoka@


# 1.25 15-Mar-2013 jasper

save a copy of the address at which the CF bus can be found, and use this in octcf(4) for
a better probe function which doesn't unconditionally tries to attach octcf(4). this would
cause endless faults on the EdgeRouter Lite as it lacks a CF bus.

feedback and testing bcallah@ and chris@
ok yasuoka@


# 1.24 13-Mar-2013 jasper

Allow octeon to reboot by poking the right address for a soft cpu reset.
No more yanking the powercable when I hit ddb :)

also tested by bcallah@

ok bcallah@ chris@ yasuoka@


Revision tags: OPENBSD_5_3_BASE
# 1.23 08-Oct-2012 deraadt

Revamp the sequences for suspend/hibernate -> resume so that the code
paths are reflexive. It is now possible to fail part-way through a
suspend sequence, and recover along the resume code path.
Split DVACT_SUSPEND by adding a new DVACT_POWERDOWN method is used
after hibernate (and suspend too) to finish the job. Some drivers
must be converted at the same time to use this instead of shutdown hooks
(the others will follow at a later time)
ok kettenis mlarkin


# 1.22 03-Oct-2012 miod

Don't include <mips64/archtype.h> when you don't need it.


# 1.21 03-Oct-2012 miod

Split ever-growing mips <machine/cpu.h> into what 99% of the kernel needs,
which will remain in <machine/cpu.h>, and a new mips_cpu.h containing only the
goriest md details, which are only of interest to a handful set of files; this
is similar in spirit to what alpha does, but here <machine/cpu.h> does not
include the new file.


# 1.20 29-Sep-2012 miod

Kill the mostly unused VMTLB_xxx and VMNUM_xxx defines. Move all tlb
knowledge to <machine/pte.h>. Add specific routines for tlb handling setup
(at cpu initialization time) and tlb ASID wrap.


Revision tags: OPENBSD_5_2_BASE
# 1.19 16-Jul-2012 miod

Forgot these files during the recent clock churning.


# 1.18 17-Jun-2012 miod

Remove leftover loongson or sgi references.


# 1.17 25-Mar-2012 miod

Move cache handling routines related definitions to a dedicated header file,
rather than abusing <machine/cpu.h>.


# 1.16 15-Mar-2012 miod

uncached_base was introduced early in IP27 support, since these designs use
subspaces in the CCA_NC uncached memory space. However, being coherent,
there was never a need for bus_dma to use uncached addresses.

This means that, on the only systems where uncached_base was not set to
PHYS_TO_XKPHYS(0, CCA_NC), it was never used.

Remove the variable, and replace PHYS_TO_UNCACHED() with
PHYS_TO_XKPHYS(, CCA_NC). No functional change.


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.15 26-Jun-2011 deraadt

if_downall() cannot be done MI in sys_reboot() because vfs_shutdown()
might need network (ie. nfs). Move the call to the MD boot() routines.
This cause for boot hangs diagnosed by kettenis.


# 1.14 24-Jun-2011 naddy

machdep.kbdreset enables a shutdown by Ctrl-Alt-Del on amd64 and
i386. Stop abusing it on other archs for controling a shutdown by
pressing the soft power button:

* Add a MI sysctl hw.allowpowerdown; if set to 1 (the default) it
allows a power button shutdown.
* Make acpi(4)/acpibtn(4) honor hw.allowpowerdown.
* Switch the various power button intercepts on landisk, sgi, sparc64
and zaurus over to hw.allowpowerdown.
* Garbage collect the machdep.kbdreset sysctl on all archs other than
amd64 and i386.

ok miod@


# 1.13 05-Jun-2011 deraadt

Move the bufcachepercent setting code to MI locations -- set it to 42%
for now; that is unlikely to hit some of the remaining starvation bugs.
Repair the bufpages calculation too; i386 was doing it ahead of time
(incorrectly) and then re-calculating it.
ok thib


# 1.12 30-May-2011 oga

Remove the freelist member from vm_physseg

The new world order of pmemrange makes this data completely redundant
(being dealt with by the pmemrange constraints instead). Remove all code
that messes with the freelist.

While touching every caller of uvm_page_physload() anyway, add the flags
argument to all callers (all but one is 0 and that one already used
PHYSLOAD_DEVICE) and remove the macro magic to allow callers to continue
without it.

Should shrink the code a bit, as well.

matthew@ pointed out some mistakes i'd made.
``freelist death, I like. Ok.' ariane@
`I agree with the general direction, go ahead and i'll fix any fallout
shortly'' miod@ (68k 88k and vax i could not check would build)


# 1.11 08-May-2011 syuu

memory handling fix


# 1.10 08-May-2011 syuu

fix variable name


# 1.9 08-May-2011 syuu

combus renamed uartbus, com_oct renamed cn30xxuart


# 1.8 08-May-2011 syuu

obio renamed iobus, moved interrupt handler code to dev/octeon_intr.c


Revision tags: OPENBSD_4_9_BASE
# 1.7 28-Nov-2010 syuu

boot descriptor support added


# 1.6 23-Nov-2010 syuu

passing stack pointer to secondary processors


# 1.5 23-Nov-2010 syuu

Correct interrupt handling


# 1.4 24-Oct-2010 miod

Move build_trampoline() and setregs() to a common location for all mips ports.


# 1.3 01-Oct-2010 syuu

Implemented combus to support com device on OCTEON without modifing dev/ic/com.c ok deraadt@


# 1.2 21-Sep-2010 syuu

Remove bootinfo.c which has license issue. ok deraadt@


# 1.1 20-Sep-2010 syuu

Initial revision