aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/fdt/fdt_common.c
Commit message (Collapse)AuthorAgeFilesLines
* Make sure the memory region definitions are zeroed before use.Luiz Otavio O Souza2025-05-011-0/+3
| | | | | | | | | | | Since only 32bits of the values are read from the fdt, the existing values can compromise the results. Fixes the boot on the Netgate 3100. Reviewed by: andrew, mmel Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D50083
* sys: Move Marvell specific fdt code to sys/arm/mvAndrew Turner2025-04-081-36/+0
| | | | | | | | | fdt_immr_* are only used by the armv7 Marvell code. Move setting the variables there as no new code should need to set them. Reviewed by: cognet Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D49535
* dev/fdt: Add const to pointers to const dataAndrew Turner2025-04-081-7/+7
| | | | | | | | | fdt_data_get and fdt_data_to_res don't change the value of the data passed to them via a pointer. Add const to these pointers. Reviewed by: emaste Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D49703
* dev/fdt: Remove old fdt_get memory functionsAndrew Turner2025-04-081-163/+0
| | | | | | | | These have been replaces with fdt_foreach equivalents so are unused. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D49702
* dev/fdt: Add fdt_foreach_reserved_regionAndrew Turner2025-04-081-0/+49
| | | | | | | | | | | As with fdt_foreach_mem_region add a function that calls a callback for each reserved memory region in /memreserve. This allows us to exclude this memory from the physical map in a way that is safe from overflowing a fixed array on the stack. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D49699
* dev/fdt: Add fdt_foreach_reserved_memAndrew Turner2025-04-081-0/+38
| | | | | | | | | | | As with fdt_foreach_mem_region add a function that calls a callback for each reserved memory region. This allows us to exclude this memory from the physical map in a way that is safe from overflowing a fixed array on the stack. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D49698
* dev/fdt: Add fdt_foreach_mem_regionAndrew Turner2025-04-081-0/+47
| | | | | | | | | | | | | | This is used early in the boot to find physical memory. Previously it needed an array of memory regions to be passed in. We keep finding hardware where this array is too small causing the kernel to smash the stack. Replace with a function that takes a callback that can insert the memory into the physical map directly. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D49697
* sys: Automated cleanup of cdefs and other formattingWarner Losh2023-11-271-1/+0
| | | | | | | | | | | | | | | | 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
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | 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
* Remove "All Rights Reserved" from FreeBSD Foundation sys/ copyrightsEd Maste2021-08-081-1/+0
| | | | | | | These ones were unambiguous cases where the Foundation was the only listed copyright holder (in the associated license block). Sponsored by: The FreeBSD Foundation
* Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)Pawel Biernacki2020-02-261-1/+2
| | | | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=358333
* cpsw: use `phy-handle` in FDT to find PHY addressEd Maste2019-04-031-0/+3
| | | | | | | | | | | | | | | | | | | | In r337703 DTS files were updated to Linux 4.18, including Linux commit 4d8b032d3c03f4e9788a18bbb51b10e6c9e8a56b which removed the `phy_id` property from am335x-bone-common (as the property was deprecated). Use `phy-handle` via fdt_get_phyaddr, keeping the existing code as a fallback for old DTBs. PR: 236624 Submitted by: manu, Gerald Aryeetey <aryeeteygerald_rogers.com> Reported by: Gerald Aryeetey Reviewed by: manu MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D19814 Notes: svn path=/head/; revision=345855
* Handle reserved memory with the no-map property.Andrew Turner2018-05-221-0/+41
| | | | | | | | | | | | | We shouldn't be mapping this memory, so we need to find it so it can be excluded from the phys_avail map. Reviewed by: manu Obtained from: ABT Systems Ltd Sponsored by: Turing Robotic Industries Differential Revision: https://reviews.freebsd.org/D15518 Notes: svn path=/head/; revision=334056
* Replace calls to fdt_is_compatible with ofw_bus_node_is_compatible. TheseAndrew Turner2018-04-081-44/+3
| | | | | | | | | are almost identical so there is no need to keep the former around. Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=332309
* Revert r332277, it contained an unintended extra changeAndrew Turner2018-04-081-2/+75
| | | | Notes: svn path=/head/; revision=332278
* Replace calls to fdt_is_compatible with ofw_bus_node_is_compatible. TheseAndrew Turner2018-04-081-75/+2
| | | | | | | | | are almost identical so there is no need to keep the former around. Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=332277
* Move fdt_is_type to be a Marvell specific function. It's not used by anyAndrew Turner2018-04-081-19/+0
| | | | | | | | | other SoCs. Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=332274
* Remove fdt_pm_is_enabled as it's Marvell specific. Replace the only call toAndrew Turner2018-04-041-13/+0
| | | | | | | | | it with a call to the helper function fdt_pm_is_enabled would call. Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=332026
* Remove fdt_is_enabled, fdt_reg_to_rl, and fdt_get_unit. These are not usedAndrew Turner2018-04-031-86/+0
| | | | | | | | | by anything in the tree. Sponsored by: DARPA, AFRL Notes: svn path=/head/; revision=331925
* [ofw] fix errneous checks for OF_finddevice(9) return valueOleksandr Tymoshenko2018-03-201-2/+2
| | | | | | | | | | | | | | | OF_finddevices returns ((phandle_t)-1) in case of failure. Some code in existing drivers checked return value to be equal to 0 or less/equal to 0 which is also wrong because phandle_t is unsigned type. Most of these checks were for negative cases that were never triggered so trhere was no impact on functionality. Reviewed by: nwhitehorn MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D14645 Notes: svn path=/head/; revision=331229
* Do pass removing some write-only variables from the kernel.Alexander Kabaev2017-12-251-11/+3
| | | | | | | | | | | | This reduces noise when kernel is compiled by newer GCC versions, such as one used by external toolchain ports. Reviewed by: kib, andrew(sys/arm and sys/arm64), emaste(partial), erj(partial) Reviewed by: jhb (sys/dev/pci/* sys/kern/vfs_aio.c and sys/kern/kern_synch.c) Differential Revision: https://reviews.freebsd.org/D10385 Notes: svn path=/head/; revision=327173
* sys/dev: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-271-0/+2
| | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=326255
* Enable parsing simple-bus 'ranges' with multiple entriesMarcin Wojtas2017-08-091-1/+2
| | | | | | | | | | | | | | | | | | | This patch makes possible to boot with up to 8 ranges in soc. Dynamic allocation cannot be used, because ftd_get_ranges function is called early, when malloc is not available. Change is required for the alignment of Marvell Armada 38x device trees present in sys/gnu/dts/arm - originally the platform has 6 entries in simple-bus 'ranges'. Submitted by: Patryk Duda <pdk@semihalf.com> Reviewed by: manu, nwhitehorn, cognet (mentor) Approved by: cognet (mentor) Obtained from: Semihalf Differential Revision: https://reviews.freebsd.org/D11876 Notes: svn path=/head/; revision=322285
* Set the correct default for #address-cells variable when the property doesLuiz Otavio O Souza2017-04-301-1/+1
| | | | | | | | | | | | not exist. This has never caused any issue because #address-cells is mandatory. Sponsored by: Rubicon Communications, LLC (Netgate) MFC after: 2 weeks Notes: svn path=/head/; revision=317604
* Make fdt_is_compatible a static function. It's only used in fdt_common.c.Andrew Turner2016-11-191-1/+3
| | | | | | | Sponsored by: ABT Systems Ltd Notes: svn path=/head/; revision=308830
* Replace OF_getprop ... fdt32_to_cpu with OF_getencprop. The latterAndrew Turner2016-11-111-7/+7
| | | | | | | | | | correctly adjusts for the endian. MFC after: 1 week Sponsored by: ABT Systems Ltd Notes: svn path=/head/; revision=308524
* Add hw.fdt sysctl node.Stephen J. Kiernan2016-08-061-0/+3
| | | | | | | | | | | | | Make FDT blob available via opaque hw.fdt.dtb sysctl, if a DTB has been installed by the time sysctls are registered. Reviewed by: andrew Approved by: sjg (mentor) Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D7411 Notes: svn path=/head/; revision=303803
* Add OF_prop_free function as a counterpart for OF_*prop_allocOleksandr Tymoshenko2016-05-111-3/+3
| | | | | | | | | | | | | | | | | | | - Introduce new OF API function OF_prop_free to free memory allocated by OF_getprop_alloc and OF_getencprop_alloc. Current code just calls free(9) with M_OFWPROP memory class which assumes knowledge about OF_*prop_alloc functions' internals and leads to unneccessary code coupling - Convert some of the free(..., M_OFWPROP) instances to OF_prop_free Files affected by this commit are the ones I was able to test on real hardware. The rest of free(..., M_OFWPROP) instances will be handled with idividual maintainers Reviewed by: andrew Differential Revision: https://reviews.freebsd.org/D6315 Notes: svn path=/head/; revision=299477
* ARM: Parse command line delivered by U-Boot:Michal Meloun2016-03-261-0/+13
| | | | | | | | | | | | | | | | - in atags - in DT blob (by using 'fdt chosen' U-Boot command) The command line must start with guard's string 'FreeBSD:' and can contain list of comma separated kenv strings. Also, boot modifier strings from boot.h are recognised and parsed into boothowto. The command line must be passed from U-Boot by setting of bootargs variable: 'setenv bootargs FreeBSD:boot_single=1,vfs.root.mountfrom=ufs:/dev/ada0s1a' followed by 'fdt chosen' (only for DT based boot) Notes: svn path=/head/; revision=297286
* Make the memory size returned from fdt_get_mem_regions a 64-bit type. ThisAndrew Turner2016-03-011-2/+2
| | | | | | | | | | | | | is the physical memory size so may be larger than a u_long can hold, e.g. on ARM with LPAE we could see an address space of up to 40 bits. On ARM u_long is only 32 bits so the memory size will be truncated, possibly to zero. Reported by: bz Sponsored by: ABT Systems Ltd Notes: svn path=/head/; revision=296265
* Make the fdt_get_mem_regions memsize argument optional. It's only used inAndrew Turner2016-03-011-1/+2
| | | | | | | | | by a few callers. Sponsored by: ABT Systems Ltd Notes: svn path=/head/; revision=296257
* Fix fdt_get_mem_regions() to work with 64-bit addressesWojciech Macek2016-02-291-2/+2
| | | | | | | | | | | | | | | Use u_long instead of uint32_t variables to avoid overflow in case of PA space bigger than 32-bit. Obtained from: Semihalf Submitted by: Michal Stanek <mst@semihalf.com> Sponsored by: Annapurna Labs Approved by: cognet (mentor) Reviewed by: andrew, br, wma Differential revision: https://reviews.freebsd.org/D5393 Notes: svn path=/head/; revision=296189
* Do not require strict compatibility on simplebusZbigniew Bodek2016-01-201-2/+2
| | | | | | | | | | | | | | | | | | Strict compatibility requirement is a root of problems when simplebus' node has two compatibility strings (i.e. on Armada38x). Removing this requirement should not interfere with other platforms. fdt_is_compatible_strict() and fdt_find_compatible() calls were changed in fdt_common.c and mv_common.c. Reviewed by: ian, imp Obtained from: Semihalf Sponsored by: Stormshield Submitted by: Bartosz Szczepanek <bsz@semihalf.com> Differential revision: https://reviews.freebsd.org/D4602 Notes: svn path=/head/; revision=294419
* Rename fdt_find_child to ofw_bus_find_child. There is nothing FDT-specificOleksandr Tymoshenko2015-05-241-17/+0
| | | | | | | | | in this function. Suggested by: andrew@ Notes: svn path=/head/; revision=283503
* Add helper method fdt_find_child to make access to child nodes easier.Oleksandr Tymoshenko2015-05-221-0/+17
| | | | | | | | | Some FDT nodes have complex properties organized as a child sub-nodes (e.g. timing for LCD panel) we need easy way to obtain handles for these sub-nodes Notes: svn path=/head/; revision=283275
* Add support for empty ranges properties within the tree, some vendorAndrew Turner2014-12-191-3/+8
| | | | | | | | | device trees have these, for example the ARM AArch64 Foundation Model. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=275937
* Eliminate fdt_data_verify(). The verification it proceed is wrongRuslan Bukin2014-12-151-64/+6
| | | | | | | | | disallowing us to encode 64-bit register numbers. Discussed with: nwhitehorn, andrew Notes: svn path=/head/; revision=275792
* The ranges parent bus address may just be a tag to the entry in the parentAndrew Turner2014-11-201-4/+87
| | | | | | | | | | | | | node. Take this in to account by searching until we find the range for the root node. Differential Revision: https://reviews.freebsd.org/D1160 Reviewed by: ian Obtained from: ABT Systems Ltd Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=274751
* Replace multiple nearly-identical copies of code to walk through an FDTIan Lepore2014-09-251-40/+0
| | | | | | | | | | | | | | | | | | | node's interrupts=<...> property creating resource list entries with a single common implementation. This change makes ofw_bus_intr_to_rl() the one true copy of that code and removes the copies of it from other places. This also adds handling of the interrupts-extended property, which allows specifying multiple interrupts for a node where each interrupt can have a separate interrupt-parent. The bindings for this state that the property cells contain an xref phandle to the interrupt parent followed by whatever interrupt info that parent normally expects. This leads to having a variable number of icells per interrupt in the property. For example you could have <&intc1 1 &intc2 26 9 0 &intc3 9 4>. Differential Revision: https://reviews.freebsd.org/D803 Notes: svn path=/head/; revision=272109
* Rename OF_xref_phandle() to OF_node_from_xref() and add a new functionIan Lepore2014-09-011-2/+2
| | | | | | | | | that provides the inverse translation, OF_xref_from_node(). Discussed with: nwhitehorn Notes: svn path=/head/; revision=270945
* Catch up with last-second name change.Ian Lepore2014-02-161-1/+1
| | | | Notes: svn path=/head/; revision=261958
* Add a helper routine to depth-search the device tree for a node with aIan Lepore2014-02-161-0/+21
| | | | | | | | | | matching 'compatible' property. This probably has a short half-life (as do most of the fdt_ functions), but it helps solve some near-term needs until we work out the larger problems of device instantiation order versus the order of things in the fdt data. Notes: svn path=/head/; revision=261955
* Fix missing offset.Nathan Whitehorn2014-02-021-1/+2
| | | | Notes: svn path=/head/; revision=261398
* Open Firmware interrupt specifiers can consist of arbitrary-length byteNathan Whitehorn2014-02-011-3/+1
| | | | | | | | | | | | strings and include arbitrary information (IRQ line/domain/sense). When the ofw_bus_map_intr() API was introduced, it assumed that, as on most systems, these were either 1 cell, containing an interrupt line, or 2, containing a line number plus a sense code. It turns out a non-negligible number of ARM systems use 3 (or even 4!) cells for interrupts, so make this more general. Notes: svn path=/head/; revision=261351
* Be more robust with malformed interrupt config data. Instead of crashingIan Lepore2014-01-241-5/+17
| | | | | | | | | | or going into a near-infinite loop, warn and make potentially-reasonable assumptions. Reviewed by: brooks, nwhitehorn Notes: svn path=/head/; revision=261094
* Retire machine/fdt.h as a header used by MI code, as its function is nowNathan Whitehorn2014-01-051-1/+0
| | | | | | | | | | | | | | | | | | obsolete. This involves the following pieces: - Remove it entirely on PowerPC, where it is not used by MD code either - Remove all references to machine/fdt.h in non-architecture-specific code (aside from uart_cpu_fdt.c, shared by ARM and MIPS, and so is somewhat non-arch-specific). - Fix code relying on header pollution from machine/fdt.h includes - Legacy fdtbus.c (still used on x86 FDT systems) now passes resource requests to its parent (nexus). This allows x86 FDT devices to allocate both memory and IO requests and removes the last notionally MI use of fdtbus_bs_tag. - On those architectures that retain a machine/fdt.h, unused bits like FDT_MAP_IRQ and FDT_INTR_MAX have been removed. Notes: svn path=/head/; revision=260327
* Reimplement fdt_intr_to_rl() in terms of OFW_BUS_MAP_INTR() andNathan Whitehorn2014-01-041-93/+21
| | | | | | | | OFW_BUS_CONFIG_INTR(). This function is only used by simplebus, so will likely be moved there in the future. Notes: svn path=/head/; revision=260282
* Do not map IRQs twice. This fixes PowerPC/FDT systems with multiple PICs,Nathan Whitehorn2013-10-241-3/+2
| | | | | | | | which would try to treat the previously-mapped interrupts from fdt_decode_intr() as interrupt line numbers on the same parent PIC. Notes: svn path=/head/; revision=257060
* Remove OF_instance_to_package() hack for FDT and replace with use of theNathan Whitehorn2013-10-231-2/+2
| | | | | | | | generic OF_xref_phandle() API universally. Also replace some related explicit uses of fdt32_to_cpu() with OF_getencprop() calls. Notes: svn path=/head/; revision=256967