aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/ofw/openfirm.c
Commit message (Collapse)AuthorAgeFilesLines
* machine/stdarg.h -> sys/stdarg.hBrooks Davis2025-06-111-2/+1
| | | | | | | | | | | | | Switch to using sys/stdarg.h for va_list type and va_* builtins. Make an attempt to insert the include in a sensible place. Where style(9) was followed this is easy, where it was ignored, aim for the first block of sys/*.h headers and don't get too fussy or try to fix other style bugs. Reviewed by: imp Exp-run by: antoine (PR 286274) Pull Request: https://github.com/freebsd/freebsd-src/pull/1595
* openfirm: Add OF_device_unregister_xrefEmannuel Vadot2025-04-031-0/+19
| | | | | | | | | | | | | When a device fails to attach, or a module is unloaded, we want to be able to unregister the xref as the device goes away. While the device_t may still be valid, it won't be providing whatever functionality the consumer that follows the xref wants it for and thus, we should not keep it discoverable. [Commit message re-worded by kevans@] Reviewed by: ian, imp Differential Revision: https://reviews.freebsd.org/D22945
* ofw: convert boolean_t to boolMitchell Horne2024-06-261-5/+5
| | | | | | | | | | | Most of these already treat it as a proper bool, i.e. using true/false. Also fix-up callers of OF_install(). No functional change intended. Reviewed by: andrew, emaste Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D45733
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Adjust function definition in ofw to avoid clang 15 warningAndrew Turner2022-08-111-2/+2
| | | | | | | | | | | | | | | 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
* Align OF_getencprop_alloc API with OF_getencprop and OF_getprop_allocOleksandr Tymoshenko2018-04-091-6/+14
| | | | | | | | | | | | | | | | | | | | | Change OF_getencprop_alloc semantics to be combination of malloc and OF_getencprop and return size of the property, not number of elements allocated. For the use cases where number of elements is preferred introduce OF_getencprop_alloc_multi helper function that copies semantics of OF_getencprop_alloc prior to this change. This is to make OF_getencprop_alloc and OF_getencprop_alloc_multi function signatures consistent with OF_getencprop_alloc and OF_getencprop_alloc_multi. Functionality-wise this patch is mostly rename of OF_getencprop_alloc to OF_getencprop_alloc_multi except two calls in ofw_bus_setup_iinfo where 1 was used as a block size. Notes: svn path=/head/; revision=332341
* Make OF_searchencprop signature consistent with OF_getencpropOleksandr Tymoshenko2018-04-091-1/+1
| | | | | | | | Use pcell_t* as a destination buffer argument instead of void pointer to be consistent with OF_getencprop signature. Notes: svn path=/head/; revision=332312
* Clean up OF_getprop_alloc APIOleksandr Tymoshenko2018-04-081-7/+34
| | | | | | | | | | | | | | | | | | | | OF_getprop_alloc takes element size argument and returns number of elements in the property. There are valid use cases for such behavior but mostly API consumers pass 1 as element size to get string properties. What API users would expect from OF_getprop_alloc is to be a combination of malloc + OF_getprop with the same semantic of return value. This patch modifies API signature to match these expectations. For the valid use cases with element size != 1 and to reduce modification scope new OF_getprop_alloc_multi function has been introduced that behaves the same way OF_getprop_alloc behaved prior to this patch. Reviewed by: ian, manu Differential Revision: https://reviews.freebsd.org/D14850 Notes: svn path=/head/; revision=332310
* Back out OF module installation in the event of failure. PS3 firmware givesNathan Whitehorn2017-11-281-0/+6
| | | | | | | | 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. Notes: svn path=/head/; revision=326310
* 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
* Add OF_prop_free function as a counterpart for OF_*prop_allocOleksandr Tymoshenko2016-05-111-0/+7
| | | | | | | | | | | | | | | | | | | - 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
* Do not destroy input buffer of the OF_getencprop() function on errorZbigniew Bodek2016-01-251-0/+3
| | | | | | | | | | | | | | | Currently when the OF_getprop() function returns with error, the caller (OF_getencprop()) still changes the buffer endiannes. This may destroy the default value passed in the input buffer if used on a Little Endian platform. Reviewed by: mmel Submitted by: Zbigniew Bodek <zbb@semihalf.com> Obtained from: Semihalf Sponsored by: Cavium Notes: svn path=/head/; revision=294729
* Fix the style of the reading of a nodes xref to make it readable.Andrew Turner2016-01-241-4/+3
| | | | Notes: svn path=/head/; revision=294668
* Fix bug in xrefinfo_find() for 64-bit platformsZbigniew Bodek2015-03-301-4/+4
| | | | | | | | | | | | | | | | | | uintptr_t may be 64-bit on some platforms, therefore when finding xrefinfo by pointer to device the high word is being cut off due to cast to phandle_t which is 32-bit long by definition. Due to that we loose the high word of the address to compare with xi->dev's address. To fix that, first argument of xrefinfo_find() is extended to uintptr_t and is being cast to appropriate type (phandle_t) when compared. Submitted by: Zbigniew Bodek <zbb@semihalf.com> Reviewed by: nwhitehorn Obtained from: Semihalf Notes: svn path=/head/; revision=280848
* Do not leak the OFW memory when the result does not satisfy our alignmentLuiz Otavio O Souza2015-01-301-2/+7
| | | | | | | | | requirement. While here, fix style(9) issues. Notes: svn path=/head/; revision=277928
* When registering an association between a device and an xref phandle, createIan Lepore2014-09-061-10/+45
| | | | | | | | | | | | | | | | | | | | | | an entry in the xref list if one doesn't already exist for the given handle. On a system that uses phandle properties, the init-time scan of the tree which builds the xref list will pre-create entries for every xref handle that exists in the data. On systems where the xref and node handles are synonymous there is no phandle property in referenced nodes, and the xref list will initialize to an empty state. In the latter case, we still need to be able to associate a device_t with an xref handle, so we create list entries on the fly as needed. Since the node and xref handles are synonymous, we have all the info needed to create a list entry at device registration time. The downside to this change is that it basically allows on the fly creation of xref handles as synonyms of node handles, and the association of a device_t with them. Whether this is a bug or a feature is in the eye of the beholder, I guess. Notes: svn path=/head/; revision=271202
* Revert rr271190, it was based on a misunderstanding. The problem ofIan Lepore2014-09-061-18/+4
| | | | | | | | non-existant device<->xref info needs to be handled by creating the info, which will come in a subsequent commit. Notes: svn path=/head/; revision=271199
* Add OF_xref_from_node_strict() which returns -1 if there is no xref handleIan Lepore2014-09-061-4/+18
| | | | | | | | | for the node. The default routine returns the untranslated handle, which is sometimes useful, but sometimes you really need to know there's no entry in the xref<->node<->device translation table. Notes: svn path=/head/; revision=271190
* Fix typo.Ian Lepore2014-09-021-1/+1
| | | | | | | Pointy hat: ian Notes: svn path=/head/; revision=270960
* Add OF_xref_from_device() so that there's no need to have an intermediateIan Lepore2014-09-021-0/+16
| | | | | | | call to ofw_bus_get_node() to lookup info that's already in the xreflist. Notes: svn path=/head/; revision=270958
* Create a mechanism for looking up a device_t associated with an ofw/fdtIan Lepore2014-09-011-4/+114
| | | | | | | | | | | | | | xref handle, and for registering that association. Also use the same data for faster translations between node and xref handles. Now when fdt properties contain &othernode references, a driver can find the device instance that corresponds to &othernode, and thus can use interfaces provided by that instance. Reviewed by: nwhitehorn Notes: svn path=/head/; revision=270953
* Rename OF_xref_phandle() to OF_node_from_xref() and add a new functionIan Lepore2014-09-011-1/+15
| | | | | | | | | that provides the inverse translation, OF_xref_from_node(). Discussed with: nwhitehorn Notes: svn path=/head/; revision=270945
* Make all Open Firmware internal interfaces endian-safe by using the newNathan Whitehorn2013-10-231-8/+7
| | | | | | | | OF_getencprop() API. This removes one explicit endianness conversion in ofw_iicbus.c. Notes: svn path=/head/; revision=256966
* Fix build.Andreas Tobler2013-10-231-2/+2
| | | | Notes: svn path=/head/; revision=256953
* A few other common cases for encode-int decoding: OF_getencprop_alloc()Nathan Whitehorn2013-10-221-0/+31
| | | | | | | | | | | | and OF_searchencprop(). I thought about using the element size parameter to OF_getprop_alloc() to do endian-switching automatically, but it breaks use with structs and a *lot* of FDT code (which can hopefully be moved to these new APIs). MFC after: 2 weeks Notes: svn path=/head/; revision=256938
* Add a new function (OF_getencprop()) that undoes the transformation appliedNathan Whitehorn2013-10-221-0/+16
| | | | | | | | | by encode-int. Specifically, it takes a set of 32-bit cell values and changes them to host byte order. Most non-string instances of OF_getprop() should be using this function, which is a no-op on big-endian platforms. Notes: svn path=/head/; revision=256932
* Add a kernel interface (OF_xref_phandle()) for systems where phandlesNathan Whitehorn2013-09-151-0/+42
| | | | | | | | | | | | | | | | used as cross-references in the device tree and phandles as used by the Open Firmware client interface are in different namespaces. This include IBM pSeries hardware as well as FDT systems. FDT certainly abuses ihandles for this purpose and should be modified to use this API eventually. This changes no behavior on systems where FreeBSD already worked. Reviewed by: marius Approved by: re (kib) MFC after: 2 weeks Notes: svn path=/head/; revision=255596
* - Add OF_hasprop() and ofw_bus_has_prop(). These can be used to checkHiroki Sato2012-08-181-0/+8
| | | | | | | | | | | | existence of the property. - Fix ofw_bus_is_compatible{,_strict}() to prevent substring match in the compatible string. Reviewed by: raj Notes: svn path=/head/; revision=239366
* Implement OF_printf() using kvprintf() directly, avoiding to use aMarius Strobl2012-01-271-4/+18
| | | | | | | buffer and allowing to handle newlines properly Notes: svn path=/head/; revision=230631
* Fix OF_finddevice error return value in case of FDT.Jayachandran C.2011-12-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | According to the open firmware standard, finddevice call has to return a phandle with value of -1 in case of error. This commit is to: - Fix the FDT implementation of this interface (ofw_fdt_finddevice) to return (phandle_t)-1 in case of error, instead of 0 as it does now. - Fix up the callers of OF_finddevice() to compare the return value with -1 instead of 0 to check for errors. - Since phandle_t is unsigned, the return value of OF_finddevice should be checked with '== -1' rather than '<= 0' or '> 0', fix up these cases as well. Reported by: nwhitehorn Reviewed by: raj Approved by: raj, nwhitehorn Notes: svn path=/head/; revision=228201
* As it turns out, r186347 actually is insufficient to avoid the use of theMarius Strobl2011-11-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | curthread-accessing part of mtx_{,un}lock(9) when using a r210623-style curthread implementation on sparc64, crashing the kernel in its early cycles as PCPU isn't set up, yet (and can't be set up as OFW is one of the things we need for that, which leads to a chicken-and-egg problem). What happens is that due to the fact that the idea of r210623 actually is to allow the compiler to cache invocations of curthread, it factors out obtaining curthread needed for both mtx_lock(9) and mtx_unlock(9) to before the branch based on kobj_mutex_inited when compiling the kernel without the debugging options. So change kobj_class_compile_static(9) to just never acquire kobj_mtx, effectively restricting it to its documented use, and add a kobj_init_static(9) for initializing objects using a class compiled with the former and that also avoids using mutex(9) (and malloc(9)). Also assert in both of these functions that they are used in their intended way only. While at it, inline kobj_register_method() and kobj_unregister_method() as there wasn't much point for factoring them out in the first place and so that a reader of the code has to figure out the locking for fewer functions missing a KOBJ_ASSERT. Tested on powerpc{,64} by andreast. Reviewed by: nwhitehorn (earlier version), jhb MFC after: 3 days Notes: svn path=/head/; revision=227537
* Make all OF client interface calls return the maximum kind ofNathan Whitehorn2010-11-091-6/+74
| | | | | | | | | does-not-exist error when no client interface module is installed instead of dereferencing NULL pointers. This eases implementation of platforms that may or may not have Open Firmware. Notes: svn path=/head/; revision=215049
* Change OF_interpret() to also take an array of cell_t (missed in r209801).Marius Strobl2010-09-111-1/+1
| | | | | | | Reviewed by: nwhitehorn Notes: svn path=/head/; revision=212477
* Change the argument type to OF_call_method to take an array of cell_tNathan Whitehorn2010-07-081-3/+3
| | | | | | | | instead of unsigned longs to prepare for platforms where they are not the same. Notes: svn path=/head/; revision=209801
* Prepare and extend OFW layer for FDT support.Rafal Jaworowski2010-05-281-7/+15
| | | | | | | | | | | | | | | | o Let OFW_INIT() and OF_init() return status value. o Provide helper routines for 'compatible' property handling. o Only compile OF and OFW code, which is relevant in FDT scenario. o Other minor cosmetics Reviewed by: imp Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=208614
* Pull OF_quiesce() out of the MI Open Firmware layer and entirely intoNathan Whitehorn2010-05-161-9/+0
| | | | | | | | | PPC ofw_machdep.c, in recognition of its state as a machine specific hack. Requested by: marius Notes: svn path=/head/; revision=208172
* On PowerMac11,2 and (presumably) PowerMac12,1, we need to quiesce theNathan Whitehorn2010-05-161-0/+9
| | | | | | | | | | | | | firmware in order to take over control of the SMU. Without doing this, the firmware background process doing fan control will run amok as we take over the system and crash the management chip. This is limited to these two machines because our kernel is heavily dependent on firmware accesses, and so quiescing firmware can cause nasty problems. Notes: svn path=/head/; revision=208152
* Fix style.Marius Strobl2009-06-141-13/+31
| | | | Notes: svn path=/head/; revision=194138
* Unbreak OF_interpret() and its standard implementation after r186347.Marius Strobl2009-03-291-1/+3
| | | | Notes: svn path=/head/; revision=190522
* Fix the OFW interrupt map parser to use its own idea of the number of interruptNathan Whitehorn2009-01-031-0/+17
| | | | | | | | | | | | cells in the map, instead of using a value passed to it and then panicing if it disagrees. This fixes interrupt map parsing for PCI bridges on some Apple Uninorth PCI controllers. Reported by: marcel Tested on: G4 iBook, Sun Ultra 5 Notes: svn path=/head/; revision=186728
* Modularize the Open Firmware client interface to allow run-time switchingNathan Whitehorn2008-12-201-536/+119
| | | | | | | | | | | | | | | of OFW access semantics, in order to allow future support for real-mode OF access and flattened device frees. OF client interface modules are implemented using KOBJ, in a similar way to the PPC PMAP modules. Because we need Open Firmware to be available before mutexes can be used on sparc64, changes are also included to allow KOBJ to be used very early in the boot process by only using the mutex once we know it has been initialized. Reviewed by: marius, grehan Notes: svn path=/head/; revision=186347
* Fix warnings.Peter Wemm2007-07-061-1/+1
| | | | | | | | | | | | nxge: cast page size fragments down to (int). If the vm's demand paging PAGE_SIZE is ever too big for that, we've got far bigger problems. ofw: move va_start() a little earlier. gcc-4.2 doesn't like us modifying the last arg before the va_start(). Approved by: re (rwatson) Notes: svn path=/head/; revision=171265
* In OF_init() check the return value of OF_getprop().Marius Strobl2007-06-161-1/+2
| | | | | | | | Found with: Coverity Prevent(tm) CID: 679 Notes: svn path=/head/; revision=170842
* - Restore the machine independency of sys/dev/ofw/openfirm.{c,h} byMarius Strobl2007-06-161-31/+0
| | | | | | | | | | moving OF_set_mmfsa_traptable() (SUNW,set-trap-table with the two arguments used here is specific to sun4v) to MD code. - In sys/dev/ofw/openfirm.h remove prototypes for unimplemented functions and unused Solaris compatibility macros. Notes: svn path=/head/; revision=170841
* Sync the styles of sys/boot/ofw/libofw/openfirm.c andMarius Strobl2007-06-161-272/+263
| | | | | | | | sys/dev/ofw/openfirm.c with themselves, with each-other and with style(9). Notes: svn path=/head/; revision=170838
* Using the ptr defines broke the powerpc build - convert set_mmfsa to the sameKip Macy2006-10-111-2/+2
| | | | | | | convention as the rest of openfirm.c Notes: svn path=/head/; revision=163221
* kernel clean up to make the sun4v kernel buildKip Macy2006-10-091-0/+33
| | | | | | | | Reviewed by: jmg Approved by: rwatson (mentor) Notes: svn path=/head/; revision=163146
* Remove unused function and variables.Marius Strobl2005-11-221-19/+0
| | | | Notes: svn path=/head/; revision=152682
* Start each of the license/copyright comments with /*-, minor shuffle of linesWarner Losh2005-01-061-2/+2
| | | | Notes: svn path=/head/; revision=139749
* Instead of "OpenFirmware", "openfirmware", etc. use the official spellingMarius Strobl2004-08-161-3/+3
| | | | | | | | | "Open Firmware" from IEEE 1275 and OpenFirmware.org (no pun intended). Ok'ed by: tmm Notes: svn path=/head/; revision=133862