Commit graph

106 commits

Author SHA1 Message Date
Warner Losh fdafd315ad sys: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:00 -07:00
Mitchell Horne 41e26e8288 powerpc: better handling of shutdown flags
RB_HALT does not mean poweroff, RB_POWEROFF does.

Reviewed by:	jhibbits
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D42339
2023-11-23 12:07:42 -04:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh 95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
John Baldwin 5edf159ff1 powerpc powernv: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-10 10:21:38 -07:00
John Baldwin c90ea83112 Remove unused uart_devclass. 2022-05-06 15:46:57 -07:00
John Baldwin 676ea8e177 Remove unused iicbus_devclass. 2022-05-06 15:39:30 -07:00
John Baldwin f602f7e6f7 opalflash: Remove unused variable. 2022-04-12 14:58:59 -07:00
Warner Losh ddfc9c4c59 newbus: Move from bus_child_{pnpinfo,location}_src to bus_child_{pnpinfo,location} with sbuf
Now that the upper layers all go through a layer to tie into these
information functions that translates an sbuf into char * and len. The
current interface suffers issues of what to do in cases of truncation,
etc. Instead, migrate all these functions to using struct sbuf and these
issues go away. The caller is also in charge of any memory allocation
and/or expansion that's needed during this process.

Create a bus_generic_child_{pnpinfo,location} and make it default. It
just returns success. This is for those busses that have no information
for these items. Migrate the now-empty routines to using this as
appropriate.

Document these new interfaces with man pages, and oversight from before.

Reviewed by:		jhb, bcr
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D29937
2021-06-22 20:52:06 -06:00
Marcin Wojtas 240429103c Rename ofwpci.c to ofw_pcib.c
It's a class0 driver that implements some pcib methods and creates
a pci bus as its children.
The "ofw_pci" name will be used by a new driver that will be a subclass
of the pci bus.
No functional changes intended.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: andrew
Obtained from: Semihalf
Sponsored by: Alstom Group
Differential Revision: https://reviews.freebsd.org/D30226
2021-05-20 11:22:25 +02:00
Justin Hibbits be48fe6000 powerpc/xive: Remove POWER9 DD1 IRQ bits
The OPAL_XIVE_*_VIA_IFW flags are used only for POWER9 DD1, which we
don't support.

Noticed while perusing Linux and skiboot git logs.
2021-05-01 16:18:02 -05:00
Alfredo Dal'Ava Junior b8bc6b7954 opal_console: fix serial console output corruption on powerpc64
Adds OPAL_CONSOLE_WRITE error handling and implements a call to
OPAL_CONSOLE_WRITE_BUFFER_SPACE to verify if there's enough space
before writing to console.

This fixes serial port output getting corrupted on fast writes, like
on "dmesg" output.

Tested on Raptor Blackbird running powerpc64 BE kernel

Reviewed by:	luporl
Sponsored by:	Eldorado Reserach Institute (eldorado.org.br)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D29063
2021-04-16 20:10:09 -03:00
Mark Johnston cb5f8694a5 powernv: Include NUMA locality information in the CPU topology
ULE uses this topology to try and preserve locality when migrating
threads between CPUs and when performing work stealing.  Ensure that on
NUMA systems it will at least take the NUMA topology into account.

Reviewed by:	bdragon, jhibbits (previous version)
Tested by:	bdragon
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D28580
2021-04-01 10:25:57 -04:00
Brandon Bergren bd94c8ab29 [PowerPC] Fix NUMA checking for powernv
At this point in startup, vm_ndomains has not been initialized. Switch
to checking kenv instead.

Fixes incorrect NUMA information being set on multi-domain systems like
Talos II.

Submitted by:	jhibbits
MFC after:	2 weeks
2021-03-27 20:42:49 -05:00
Alfredo Dal'Ava Junior 6d2254bc92 [POWERPC64LE] fix sysctl dev.opal_sensor.* on little-endian kernel
- fix values returned by 'sysctls dev.opal_sensor.*.sensor'
- fix missing 'dev.opal_sensor.*.sensor_[max|min]' on sysctl

Reviewed-by: 	jhibbits
Sponsored-by:	Eldorado Research Institute (eldorado.org.br)
Differential-Revision: 	https://reviews.freebsd.org/D27365
2020-12-30 22:00:28 -03:00
Conrad Meyer 78599c32ef Add CFI start/end proc directives to arm64, i386, and ppc
Follow-up to r353959 and r368070: do the same for other architectures.

arm32 already seems to use its own .fnstart/.fnend directives, which
appear to be ARM-specific variants of the same thing.  Likewise, MIPS
uses .frame directives.

