History log of /freebsd-current/sys/powerpc/ofw/ofw_machdep.c
Revision Date Author Comments
# b52dceb8 27-Feb-2024 Shawn Anastasio <sanastasio@raptorengineering.com>

powerpc: Bump maximum number of FDT reserved mem entries

Newer firmware on POWER systems, including v2.10 of the Talos II and
Blackbird firmware can end up reserving more than 32 memory regions in
the device tree, which exceeded an assumption made by ofw_machdep.c's
excise_fdt_reserved(). Bump the maximum number of FDT reservations to
the next power of 2 in order to fix booting on newer firmware.

PR: 277097
Reviewed by: jhibbits
Differential Revision: https://reviews.freebsd.org/D44015


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 429ba161 25-Feb-2023 Piotr Kubaj <pkubaj@FreeBSD.org>

powerpc: fix warning: a function declaration without a prototype is deprecated in all versions of C

Reviewers: #powerpc
Approved by: alfredo

Subscribers: imp, jhibbits

Differential Revision: https://reviews.freebsd.org/D38787


# a6625592 22-Sep-2020 Brandon Bergren <bdragon@FreeBSD.org>

[PowerPC64LE] LE bringup work: locore / machdep / platform

This is the initial LE changes required in the machdep code to get as far
as platform attachment on qemu pseries.

Sponsored by: Tag1 Consulting, Inc.


# b64b3133 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

powerpc: clean up empty lines in .c and .h files


# 490ebb8f 17-Jan-2020 Justin Hibbits <jhibbits@FreeBSD.org>

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


# 12fe21a3 27-Dec-2019 Brandon Bergren <bdragon@FreeBSD.org>

[PowerPC] Ignore fortify-source warning in trap vector copy

Due to a bug in clang 9.0.0 source tracking, the trap vector copying will
always trigger a fortify-source warning.

The destination buffers are 0x2f00 bytes, and the bcopy region is 0x2e00
bytes, so there is not an overflow here.

(I have been running with this patch since September.)


# f2c7768c 22-Oct-2019 Leandro Lupori <luporl@FreeBSD.org>

[PPC] Avoid underflows in NUMA domains

On POWER8 systems with only one memory domain, the "ibm,associativity"
number that corresponds to it is 0, unlike POWER9 systems with two
or more domains, in which the minimum value is 1.

In POWER8 case, subtracting 1 causes an underflow on the unsigned domain
variable and a subsequent index out-of-bounds access.

Reviewed by: jhibbits
Tested by: bdragon, luporl


# e2e050c8 19-May-2019 Conrad Meyer <cem@FreeBSD.org>

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.


# 49d9a597 12-Apr-2019 Justin Hibbits <jhibbits@FreeBSD.org>

Add NUMA support to powerpc

Summary:
Initial NUMA support:
- associate CPU with domain
- associate memory ranges with domain
- identify domain for devices
- limit device interrupt binding to appropriate domain

- Additionally fixes a bug in the setting of Maxmem which led to
only memory attached to the first socket being enabled for DMA

A pmap variant can opt in to numa support by by calling `numa_mem_regions`
at the end of pmap_bootstrap - registering the corresponding ranges with the
VM.

This yields a ~20% improvement in build times of llvm on dual socket POWER9
over non-NUMA.

Original patch by mmacy.

Differential Revision: https://reviews.freebsd.org/D17933


# fd8cf3be 24-Sep-2018 Justin Hibbits <jhibbits@FreeBSD.org>

powerpc: Blacklist the top 64kB range of the lower 4GB PA space

The PHB4 host bridge used by the POWER9 uses a 64kB range in 32-bit
space at the address 0xffff0000-0xffffffff. Reserve this range so that
DMA memory cannot be allocated within this range. This fixes seemingly
random crashes on a POWER9 system. Ideally this range will have been
reserved by the firmware, but as of now this is not the case.

Submitted by: git_bdragon.rtk0.net
Reviewed by: nwhitehorn
Approved by: re(kib)
Differential Revision: https://reviews.freebsd.org/D17183


# 6d645c57 07-Jun-2018 Breno Leitao <leitao@FreeBSD.org>

Fix excise_initrd_region() to support 32- and 64-bit initrd params.

Changed excise_initrd_region to support both 32- and 64-bit
values for linux,initrd-start and linux,initrd-end.

This fixes the boot problem on some machines after rS334485.

Submitted by: Luis Pires <lffpires@ruabrasil.org>
Reviewed by: jhibbits, leitao
Approved by: jhibbits (mentor)
Differential Revision: https://reviews.freebsd.org/D15667


# 48f64992 31-May-2018 Breno Leitao <leitao@FreeBSD.org>

