Commit Graph

333 Commits

Author SHA1 Message Date
Warner Losh
031beb4e23 sys: Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:58 -06: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
Emmanuel Vadot
81b41b2ef5 ofw_firmware: Return BUS_PROBE_GENERIC instead of 0
While here make it only probe if the node is directly under the root
one. If it's not it's likely a device node named 'firmware' and not the
firmware group we're interested in.

Suggested by:	jhb
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2023-08-15 08:45:22 +02:00
Emmanuel Vadot
69f8cc60aa ofw_firmware: Only match if there is no compatible
If there is a compatible string it likely means that the firmware needs
a dedicated driver (like on RPI*).

PR:	273087
Tested-by:	Mark Millard <marklmi26-fbsd@yahoo.com>
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Fixes:		fdfd3a90b6 ("ofw: Add a ofw_firmware driver")
2023-08-13 11:19:44 +02:00
Emmanuel Vadot
fdfd3a90b6 ofw: Add a ofw_firmware driver
Some SoCs have an external firmware doing power management, clock
and other stuffs. (Xilinx, ARM Juno etc ...)
The way it is represent in the DTB is usually having a 'firmware' node
under the root node and have some nodes under it with the correct
compatible strings.
The firmware node itself doesn't have any compatible strings.
This driver is simple subclassed from simplebus and attaches at
BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE so early drivers (like clock drivers)
can still have a change to attach early.

Reviewed by:	andrew
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D37612
2023-08-08 15:13:31 +02:00
Marius Strobl
29fe5efc8a ofw(4): Add my copyright and additional history for ofw_reg_to_paddr()
The ofw_reg_to_paddr() in this file is the powerpc OF_decode_addr()
formerly added in 812403402e. However,
the latter function in turn was based on the sparc64 counterpart I
previously added in 2b2250b149.
2023-07-26 13:14:22 +02:00
Christos Margiolis
9105ba0471 ofw: remove redundant calls in ofwbus_attach()
Since commit ecaecbc7d8, calling
ofw_bus_gen_setup_devinfo() is redundant, as the call to
device_set_ivars() now happens inside simplebus_add_device().

Reviewed by:	markj
Approved by:	markj (mentor)
Differential Revision:	https://reviews.freebsd.org/D40271
2023-05-25 23:47:41 +03:00
Mitchell Horne
08637d5d15 ofw_cpu: quiet secondary CPU devices
We already do plenty to announce the different CPUs in dmesg. Follow the
ACPI CPU strategy of reporting the first CPU device, but quieting the
rest for non-verbose boot. This cuts down slightly on dmesg output.

Reviewed by:	manu, jhb
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40243
2023-05-24 10:28:26 -03:00
Mitchell Horne
5edffecc4b ofw_cpu: whitespace cleanup
Reviewed by:	jhb, emaste
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40242
2023-05-24 10:28:26 -03:00
Warner Losh
b61a573019 spdx: The BSD-2-Clause-NetBSD identifier is obsolete, drop -NetBSD
The SPDX folks have obsoleted the BSD-2-Clause-NetBSD 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:04 -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
afdb42987c ofw_cpu_early_foreach: Change callback to return bool instead of boolean_t.
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D39926
2023-05-04 12:33:39 -07:00
Christos Margiolis
38594ff9c0 ofw: fix memory leak in ofwbus_attach()
PR:		269509
Reported by:	Jaroslaw Pelczar <jarek@jpelczar.com>
Reviewed by:	markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38903
2023-04-10 12:14:12 -04:00
Mitchell Horne
afca197f52 ofwbus: only allow unit number zero
ofwbus has always been the root of attachment for OFW/FDT platforms. It
may have simplebus children, but we expect only one instance of the
ofwbus driver, added directly by nexus. We may as well ensure this
remains the case.

Reviewed by:	jhb
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D38493
2023-02-13 13:45:01 -04:00
Mitchell Horne
53d5e65eea ofwbus: remove arm64 ifdefs
Rather than using the DEVICE_IDENTIFY method, let's have other
ofwbus-using platforms add ofwbus0 explicitly in nexus, like arm64. This
gives them the same flexibility, e.g. if riscv starts supporting ACPI,
and cleans up the #ifdefs.

We were doing this already on riscv, but adjust the 'order' parameters.