Reviewed by:	arichardson
Differential Revision:	https://reviews.freebsd.org/D27387
2020-12-05 00:33:28 +00:00
Leandro Lupori e2d6c417e3 Implement superpages for PowerPC64 (HPT)
This change adds support for transparent superpages for PowerPC64
systems using Hashed Page Tables (HPT). All pmap operations are
supported.

The changes were inspired by RISC-V implementation of superpages,
by @markj (r344106), but heavily adapted to fit PPC64 HPT architecture
and existing MMU OEA64 code.

While these changes are not better tested, superpages support is disabled by
default. To enable it, use vm.pmap.superpages_enabled=1.

In this initial implementation, when superpages are disabled, system
performance stays at the same level as without these changes. When
superpages are enabled, buildworld time increases a bit (~2%). However,
for workloads that put a heavy pressure on the TLB the performance boost
is much bigger (see HPC Challenge and pgbench on D25237).

Reviewed by:	jhibbits
Sponsored by:	Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D25237
2020-11-06 14:12:45 +00:00
Brandon Bergren 05c3051f86 [PowerPC64LE] Endian fix for opal_hmi.c
Another boring one. We need to endian swap before checking flags.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-23 01:51:01 +00:00
Brandon Bergren f9acb7a818 [PowerPC64LE] Get XIVE up and running.
More endian conversion.

* Install TCEs correctly (i.e. in big endian)

* Convert to big endian and back when setting up queue pages and IRQs.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-23 01:49:37 +00:00
Brandon Bergren bf933a83ec [PowerPC64LE] Endian fix for opal_dev.c.
Not much to say here, another missing be64toh() in memory that was written
from OPAL.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-23 01:41:51 +00:00
Brandon Bergren 9cbcb6ffce [PowerPC64LE] Endian fixes for opal_pci.c.
Since OPAL runs in big endian, any data being passed back and forth
via memory instead of registers needs to be byteswapped.

From my notes during development:

"A good way to find candidates is to look for vtophys() in opal_call()
parameters. The memory being passed will be written into in BE."

Sponsored by:	Tag1 Consulting, Inc.
2020-09-23 01:37:01 +00:00
Brandon Bergren c16359cf66 [PowerPC64LE] powernv ILE setup code.
When running without a hypervisor, we need to set the ILE bit in the LPCR
ourselves.

For the boot processor, handle it in powernv_attach() like we do for other
LPCR bits.

No change for the APs, as they will use the lpcr global to set up their own
LPCR when they do their own cpudep_ap_early_bootstrap() and pick up this
automatically.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-23 00:32:50 +00:00
Brandon Bergren dadfbc2e60 [PowerPC64LE] LE opal_call() implementation
OPAL runs in big endian, so we need to rfid into it to switch endian
atomically when branching to it, and we need to do the
RETURN_TO_NATIVE_ENDIAN dance when it returns to us.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-23 00:28:47 +00:00
Brandon Bergren 4efb1ca7d2 [PowerPC64LE] Work around qemu TCG bug in mtmsrd emulation.
The TCG implementation of mtmsrd in qemu blindly copies the entire register
to the MSR, instead of the specific bit positions listed in the ISA.

This means that qemu will prematurely switch endian out from under the
running code instead of waiting for the rfid, causing an immediate trap
as it attempts to interpret the next instruction in the wrong endianness.

To work around this, ensure PSL_LE is still set before doing the mtmsrd.

In the future, we may wish to just turn off translation and unconditionally
use rfid to switch to the ofmsr instead of quasi-switching to the ofmsr.

Add a new platform option so this can be disabled. (And so that we can
conditonalize additional QEMU-specific hacks in the platform code.)

Sponsored by:	Tag1 Consulting, Inc.
2020-09-23 00:09:29 +00:00
Brandon Bergren 15be37cb7f [PowerPC64LE] Fix endianness issues in phyp and opal consoles.
This applies to both pseries and powernv, which were tested at different
points during the patchset development.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-23 00:06:48 +00:00
Brandon Bergren 5c74d551d2 [PowerPC] Fix setting of time in OPAL
There were multiple bugs in the OPAL RTC code which had never been
discovered, as the default configuration of OPAL machines is to
have the BMC / FSP control the RTC.

* Fix calling convention for setting the time -- the variables are passed
directly in CPU registers, not via memory.

* Fix bug in the bcd encoding routines. (from jhibbits)

Tested on POWER9 Talos II (BE) and POWER9 Blackbird (LE).

Reviewed by:	jhibbits (in irc)
Sponsored by:	Tag1 Consulting, Inc.
2020-09-10 01:49:53 +00:00
Brandon Bergren 6957645145 [PowerPC64] Fix xive order calculation in qemu TCG
When emulating a single thread system for testing reasons, mp_maxid can
be 0. This trips up our math for calculating the order.