powerpc64: Avoid overwriting initrd area

Currently kexec loads an initrd file into the main memory but does not
mark that region as reserved, thus the area is not protected.

If any initrd/md file is loaded from kexec/petitboot, the region might become
corarupted/overwritten since FreeBSD does not know the region is 'reserved'.

This patch simply adds the initrd area as a reserved memory region.

Approved by: jhibbits
Differential Revision: https://reviews.freebsd.org/D15610


# c07c77a3 18-May-2018 Justin Hibbits <jhibbits@FreeBSD.org>

Fix a manual copy from the original diff for r333825

The 'else' was in the original diff.

Submitted by: Breno Leitao


# 876f3b92 18-May-2018 Justin Hibbits <jhibbits@FreeBSD.org>

Add yet another option for gathering available memory

On some POWER9 systems, 'reg' denotes the full memory in the system, while
'linux,usable-memory' denotes the usable memory. Some memory is reserved for
NVLink usage, so is partitioned off.

Submitted by: Breno Leitao


# 42ca1d5c 24-Apr-2018 Justin Hibbits <jhibbits@FreeBSD.org>

Increase the fdtmemreserv array limit to boot on POWER9

Discussing with others, this needs to be at least 20 to boot on some POWER9
nodes. Linux made a similar change for the same reason, so increase to 32
to give us some extra breathing room as well. The input and output arrays
are sized at 256, so much greater than the increase in the property array
size.


# 35feca37 10-Mar-2018 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Make FDT-using parts of ofw_machdep.c condition on options FDT. This fixes
the kernel build when options FDT is absent.


# f9edb09d 07-Mar-2018 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Move the powerpc64 direct map base address from zero to high memory. This
accomplishes a few things:
- Makes NULL an invalid address in the kernel, which is useful for catching
bugs.
- Lays groundwork for radix-tree translation on POWER9, which requires the
direct map be at high memory.
- Similarly lays groundwork for a direct map on 64-bit Book-E.

The new base address is chosen as the base of the fourth radix quadrant
(the minimum kernel address in this translation mode) and because all
supported CPUs ignore at least the first two bits of addresses in real
mode, allowing direct-map addresses to be used in real-mode handlers.
This is required by Linux and is part of the architecture standard
starting in POWER ISA 3, so can be relied upon.

Reviewed by: jhibbits, Breno Leitao
Differential Revision: D14499


# 222393d5 12-Jan-2018 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Chase removal of FDT fixup code on PowerPC in r327907.


# 2bfca577 27-Nov-2017 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Back out OF module installation in the event of failure. PS3 firmware gives
some ancient FDT version (2) that fails the init check in OFW_FDT. It is
still possible to make progress, but not while the OF layer is going crazy.


# 71e3c308 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/powerpc: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# 91419bda 25-Nov-2017 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Avoid assumptions about the BSP being CPU 0.

MFC after: 3 weeks


# c0650b2f 25-Nov-2017 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

When booting from an FDT, make sure the FDT itself isn't included the range
of available memory. Boot loaders are supposed to add a reserved entry for
it, but not all do.

MFC after: 2 weeks


# bb7137e1 16-Nov-2017 Justin Hibbits <jhibbits@FreeBSD.org>

Stop special casing 32-bit AIM in memory parsing

There's no need to special case 32-bit AIM to short circuit processing.
Some AIM CPUs can handle 36 bit addresses, and 64-bit CPUs can run 32-bit
OSes, so this will allow us to expand for that in the future if we desire.


# 95ce4c00 19-Oct-2017 Justin Hibbits <jhibbits@FreeBSD.org>

No need to check for AIM here

This block is already in a #ifdef AIM block.


# 67d955aa 08-Apr-2017 Patrick Kelsey <pkelsey@FreeBSD.org>

Corrected misspelled versions of rendezvous.

The MFC will include a compat definition of smp_no_rendevous_barrier()
that calls smp_no_rendezvous_barrier().

Reviewed by: gnn, kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D10313


# 62c6b30e 07-Mar-2017 Justin Hibbits <jhibbits@FreeBSD.org>

Fix booting with >4GB RAM on PowerMac G5 hardware

===
From Nathan Whitehorn:

Open Firmware runs in virtual mode on the Powermac G5. This runs inside the
kernel page table, which preserves all address translations made by OF before
the kernel starts; as a result, the kernel address space is a strict superset of
OF's.

Where this explodes is if OF uses an unmapped SLB entry. The SLB fault handler
runs in real mode and refers to the PCPU pointer in SPRG0, which blows up the
kernel. Having a value of SPRG0 that works for the kernel is less fatal than
preserving OF's value in this case.

===