Reviewed by:	andrew, jhb
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D38492
2023-02-13 13:45:01 -04:00
Mitchell Horne
99553344e9 ofwbus: trim includes
Nothing in the file today relies on these.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D38491
2023-02-13 13:45:01 -04:00
Elliott Mitchell
f9bdaab95e ofwbus: remove handling of resources from ofwbus
The architecture nexus should handle allocation and release of memory and
interrupts. This is to ensure that system-wide resources such as these
are available to all devices, not just children of ofwbus0.

On powerpc this moves the ownership of these resources up one level,
from ofwbus0 to nexus0. Other architectures already have the required
logic in their nexus implementation, so this eliminates the duplication
of resources. An implementation of nexus_adjust_resource() is added for
arm, arm64, and riscv.

As noted by ian@ in the review, resource handling was the main bit of
logic distinguishing ofwbus from simplebus. With some attention to
detail, it should be possible to merge the two in the future.

Co-authored by:	mhorne
MFC after:	1 month
Differential Revision: https://reviews.freebsd.org/D30554
2023-02-08 16:50:46 -04:00
Takanori Watanabe
7b5d62bb73 ofw: add BUS_GET_DEVICE_PATH interface to openfirm/fdt, somewhat incomplete.
This add BUS_GET_DEVICE_PATH interface,
which shows device tree of openfirm/fdt.

In qemu-system-arm64 with "virt" machine with device-tree firmware,
% devctl getpath OFW cpu0

Reviewed by: andrew
Differential Revision: https://reviews.freebsd.org/D37031
2022-10-18 16:55:47 +09:00
John Baldwin
7ae99f80b6 pmap_unmapdev/bios: Accept a pointer instead of a vm_offset_t.
This matches the return type of pmap_mapdev/bios.

Reviewed by:	kib, markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36548
2022-09-22 15:08:52 -07:00
Andrew Turner
ec666d187d Adjust function definition in ofw to avoid clang 15 warning
With clang 15, the following -Werror warning is produced:

    sys/dev/ofw/openfirm.c:826:9: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    OF_enter()
            ^
             void

This is because OF_enter() and OF_exit are declared with a (void)
argument list, but defined with an empty argument list. Make the
definition match the declaration.

Sponsored by:	The FreeBSD Foundation
2022-08-11 14:30:32 +01:00
Andrew Turner
b1e9313274 Fix ofw pcib when it rman_init fails
rman_fini assumes rman_init has been called successfully. Clean up
init faulure by only calling rman_fini when rman_init has succeeded.

While here add ofw_pcib_fini that can be used by a sub-class to clean
up.

Reviewed by:	bz, imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35681
2022-07-04 15:27:00 +01:00
John Baldwin
03f6459cb3 ofw drivers: Remove unused devclass arguments to DRIVER_MODULE. 2022-05-09 14:26:44 -07:00
Ruslan Bukin
0c0bfa0f6f Fix ofw_bus_iommu_map() since there is no limit on amount of maps
described in "iommu-map" DTS property.

Pointed out by:	rpokala
Sponsored by:	UKRI
2022-05-06 18:09:42 +01:00
Ruslan Bukin
0b6bacc787 Add ofw_bus_iommu_map() that maps PCI requester ID to an IOMMU
specifier based on "iommu-map" DTS property.

Sponsored by: UKRI
2022-05-06 16:48:04 +01:00
Mike Karels
b8b0c65e8a Add serial-number to hw.fdt sysctl area if found in fdt.
Add serial-number sysctl if that fdt property exists and is a printable
string.  While here, ensure that the hw.fdt sysctl values fit in the
buffers provided so that they will be NUL-terminated.  Tested on
Raspberry Pi 3B+ and 4.

MFC after:	5 days
Reviewed by:	manu imp
Differential Revision: https://reviews.freebsd.org/D34356
2022-03-03 07:08:32 -06:00
Emmanuel Vadot
02398e581d ofw_cpu: Make ext_resources non-optional for arm* and riscv
EXT_RESOURCES have been introduced in 12-CURRENT and all supported
releases have it enabled in their kernel config.
For RISC-V it was always enabled.

MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D33835
2022-02-21 17:29:07 +01:00
Jessica Clarke
4e3a43905e ofw_pci: Fix incorrectly sized softc causing pci(4) out-of-bounds reads
We do not include sys/rman.h and so machine/resource.h ends up not being
included by the time pci_private.h is included. This means PCI_RES_BUS
is never defined, and so the sc_bus member of pci_softc is not present
when compiling ofw_pci, resulting in the wrong softc size being passed
to DEFINE_CLASS_1 and thus any attempts by pci(4) to access that member
are out-of-bounds reads or writes.