Account for this to fix xive attachment when emulating a single-thread
core on qemu powernv (a configuration that doesn't exist in the real world.)

Sponsored by:	Tag1 Consulting, Inc.
2020-09-08 23:48:49 +00:00
Mateusz Guzik b64b31338f powerpc: clean up empty lines in .c and .h files 2020-09-01 21:20:08 +00:00
Brandon Bergren b94b2fcd61 [PowerPC64] Fix invalid OPAL call in xive_bind().
This fixes spurious "XIVE[ IC 00  ] ISN 1 lead to invalid IVE !" messages
generated by OPAL when running with the debug level cranked up.

Discussed with jhibbits.

Sponsored by:	Tag1 Consulting, Inc.
2020-08-21 03:23:10 +00:00
Brandon Bergren 60185d8965 [PowerPC] XIVE dispatch tweaks
* Only read the DPCPU pointer once per xive_dispatch call.
  * Optimize HE decoding for the common cases.

Reported by:	jhibbits (in irc)
Reviewed by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D25545
2020-07-06 15:15:37 +00:00
Justin Hibbits 46e8ab5aa1 powerpc/powernv: Don't use the vmem quantum cache for OPAL PCI MSI allocations
vmem quantum cache is only needed when doing a lot of concurrent allocations,
which doesn't happen when allocating MSIs.  This wastes memory for the cache
zones.  Avoid this waste and don't use the quantum cache.

Reported by:	markj
2020-06-10 04:08:16 +00:00
Justin Hibbits e48f804f8c powerpc/powernv: Don't configure disabled CPUs
If the POWER firmware detects a bad CPU core, it will "GUARD" it out,
marking it disabled.  Any attempt to spin up a bad CPU will trigger a panic
later on when waiting for threads on said core to wake up.  Support limping
along on fewer cores instead.
2020-06-08 02:28:00 +00:00
Justin Hibbits 6df6aae9bd powerpc/powernv: powernv_node_numa_domain() fix non-NUMA case
If NUMA is not enabled in the kernel config, or is disabled at boot, this
function should just return domain 0 regardless of what's in the device
tree.

Fixes a panic in iflib with NUMA disabled.

Reported by:	luporl
2020-03-03 03:22:00 +00:00
Pawel Biernacki 7029da5c36 Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)
r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE.  All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by:	kib (mentor, blanket)
Commented by:	kib, gallatin, melifaro
Differential Revision:	https://reviews.freebsd.org/D23718
2020-02-26 14:26:36 +00:00
Leandro Lupori a9d8f71f7b [PPC64] Fix NUMA on POWER8
On some POWER8 machines, 'ibm,associativity' property may have 6
cells, which would overflow the 5 cells buffer being used.
There was also an issue with the "check if node is root" part,
that have been fixed too.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D23414
2020-01-29 18:13:44 +00:00
Justin Hibbits 490ebb8f35 powerpc: Fix the NUMA domain list on powernv
Summary:
Consolidate the NUMA associativity handling into a platform function.
Non-NUMA platforms will just fall back to the default (0).  Currently
only implemented for powernv, which uses a lookup table to map the
device tree associativity into a system NUMA domain.

Fixes hangs on powernv after r356534, and corrects a fairly longstanding
bug in powernv's NUMA handling, which ended up using domains 1 and 2 for
devices and memory on power9, while CPUs were bound to domains 0 and 1.

Reviewed by:	bdragon, luporl
Differential Revision:	https://reviews.freebsd.org/D23220
2020-01-18 01:26:54 +00:00
Justin Hibbits 03b6e7a627 powerpc/powernv: Un-Giant-ify opal_nvram driver
It may be possible to make this completely lock free, but for now it's using
a statically allocated bounce buffer in the softc, so it needs to be
guarded.
2020-01-10 01:24:49 +00:00
Brandon Bergren 9367fb301c [PowerPC] Fix panic when attempting to handle an HMI from an idle thread
In IRC, sfs_ finally managed to get a good trace of a kernel panic that was
happening when attempting to use webengine.

As it turns out, we were using vtophys() from interrupt context on an idle
thread in opal_hmi_handler2().

Since this involves locking the kernel pmap on PPC64 at the moment, this
ended up tripping a KASSERT in mtx_lock(), which then caused a parallel
panic stampede.

So, avoid this by preallocating the flags variable and storing it in PCPU.

Fixes "panic: mtx_lock() by idle thread 0x... on sleep mutex kernelpmap".

Differential Revision:	https://reviews.freebsd.org/D22962
2019-12-30 02:56:47 +00:00
Justin Hibbits 1223b40eba powerpc/powernv: Set the PTCR for the Nest MMU
The Nest MMU manages address translation for accelerators on the POWER9.  To
do so, it needs a page table, so export the system page table to the Nest
MMU.  This will quietly fail on pre-POWER9 systems that do not have a NMMU.