The result of this is seemingly random panics from NULL dereferences, or hangs
immediately upon boot. By not restoring SPRG0 for Open Firmware entry the
kernel PCPU pointer is preserved and SLB faults are successful, resulting in a
stable kernel.

PR: 205458
Reported by: several (over bugzilla, lists, IRC)
Reviewed by: andreast
Tested by: many (various forms)
MFC after: 2 weeks


# d80cb37f 21-Sep-2016 Justin Hibbits <jhibbits@FreeBSD.org>

Revert part of r306065

This is a separate change I was testing.


# 9ed9b267 20-Sep-2016 Justin Hibbits <jhibbits@FreeBSD.org>

Add a ofw_parse_bootargs function, and use it for powerpc

Summary:
If the environment variable is set, U-boot adds a 'bootargs' property to
/chosen. This is already handled by ARM and MIPS, but should be handled in a
central location. For now, ofw_subr.c is a good place until we determine if it
should be moved to init_main.c, or somewhere more central to all architectures.

Eventually arm and mips should be modified to use ofw_parse_bootargs() as well,
rather than using the duplicate code already.

Reviewed By: adrian
Differential Revision: https://reviews.freebsd.org/D7846


# 45fd1862 16-Feb-2016 Andrew Turner <andrew@FreeBSD.org>

Allow callers of OF_decode_addr to get the size of the found mapping. This
will allow for code that uses the old fdt_get_range and fdt_regsize
functions to find a range, map it, access, then unmap to replace this, up
to and including the map, with a call to OF_decode_addr.

As this function should only be used in the early boot code the unmap is
mostly do document we no longer need the mapping as it's a no-op, at least
on arm.

Reviewed by: jhibbits
Sponsored by: ABT Systems Ltd
Differential Revision: https://reviews.freebsd.org/D5258


# b3936ebe 23-Dec-2015 Justin Hibbits <jhibbits@FreeBSD.org>

Extend Book-E to support >4GB RAM

Summary:
With some additional changes for AIM, that could also support much
larger physmem sizes. Given that 32-bit AIM is more or less obsolete, though,
it's not worth it at this time.

Differential Revision: https://reviews.freebsd.org/D4345


# bc7b9300 21-Dec-2015 Ian Lepore <ian@FreeBSD.org>

Implement OF_decode_addr() for arm. Move most of powerpc's implementation
into a new function that other platforms can share.

This creates a new ofw_reg_to_paddr() function (in a new ofw_subr.c file)
that contains most of the existing ppc implementation, mostly unchanged.
The ppc code now calls the new MI code from the MD code, then creates a
ppc-specific bus_space mapping from the results. The new arm implementation
does the same in an arm-specific way.

This also moves the declaration of OF_decode_addr() from ofw_machdep.h to
openfirm.h, except on sparc64 which uses a different function signature.

This will help all FDT platforms to set up early console access using
OF_decode_addr().


# 509142e1 17-Nov-2015 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Where appropriate, use the endian-flipping OF_getencprop() instead of
OF_getprop() to get encode-int encoded values from the OF tree. This is
a no-op at present, since all existing PowerPC ports are big-endian, but
it is a correctness improvement and will be required if we have a
little-endian kernel at some future point.

Where it is totally impossible for the code ever to be used on a
little-endian system (much of powerpc/powermac, for instance), I have not
necessarily made the appropriate changes.

MFC after: 1 month


# 8c092157 23-Aug-2015 Justin Hibbits <jhibbits@FreeBSD.org>

Fix static fdt support.

FDT_DTB_STATIC is defined in opt_platform.h, and fdt_static_dtb is in
fdt_common.h, so include those files.

Sponsored by: Alex Perez/Inertial Computing


# 6f489d43 29-Apr-2015 Justin Hibbits <jhibbits@FreeBSD.org>

Missed ofw_machdep.c in r282264.


# 922a3152 31-Jan-2015 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Correctness improvements for removing FDT excluded memory areas.


# b9d056f3 19-Jan-2015 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Remove space in the FDT reservation map from the available memory regions
in ofw_mem_regions(). This function is actually MI and should move to
dev/ofw at some point in the near future so that ARM and MIPS can use the
same code.


# bb808254 18-Jan-2015 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Refactor PowerPC (especially AIM) init sequence to be less baroque.

MFC after: 2 months


# 6e127b87 02-Jan-2015 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Remove last vestige of Apple-specific memory parsing removed in r258807.


# 44d29d47 01-Jan-2015 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Allow booting with both a real Open Firmware tree and a flattened version of
the Open Firmware, as provided by petitboot, for example. Note that this is
not quite complete, since RTAS instantiation still depends on callable
firmware.