This is pretty fragile; arguably pci_private.h should be including
sys/rman.h, but this is the minimal needed change to fix the bug whilst
maintaining the status quo.

Found by:	CHERI
Reported by:	andrew
2022-01-15 19:03:53 +00:00
Mark Johnston
1fb99e97e9 bus: Make BUS_TRANSLATE_RESOURCE behave more like other bus methods
- Return an errno value upon failure, instead of 1.
- Provide a bus_translate_resource() wrapper.
- Implement the generic version, which traverses the hierarchy until a
  bus driver with a non-trivial implementation is found, in subr_bus.c
  like other similar default implementations.
- Make ofw_pcib_translate_resource() return an error if a matching PCI
  address range is not found.
- Make generic_pcie_translate_resource_common() return an int instead of
  a bool.  Fix up callers.

No functional change intended.

Reviewed by:	imp, jhb
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32855
2021-11-15 13:01:30 -05:00
Ed Maste
9feff969a0 Remove "All Rights Reserved" from FreeBSD Foundation sys/ copyrights
These ones were unambiguous cases where the Foundation was the only
listed copyright holder (in the associated license block).

Sponsored by:	The FreeBSD Foundation
2021-08-08 10:42:24 -04:00
Emmanuel Vadot
50e0dc0c4b fdt: Expose the model, compatible and freebsd dts brandind as sysctl
This make it easier for script to get the hardware on which they are running.

MFC after:	1 month
Sponsored by:	Diablotin Systems
Differential Revision:	  https://reviews.freebsd.org/D31205
Reviewed by: 		  imp
Should be ok on powerpc:  jhibbits (over irc)
2021-07-22 14:53:32 +02:00
Kornel Duleba
9428765626 ofw_pci: fix probing for non-DT cases
phandle_t is a uint32_t type, <= 0 comparison doesn't work with it as intended.
This caused the ofw_pci code to attach to PCI bus on ACPI based systems.
Since 3eae4e106a ("Fix error value returned by ofw_bus_gen_get_node().")
ofw subsystem can only return -1 for invalid nodes. Use that.

MFC after: 4 weeks
Reviewed by: mw
Differential revision: https://reviews.freebsd.org/D30953
2021-07-01 20:35:23 +02:00
Michal Meloun
3eae4e106a Fix error value returned by ofw_bus_gen_get_node().
By definition ofw_bus_get_node() should  consistently return -1 when there
is no associated OF node.

MFC after:	4 weeks
Discussed with:	nwhitehorn
Analyzed in: 	https://reviews.freebsd.org/D30761
2021-06-24 12:01:05 +02:00
Warner Losh
c90902d39e bus_child_pnpinfo: fix two stragglers
ddfc9c4c59 was missing changes to two files to complete the
bus_child_pnpinfo_str->bus_child_pnpinfo. This fixes the broken kernel
builds.

Sponsored by:		Netflix
2021-06-22 22:10:31 -06: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
28c4e511c2 Add ofw interface support to PCI
Some arm64 SoCs have nodes in their fdts that describe devices
connected to the internal PCI bus. One such SoC is Freescale LS1028A.
In order to access information stored in them we need to add ofw bus
support to pci. Pass devinfo request up to our parent, which
is responsible for parsing all the information.
It allows to use ofw interface on PCI devices that support it.
This method is similar to sys/dev/acpica/acpi_pci.c.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: andrew
Obtained from: Semihalf
Sponsored by: Alstom Group
Differential Revision: https://reviews.freebsd.org/D30181
2021-06-08 17:52:02 +02:00
Mark Johnston
fbeb4ccac9 Suppress D_NEEDGIANT warnings for some drivers
During boot we warn that the kbd and openfirm drivers are Giant-locked
and may be deleted.  Generally, the warning helps signal that certain
old drivers are not being maintained and are subject to removal, but
this doesn't really apply to certain drivers which are harder to
detangle from Giant.

Add a flag, D_GIANTOK, that devices can specify to suppress the
misleading warning.  Use it in the kbd and openfirm drivers.

Reviewed by:	imp, jhb
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30649
2021-06-06 16:44:46 -04: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
Ruslan Bukin
9146c6240d ofw: support for a single 'port' DTS property.
On rk3399 the VOP-little node has a single 'port' property (not a
collection of 'ports' or indexed ports).

