aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/subr_hints.c
Commit message (Collapse)AuthorAgeFilesLines
* Move kernel env global variables, etc to sys/kenv.hWarner Losh2020-10-071-0/+1
| | | | | | | | | | The kernel globals for kenv are confined to 2 files that need them and a few that likely shouldn't (but as written the code does). Move them from sys/systm.h to sys/kenv.h. This removed a XXX from systm.h and cleans it up a little bit... Notes: svn path=/head/; revision=366508
* Remove duplicated empty lines from kern/*.cMateusz Guzik2020-01-301-2/+0
| | | | | | | No functional changes. Notes: svn path=/head/; revision=357312
* res_find: Fix fallback logicKyle Evans2018-08-181-23/+30
| | | | | | | | | | | | | | | | | | | | | | | | | The fallback logic was broken if hints were found in multiple environments. If we found a hint in either the loader environment or the static environment, fallback would be incremented excessively when we returned to the environment-selection bits. These checks should have also been guarded by the fbacklvl checks. As a result, fbacklvl could quickly get to a point where we skip either the static environment and/or the static hints depending on which environments contained valid hints. The impact of this bug is minimal, mostly affecting mips boards that use static hints and may have hints in either the loader environment or the static environment. There may be better ways to express the searchable environments and describing their characteristics (immutable, already searched, etc.) but this may be revisited after 12 branches. Reported by: Dan Nelson <dnelson_1901@yahoo.com> Triaged by: Dan Nelson <dnelson_1901@yahoo.com> MFC after: 3 days Notes: svn path=/head/; revision=338020
* subr_hints: Skip static_env and static_hints if they don't contain hintsKyle Evans2018-07-101-4/+10
| | | | | | | | | | This is possible because, well, they're static. Both the dynamic environment and the MD-environment (generally loader(8) environment) can potentially have room for new variables to be set, and thus do not receive this treatment. Notes: svn path=/head/; revision=336154
* subr_hints: Convert some bool-like ints to boolsKyle Evans2018-07-101-5/+6
| | | | Notes: svn path=/head/; revision=336153
* subr_hints: Use goto/label instead of series of conditionalsKyle Evans2018-07-101-26/+22
| | | | Notes: svn path=/head/; revision=336152
* kern_environment: Fix SYSINIT orderingKyle Evans2018-07-061-1/+1
| | | | | | | | | | | | | | | | | | The dynamic environment was being initialized at SI_SUB_KMEM, SI_ORDER_ANY. I added the hint-merging at SI_SUB_KMEM, SI_ORDER_ANY as well in r335998 - this can only work by coincidence. Re-do both to operate at SI_SUB_KMEM + 1, SI_ORDER_FIRST and SI_ORDER_SECOND respectively to be safe. It's sufficiently obfuscated away as to when in SU_SUB_KMEM malloc will be available, and the dynamic environment cannot be relied upon there anyways since it's initialized at SI_ORDER_ANY. Reported by: bde Discussed with: bde X-MFC-With: r335998 Notes: svn path=/head/; revision=336036
* kern_environment: use any provided environments, evict hintmode/envmodeKyle Evans2018-07-051-126/+155
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | At the moment, hintmode and envmode are used to indicate whether static hints or static env have been provided in the kernel config(5) and the static versions are mutually exclusive with loader(8)-provided environment. hintmode *can* be reconfigured later to pull from the dynamic environment, thus taking advantage of the loader(8) or post-kmem environment setting. This changeset fixes both problems at once to move us from a semi-confusing state to a consistent state: if an environment file, hints file, or loader(8) environment are provided, we use them in a well-known order of precedence: - loader(8) environment - static environment - static hints file Once the dynamic environment is setup this becomes a moot point. The loader(8) and static environments are merged (respecting the above order of precedence), and the static hints are merged in on an as-needed basis after the dynamic environment has been setup. Hints lookup are changed to respect all of the above. Before the dynamic environment is setup, lookups use the above-mentioned order and fallback to the next environment if a matching hint is not found. Once the dynamic environment is setup, that is used on its own since it captures all of the above information plus any dynamic kenv settings that came up later in boot. The following tangentially related changes were made to res_find: - A hintp cookie is now passed in so that related searches continue using the chain of environments (or dynamic environment) without relying on global state - All three environments will be searched if they actually have valid hints to use, rather than just choosing the first environment that actually had a hint and rolling with that only The hintmode sysctl has been ripped out. static_{env,hints}.disabled are still honored and will disable their respective environments from being used for hint lookups and from being merged into the dynamic environment, as expected. MFC after: 1 month (maybe) Differential Revision: https://reviews.freebsd.org/D15953 Notes: svn path=/head/; revision=335998
* Revert r335995 due to accidental changes snuck inKyle Evans2018-07-051-155/+126
| | | | Notes: svn path=/head/; revision=335997
* kern_environment: use any provided environments, evict hintmode/envmodeKyle Evans2018-07-051-126/+155
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | At the moment, hintmode and envmode are used to indicate whether static hints or static env have been provided in the kernel config(5) and the static versions are mutually exclusive with loader(8)-provided environment. hintmode *can* be reconfigured later to pull from the dynamic environment, thus taking advantage of the loader(8) or post-kmem environment setting. This changeset fixes both problems at once to move us from a semi-confusing state to a consistent state: if an environment file, hints file, or loader(8) environment are provided, we use them in a well-known order of precedence: - loader(8) environment - static environment - static hints file Once the dynamic environment is setup this becomes a moot point. The loader(8) and static environments are merged (respecting the above order of precedence), and the static hints are merged in on an as-needed basis after the dynamic environment has been setup. Hints lookup are changed to respect all of the above. Before the dynamic environment is setup, lookups use the above-mentioned order and fallback to the next environment if a matching hint is not found. Once the dynamic environment is setup, that is used on its own since it captures all of the above information plus any dynamic kenv settings that came up later in boot. The following tangentially related changes were made to res_find: - A hintp cookie is now passed in so that related searches continue using the chain of environments (or dynamic environment) without relying on global state - All three environments will be searched if they actually have valid hints to use, rather than just choosing the first environment that actually had a hint and rolling with that only The hintmode sysctl has been ripped out. static_{env,hints}.disabled are still honored and will disable their respective environments from being used for hint lookups and from being merged into the dynamic environment, as expected. MFC after: 1 month (maybe) Differential Revision: https://reviews.freebsd.org/D15953 Notes: svn path=/head/; revision=335995
* subr_hints: Fix acpi unit hinting (at the very least)Kyle Evans2018-06-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | The refactoring in r335479 overlooked the fact that the dynamic kenv can also be switched to if hintmode == 0. This is problematic because the checkmethod bits are only ever ran once, but it worked previously because the use_kenv was a global state and the first lookup would enable it if occurring after the dynamic environment has been setup. Extending our local definition of use_kenv to include all non-STATIC hintmodes as long as the dynamic_kenv is setup fixes this. We still have potential issues if the dynamic kenv comes up while we're doing an anchored search through the environment, but this is not much of a concern right now because: 1.) The dynamic environment comes up super early in boot, just after kmem 2.) This is going to get rewritten to provide a safer mechanism for the anchored searches, ensuring that we continue using the same environment chain (dynamic env or static fallback) for all anchored search invocations Reported by: mmamcy X-MFC-With: r335479 Notes: svn path=/head/; revision=335509
* subr_hints: simplify a little bitKyle Evans2018-06-211-38/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | Some complexity exists in these bits that isn't needed. The sysctl handler, upon change to '2', runs through the current set of hints and sets them in the kenv. However, this isn't at all necessary if we're pulling hints from the kenv, static or dynamic, as the former will get added to the latter in init_dynamic_kenv (see: kern_environment.c). We can reduce this configuration to just adding static_hints to the kenv if we were previously using them. The changes in res_find are minimal and based on the observation that once use_kenv gets set to '1' it will never be reset to '0', and it gets set to '1' as soon as we hit fallback mode. Later work will refactor res_find a little bit and eliminate this now-local, because it's become clear that there's some funkiness revolving around use_kenv=1 and it being used to imply that we're certainly looking at the dynamic_kenv. Reviewed by: ray MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D15940 Notes: svn path=/head/; revision=335479
* sys/kern: 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=326271
* Add a new device control utility for new-bus devices called devctl. ThisJohn Baldwin2015-02-061-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | allows the user to request administrative changes to individual devices such as attach or detaching drivers or disabling and re-enabling devices. - Add a new /dev/devctl2 character device which uses ioctls for device requests. The ioctls use a common 'struct devreq' which is somewhat similar to 'struct ifreq'. - The ioctls identify the device to operate on via a string. This string can either by the device's name, or it can be a bus-specific address. (For unattached devices, a bus address is the only way to locate a device.) Bus drivers register an eventhandler to claim unrecognized device names that the driver recognizes as a valid address. Two buses currently support addresses: ACPI recognizes any device in the ACPI namespace via its full path starting with "\" and the PCI bus driver recognizes an address specification of 'pci[<domain>:]<bus>:<slot>:<func>' (identical to the PCI selector strings supported by pciconf). - To make it easier to cut and paste, change the PnP location string in the PCI bus driver to output a full PCI selector string rather than 'slot=<slot> function=<func>'. - Add a devctl(3) interface in libdevctl which provides a wrapper around the ioctls and is the preferred interface for other userland code. - Add a devctl(8) program which is a simple wrapper around the requests supported by devctl(3). - Add a device_is_suspended() function to check DF_SUSPENDED. - Add a resource_unset_value() function that can be used to remove a hint from the kernel environment. This is used to clear a hint.<driver>.<unit>.disabled hint when re-enabling a boot-time disabled device. Reviewed by: imp (parts) Requested by: imp (changing PCI location string) Relnotes: yes Notes: svn path=/head/; revision=278320
* Follow up to r225617. In order to maximize the re-usability of kernel codeDavide Italiano2014-10-161-1/+1
| | | | | | | | | | | in userland rename in-kernel getenv()/setenv() to kern_setenv()/kern_getenv(). This fixes a namespace collision with libc symbols. Submitted by: kmacy Tested by: make universe Notes: svn path=/head/; revision=273174
* Preserve one character space for a trailing '\0'.Sergey Kandaurov2014-02-141-1/+1
| | | | | | | | | Found by: Ivan Klymenko via cppcheck Discussed with: ae MFC after: 1 week Notes: svn path=/head/; revision=261901
* Style fixes.Aleksandr Rybalko2012-09-041-6/+9
| | | | | | | | Suggested by: mdf Approved by: adrian (menthor) Notes: svn path=/head/; revision=240119
* Add missing braces.Aleksandr Rybalko2012-09-031-1/+2
| | | | | | | | | Approved by: bschmidt (while mentor offline) Pointed by: gcooper Pointy hat to: ray Notes: svn path=/head/; revision=240070
* Add kern.hintmode sysctl variable to show current state of hints:Aleksandr Rybalko2012-09-031-0/+77
| | | | | | | | | | | | | 0 - loader hints in environment only; 1 - static hints only 2 - fallback mode (Dynamic KENV with fallback to kernel environment) Add kern.hintmode write handler, accept only value 2. That will switch static KENV to dynamic. So it will be possible to change device hints. Approved by: adrian (mentor) Notes: svn path=/head/; revision=240067
* Use strchr() and strrchr().Ed Schouten2012-01-021-6/+5
| | | | | | | | | | | It seems strchr() and strrchr() are used more often than index() and rindex(). Therefore, simply migrate all kernel code to use it. For the XFS code, remove an empty line to make the code identical to the code in the Linux kernel. Notes: svn path=/head/; revision=229272
* Use a sleep mutex instead of an sx lock for the kernel environment. ThisScott Long2006-07-091-6/+6
| | | | | | | | | allows greater flexibility for drivers that want to query the environment. Reviewed by: jhb, mux Notes: svn path=/head/; revision=160217
* The resource_xxx routines in subr_hints.c are called before and after theAlexander Leidinger2005-07-311-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | kenv environment in kern_environment.c switches to dynamic kenv. The prior call sets the static variable hintp to the static hints in subr_hints.c (hintmode==0). However, changes to the environment are not detected by the resource_xxx lookups after the change to dynamic kernel environment, so the lookup routines only report the old stuff of hintmode==0, even after the change to the dynamic kenv. This causes kenv users to see a different environment than the kernel routines. This is a problem in the mixer.c code that looks up initial mixer volume settings from the hints: If the hints are dynamic and not from the device.hints file, mixer.c doesn't see them, but kenv does. The patch from the PR (modified to comply to the style of the function) solves this. PR: 83686 Submitted by: Harry Coin <harrycoin@qconline.com> Notes: svn path=/head/; revision=148586
* Don't set ret_namelen and ret_resnamelen in res_find() unless both theJohn Baldwin2005-03-241-2/+2
| | | | | | | | | | corresponding pointer to the buffer (ret_name and ret_resname) is non-NULL to avoid possible NULL pointer derefs. Reported by: Coverity via sam Notes: svn path=/head/; revision=144077
* fix spelling of match in comment...John-Mark Gurney2005-03-101-1/+1
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=143386
* Add a resource_disabled() helper function that returns true (non-zero) ifJohn Baldwin2003-07-021-0/+14
| | | | | | | | a specified resource has been disabled via a non-zero 'disabled' hint and false otherwise. Notes: svn path=/head/; revision=117166
* Use __FBSDID().David E. O'Brien2003-06-111-2/+3
| | | | Notes: svn path=/head/; revision=116182
* Cosmetic tweaks. Try and keep the style more consistent, catch some strayPeter Wemm2002-05-011-3/+2
| | | | | | | whitespace and update a comment. Notes: svn path=/head/; revision=95839
* Finish fixing hints. Remember the use_kenv state for the next run.Peter Wemm2002-04-271-8/+10
| | | | | | | | | | | | Otherwise we fall back to using the static hints the next time around. We still have the leftover fallback code there which meant that we skipped the use_hints checking on the second and subsequent calls. Also, be a bit more careful about walking off the end of the envp array. I've extracted this from a larger diff. I hope I didn't miss anything... Notes: svn path=/head/; revision=95593
* Partial fix for hintsPeter Wemm2002-04-271-2/+4
| | | | | | | Obtained from: mux Notes: svn path=/head/; revision=95592
* Rework the kernel environment subsystem. We now convert the staticMaxime Henrion2002-04-171-18/+54
| | | | | | | | | | | | | | | | | | | | environment needed at boot time to a dynamic subsystem when VM is up. The dynamic kernel environment is protected by an sx lock. This adds some new functions to manipulate the kernel environment : freeenv(), setenv(), unsetenv() and testenv(). freeenv() has to be called after every getenv() when you have finished using the string. testenv() only tests if an environment variable is present, and doesn't require a freeenv() call. setenv() and unsetenv() are self explanatory. The kenv(2) syscall exports these new functionalities to userland, mainly for kenv(1). Reviewed by: peter Notes: svn path=/head/; revision=94936
* Fix a fatal type mismatch (char *static_env; vs char static_env[]).Peter Wemm2001-09-171-2/+0
| | | | | | | Submitted by: bde Notes: svn path=/head/; revision=83595
* Go back to having either static OR dynamic hints, with fallbackPeter Wemm2001-07-141-15/+40
| | | | | | | | | | | support. Trying to fix the merged set where dynamic overrode static was getting more and more complicated by the day. This should fix the duplicate atkbd, psm, fd* etc in GENERIC. (which paniced the alpha, but not the i386) Notes: svn path=/head/; revision=79696
* Hints overhaul:Peter Wemm2001-06-121-0/+304
- Replace some very poorly thought out API hacks that should have been fixed a long while ago. - Provide some much more flexible search functions (resource_find_*()) - Use strings for storage instead of an outgrowth of the rather inconvenient temporary ioconf table from config(). We already had a fallback to using strings before malloc/vm was running anyway. Notes: svn path=/head/; revision=78135