MFC after: 2 weeks


# 4aa3cee6 01-Dec-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Revert last few revisions; apologies for the noise. There are very rare,
broken systems that require SPRG state to be preserved.


# c7291bdc 01-Dec-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Deleted one line too many.


# ff4ae2ea 01-Dec-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

No actual hardware supported by FreeBSD requires this SPRG save/restore
paranoia, so kill it. In particular, changes to SPRG0 are dangerous, since
that is where the PCPU pointer is kept.


# c1cb22d7 01-Dec-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Rearchitect platform memory map parsing to make it less
Open Firmware-centric:
- Keep the static list of regions in platform.c instead of ofw_machdep.c
- Move various merging and sorting operations to platform.c as well
- Move apple_hacks code out of ofw_machdep.c and into platform_powermac.c,
where it belongs
- Move CHRP-specific dynamic-reconfiguration memory parsing into
platform_chrp.c instead of pretending it is shared code


# 86b2b302 30-Nov-2013 Andreas Tobler <andreast@FreeBSD.org>

Add a printf to inform about the logical memory block size which is in use
by the system. This might give a hint why a pSeries system is not booting.


# f367ffde 23-Nov-2013 Andreas Tobler <andreast@FreeBSD.org>

Save and restore the trap vectors when doing OF calls on pSeries machines.

It turned out that on pSeries machines the call into OF modified the trap
vectors and this made further behaviour unpredictable.

With this commit I'm now able to boot multi user on a network booted
environment on my IntelliStation 285. This is a POWER5+ machine.

Discussed with: nwhitehorn
MFC after: 1 week


# 629aa519 11-Nov-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Make tsec work with the device tree present on the RB800. The previous code
assumed that the MDIO bus was a direct child of the Ethernet interface. It
may not be and indeed on many device trees is not. While here, add proper
locking for MII transactions, which may be on a bus shared by several MACs.

Hardware donated by: Benjamin Perrault


# 43a581e1 11-Nov-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Allow OF_decode_addr() to also be able to map resources on big-endian
devices. To this end, make PCI device detection rely on the device_type
field rather than name, as per the standard.


# bcb6fb8b 11-Nov-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Consolidate Apple firmware hacks and improve them by switching on the
presence of mac-io devices in the tree, which uniquely identifies Apple
hardware.

MFC after: 6 weeks


# 9f706727 27-Sep-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Rework handling of ofw_quiesce(), making it the responsibility of the
platform modules. Whether to call this function or not is highly machine
dependent: on some systems, it is required, while on others it breaks
everything. Platform modules are in a better position to figure this
out. This is required for POWER hypervisor SCSI to work correctly. There
are no functional changes on Powermac systems.

Approved by: re (kib)


# 023864f6 26-Sep-2013 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Allow Open Firmware syscons to attach to devices without an "address"
property such as those found on some real and emulated IBM systems. The
approach, which is taken from Linux, is to scan through the PCI bars
until we find one large enough to contain the linear framebuffer and
which is ideally prefetchable if no "address" property can be found.
This makes the graphical console work with the pSeries target in QEMU.

Approved by: re (delphij)


# 8bab0d80 20-Jan-2012 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Prevent an error resulting from signed/unsigned comparison on systems
that do not comply with the OF spec.

Submitted by: Anders Gavare
MFC after: 1 week


# d8c6808a 03-Jun-2011 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Retry the memory map-related portions of r222613, written by andreast,
after some minor tweaks and an increase in the early-boot stack space in
r222632.


# 48174c14 02-Jun-2011 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Temporarily back out those parts of r222613 related to parsing the memory
map. They cause non-understood boot failures on some Apple machines with
more than 2 GB of RAM (like my work desktop).


# 17879090 02-Jun-2011 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

MFpseries:
Renovate and improve the AIM Open Firmware support:
- Add RTAS (Run-Time Abstraction Services) support, found on all IBM systems
and some Apple ones
- Improve support for 32-bit real mode Open Firmware systems
- Pull some more OF bits over from the AIM directory
- Fix memory detection on IBM LPARs and systems with more than one /memory
node (by andreast@)


# 797c37ee 09-Mar-2011 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Fix whitespace nit.


# fe3b4685 11-Nov-2010 Nathan Whitehorn <nwhitehorn@FreeBSD.org>

Remove use of a separate ofw_pmap on 32-bit CPUs. Many Open Firmware
mappings need to end up in the kernel anyway since the kernel begins
executing in OF context. Separating them adds needless complexity,
especially since the powerpc64 and mmu_oea64 code gave up on it a long
time ago.

As a side effect, the PPC ofw_machdep code is no longer AIM-specific,
so move it to powerpc/ofw.