Reviewed by:	manu
Sponsored by:	UKRI
Differential Revision:	https://reviews.freebsd.org/D30165
2021-05-08 15:41:57 +01:00
Marius Strobl
daad26e5fc openpromio(4): remove obsolete pseudo device driver
It's unused since 58aa35d429 and r357455
respectively and should have gone along with these.
2021-01-16 23:53:13 +01:00
Brandon Bergren
26869ad14c [PowerPC] Allow traversal of oversize OF properties.
In standards such as LoPAPR, property names in excess of the usual 31
characters exist.

This breaks property traversal.

While in IEEE 1275-1994, nextprop is defined explicitly to work with a
32-byte region of memory, using a larger buffer should be fine. There is
actually no way to pass a buffer length to the nextprop call in the OF
client interface, so SLOF actually just blindly overflows the buffer.

So we have to defensively make the buffer larger, to avoid memory
corruption when reading out long properties on live OF systems.

Note also that on real-mode OF, things are pretty tight because we are
allocating against a static bounce buffer in low memory, so we can't just
use a huge buffer to work around this without it being wasteful of our
limited amount of 32-bit physical memory.

This allows a patched ofwdump to operate properly on SLOF (i.e. pseries)
systems, as well as any other PowerPC systems with overlength properties.

Reviewed by:	jhibbits
MFC after:	2 weeks
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D26669
2020-11-13 16:49:41 +00:00
Mateusz Guzik
f9874fbbf1 ofw: clean up empty lines in .c and .h files 2020-09-01 22:01:53 +00:00
Kyle Evans
23d5326823 tty: convert tty_lock_assert to tty_assert_locked to hide lock type
A later change, currently being iterated on in D24459, will in-fact change
the lock type to an sx so that TTY drivers can sleep on it if they need to.
Committing this ahead of time to make the review in question a little more
palatable.

tty_lock_assert() is unfortunately still needed for now in two places to
make sure that the tty lock has not been recursed upon, for those scenarios
where it's supplied by the TTY driver and possibly a mutex that is allowed
to recurse.

Suggested by:	markj
2020-04-17 18:34:49 +00:00
Pawel Biernacki
5c2c6e01a6 Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (11 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.

Approved by:	kib (mentor, blanket)
Differential Revision:	https://reviews.freebsd.org/D23636
2020-02-24 10:41:22 +00:00
Warner Losh
58aa35d429 Remove sparc64 kernel support
Remove all sparc64 specific files
Remove all sparc64 ifdefs
Removee indireeect sparc64 ifdefs
2020-02-03 17:35:11 +00:00
Pedro F. Giffuni
64310043ca SPDX: update some tags with two licenses. 2019-12-28 02:58:30 +00:00
Ian Lepore
9977bd1d5b Add an OFWBUS_PNP_INFO() macro for devices that hang directly off the root
ofwbus.  Also, apply some style(9) whitespace fixing to the
SIMPLEBUS_PNP_INFO() macro (no functional change).
2019-11-30 19:16:44 +00:00
Emmanuel Vadot
0f6efb4445 ofw: ofw_reg_to_paddr: Use a 256 static array for the cell
Some hardware needs more than 32, bump this value.

We cannot use the _alloc for of getencprop as this function is called
too early in the boot before pmap is initialized and we only have
2k of stack when cninit is called.

Discussed with:     ian
2019-08-07 13:13:16 +00:00
Justin Hibbits
937a05ba81 Add necessary bits for Linux KPI to work correctly on powerpc
PowerPC, and possibly other architectures, use different address ranges for
PCI space vs physical address space, which is only mapped at resource
activation time, when the BAR gets written.  The DRM kernel modules do not
activate the rman resources, soas not to waste KVA, instead only mapping
parts of the PCI memory at a time.  This introduces a
BUS_TRANSLATE_RESOURCE() method, implemented in the Open Firmware/FDT PCI
driver, to perform this necessary translation without activating the
resource.

In addition to system KPI changes, LinuxKPI is updated to handle a
big-endian host, by adding proper endian swaps to the I/O functions.

Submitted by:	mmacy
Reported by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D21096
2019-08-04 19:28:10 +00:00
Ian Lepore
b609a55345 Define macros making it easier to define bus-specific pnpinfo for FDT systems.
Pnpinfo is bus-specific and requires the bus name. The FDTCOMPAT_PNP_INFO()
macro makes it easier to define new FDT-based pnpinfo for busses other than
simplebus.

Differential Revision:	https://reviews.freebsd.org/D20382
2019-05-23 15:47:30 +00:00