The NMMU is currently unused, so this change is currently effectively a NOP,
but the NMMU and VAS will eventually be used.
2019-12-15 21:20:18 +00:00
Leandro Lupori a16111e6a2 [PPC64] Enable opal console use as a GDB DBGPORT
This change makes it possible to use OPAL console as a GDB debug port.

Similar to uart and uart_phyp debug ports, it has to be enabled by
setting the hw.uart.dbgport variable to the serial console node
of the device tree.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D22649
2019-12-09 13:09:32 +00:00
Justin Hibbits 0b4753405b powerpc64/powernv: Use OPAL call for non-POWER8 PCI TCE reset
According to the OPAL documentation, only the POWER8 (PHB3) should use
the register write TCE reset method.  All others should use the OPAL
call.

On POWER9 the call is semantically identical to the register write, with
a wait for completion.
2019-11-10 04:24:36 +00:00
Justin Hibbits 1c56203bcf powerpc64/powernv: Add opal NVRAM driver for PowerNV systems
Add a very basic NVRAM driver for OPAL which can be used by the IBM
powerpc-utils nvram utility, not to be confused with the base nvram utility,
which only operates on powermac_nvram.

The IBM utility handles all partitions itself, treating the nvram device as
a plain store.

An alternative would be to manage partitions in the kernel, and augment the
base nvram utility to deal with different backing stores, but that
complicates the driver significantly.  Instead, present the same interface
IBM's utlity expects, and we get the usage for free.

Tested by:	bdragon
2019-09-14 03:30:34 +00:00
Justin Hibbits 84ce4f0375 powerpc/powernv: Fix OPAL cfgread/cfgwrite error handling
Freeze clearing needs to heppen any time OPAL reads return either an error
(except OPAL_HARDWARE), AND any time it returns 0xff for all bytes.

For cfgwrite, any error that's not OPAL_HARDWARE should be cleaned up.
2019-08-03 01:55:51 +00:00
Justin Hibbits 0effb2ccf3 powerpc/powernv: Only clear EEH freeze for some errors
Only clear an EEH freeze if an error occurs.  However, if an OPAL_HARDWARE
error is returned, this indicates a hardware failure which cannot be
unfrozen, and instead needs a hardware reset.  Attempting to unfreeze a
broken PCH will result in console spam for each attempt.  To avoid the spam,
just don't do it.
2019-08-01 03:59:25 +00:00
Justin Hibbits fdb916d53e powernv: Port HMI handler to use the message framework
When an HMI occurs a message event also gets created with the details of the
exception.  Hook into the messaging framework to retrieve the HMI message.
Nothing is done with it yet, except to panic on unhandled exception.
2019-06-10 03:24:38 +00:00
Justin Hibbits f433dab2de powerpc/powernv: Reduce the scope of the sensor guarding mutex
vmem_xalloc() cannot be called while holding a nonblocking mutex, warned
by WITNESS.  The lock may not be necessary in general, but it avoids
superfluous concurrent OPAL calls for the same sensor.

Reported by:	pkubaj
2019-06-10 03:16:55 +00:00
Conrad Meyer e2e050c8ef Extract eventfilter declarations to sys/_eventfilter.h
This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h"
in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header
pollution substantially.

EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c
files into appropriate headers (e.g., sys/proc.h, powernv/opal.h).

As a side effect of reduced header pollution, many .c files and headers no
longer contain needed definitions.  The remainder of the patch addresses
adding appropriate includes to fix those files.

LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by
sys/mutex.h since r326106 (but silently protected by header pollution prior
to this change).

No functional change (intended).  Of course, any out of tree modules that
relied on header pollution for sys/eventhandler.h, sys/lock.h, or
sys/mutex.h inclusion need to be fixed.  __FreeBSD_version has been bumped.
2019-05-20 00:38:23 +00:00
Justin Hibbits b4698b7a6c powerpc: Drop OPAL_HANDLE_HMI2 for now, to avoid panicking
It's possible for a Hypervisor Maintenance Interrupt (HMI) to occur while in
the pmap code, holding locks.  This can cause WITNESS to panic due to lock
errors in calling pmap_kextract().  Since we don't yet handle the flags
returned by OPAL_HANDLE_HMI2, just stop using it, so that we don't call into
pmap_kextract().

Reported by:	pkubaj
2019-05-02 03:39:03 +00:00
Justin Hibbits e2e3e7d28e powerpc: Make OPAL root node probe at bus pass
This way its children can attach earlier if needed, and some subsystems are
attached earlier, like the asynchronous token management.

MFC after:	2 weeks
2019-04-29 01:10:57 +00:00