Commit Graph

39 Commits

Author SHA1 Message Date
christos 9e1f6b1ae6 include ioconf.h instead of locally declaring the prototype of the attach
function
2015-08-20 09:45:45 +00:00
uebayasi bf97b90378 Mark pseudo attach unused arg with __unused. 2015-08-20 08:27:09 +00:00
uebayasi fa089ff763 Convert pseudo attach functions to take no arguments, as some functions
(pppattach(), putterattach(), etc.) already do.  This means that pseudo
attach function will be able to become a constructor.
2015-08-18 13:46:20 +00:00
dholland f9228f4225 Add d_discard to all struct cdevsw instances I could find.
All have been set to "nodiscard"; some should get a real implementation.
2014-07-25 08:10:31 +00:00
dholland a68f9396b6 Change (mostly mechanically) every cdevsw/bdevsw I can find to use
designated initializers.

I have not built every extant kernel so I have probably broken at
least one build; however I've also found and fixed some wrong
cdevsw/bdevsw entries so even if so I think we come out ahead.
2014-03-16 05:20:22 +00:00
msaitoh 50699a2b3c Fix memory leak on the following cases when device attached or detached:
- No one open drvctl.
 - kmem_alloc() failed in devmon_insert().

XXX pullup to both netbsd-5 and netbsd-6.
2013-04-26 09:04:43 +00:00
chs cbab9cadce split device_t/softc for all remaining drivers.
replace "struct device *" with "device_t".
use device_xname(), device_unit(), etc.
2012-10-27 17:17:22 +00:00
plunky 7f3d4048d7 NULL does not need a cast 2011-08-31 18:31:02 +00:00
dsl 2a54322c7b If a multithreaded app closes an fd while another thread is blocked in
read/write/accept, then the expectation is that the blocked thread will
exit and the close complete.
Since only one fd is affected, but many fd can refer to the same file,
the close code can only request the fs code unblock with ERESTART.
Fixed for pipes and sockets, ERESTART will only be generated after such
a close - so there should be no change for other programs.
Also rename fo_abort() to fo_restart() (this used to be fo_drain()).
Fixes PR/26567
2009-12-20 09:36:05 +00:00
dsl 7a42c833db Rename fo_drain() to fo_abort(), 'drain' is used to mean 'wait for output
do drain' in many places, whereas fo_drain() was called in order to force
blocking read()/write() etc calls to return to userspace so that a close()
call from a different thread can complete.
In the sockets code comment out the broken code in the inner function,
it was being called from compat code.
2009-12-09 21:32:58 +00:00
dyoung 36fffd8d02 In pmf(9), improve the implementation of device self-suspension
and make suspension by self, by drvctl(8), and by ACPI system sleep
play nice together.  Start solidifying some temporary API changes.

1. Extract a new header file, <sys/device_if.h>, from <sys/device.h> and
   #include it from <sys/pmf.h> instead of <sys/device.h> to break the
   circular dependency between <sys/device.h> and <sys/pmf.h>.

2. Introduce pmf_qual_t, an aggregate of qualifications on a PMF
   suspend/resume call.  Start to replace instances of PMF_FN_PROTO,
   PMF_FN_ARGS, et cetera, with a pmf_qual_t.

3. Introduce the notion of a "suspensor," an entity that holds a
   device in suspension.  More than one suspensor may hold a device
   at once.  A device stays suspended as long as at least one
   suspensor holds it.  A device resumes when the last suspensor
   releases it.

   Currently, the kernel defines three suspensors,

   3a the system-suspensor: for system suspension, initiated
      by 'sysctl -w machdep.sleep_state=3', by lid closure, by
      power-button press, et cetera,

   3b the drvctl-suspensor: for device suspension by /dev/drvctl
      ioctl, e.g., drvctl -S sip0.

   3c the system self-suspensor: for device drivers that suspend
      themselves and their children.  Several drivers for network
      interfaces put the network device to sleep while it is not
      administratively up, that is, after the kernel calls if_stop(,
      1).  The self-suspensor should not be used directly.  See
      the description of suspensor delegates, below.

   A suspensor can have one or more "delegates".  A suspensor can
   release devices that its delegates hold suspended.  Right now,
   only the system self-suspensor has delegates.  For each device
   that a self-suspending driver attaches, it creates the device's
   self-suspensor, a delegate of the system self-suspensor.

   Suspensors stop a system-wide suspend/resume cycle from waking
   devices that the operator put to sleep with drvctl before the cycle.
   They also help self-suspension to work more simply, safely, and in
   accord with expectations.

4. Add the notion of device activation level, devact_level_t,
   and a routine for checking the current activation level,
   device_activation().  Current activation levels are DEVACT_LEVEL_BUS,
   DEVACT_LEVEL_DRIVER, and DEVACT_LEVEL_CLASS, which respectively
   indicate that the device's bus is active, that the bus and device are
   active, and that the bus, device, and the functions of the device's
   class (network, audio) are active.

   Suspend/resume calls can be qualified with a devact_level_t.
   The power-management framework treats a devact_level_t that
   qualifies a device suspension as the device's current activation
   level; it only runs hooks to reduce the activation level from
   the presumed current level to the fully suspended state.  The
   framework treats a devact_level_t qualifying device resumption
   as the target activation level; it only runs hooks to raise the
   activation level to the target.

5. Use pmf_qual_t, devact_level_t, and self-suspensors in several
   drivers.

6. Temporarily add an unused power-management workqueue that I will
   remove or replace, soon.
2009-09-16 16:34:49 +00:00
dyoung 662437b2c3 Remove extraneous parentheses. Fix spelling/grammar. No functional
change intended.
2009-04-30 20:39:08 +00:00
nonaka 3c6a17f5ff include sys/lwp.h for curlwp. 2009-04-30 05:15:36 +00:00
christos 86ba58fd64 Fix locking as Andy explained. Also fill in uid and gid like sys_pipe did. 2009-04-11 23:05:26 +00:00
christos b859fbe7cb Fix PR/37878 and PR/37550: Provide stat(2) for all devices and don't use
fbadop_stat.
2009-04-11 15:47:33 +00:00
joerg 3cb902383f Allow querying for root devices in the tree by specifying an empty
device name. Ensure that l_devname is NUL-terminated and fail otherwise.
OK cube@
2009-04-04 21:49:05 +00:00
ad c6367674d6 Add fileops::fo_drain(), to be called from fd_close() when there is more
than one active reference to a file descriptor. It should dislodge threads
sleeping while holding a reference to the descriptor. Implemented only for
sockets but should be extended to pipes, fifos, etc.

Fixes the case of a multithreaded process doing something like the
following, which would have hung until the process got a signal.

thr0	accept(fd, ...)
thr1	close(fd)
2009-04-04 10:12:51 +00:00
yamt cea19a4d14 malloc -> kmem_alloc. 2009-01-17 07:02:35 +00:00
yamt 68b6d8786e remove extra semicolons. 2009-01-03 03:31:23 +00:00
jmcneill 42c69bb1ce Add poll support for drvctl notification events 2008-11-23 23:59:41 +00:00
gmcgarry fb6bc48511 ioctl commands are unsigned long. 2008-06-24 10:24:21 +00:00
freza 1531f6d32e Any time we remove event from the queue make sure we 1. release the
event plist and 2. free the drvctl_event struct.

Discussed with jmcneill@.
2008-05-30 15:30:37 +00:00
jmcneill 3a8a32076d Add DRVGETEVENT support for /dev/drvctl, based on devmon support by
Jachym Holecek for Google Summer of Code. DRVGETEVENT plist is currently
limited to event type, device name, and device parent name.
2008-05-25 12:30:40 +00:00
dyoung 3df2b2feb5 Use device_t and its accessors throughout. Use aprint_*_dev().
Improve PMF-ability.

        Add a 'flags' argument to suspend/resume handlers and
        callers such as pmf_system_suspend().

        Define a flag, PMF_F_SELF, which indicates to PMF that a
        device is suspending/resuming itself.  Add helper routines,
        pmf_device_suspend_self(dev) and pmf_device_resume_self(dev),
        that call pmf_device_suspend(dev, PMF_F_SELF) and
        pmf_device_resume(dev, PMF_F_SELF), respectively.  Use
        PMF_F_SELF to suspend/resume self in ath(4), audio(4),
        rtw(4), and sip(4).

        In ath(4) and in rtw(4), replace the icky sc_enable/sc_disable
        callbacks, provided by the bus front-end, with
        self-suspension/resumption.  Also, clean up the bus
        front-ends.  Make sure that the interrupt handler is
        disestablished during suspension.  Get rid of driver-private
        flags (e.g., RTW_F_ENABLED, ath_softc->sc_invalid); use
        device_is_active()/device_has_power() calls, instead.

        In the network-class suspend handler, call if_stop(, 0)
        instead of if_stop(, 1), because the latter is superfluous
        (bus- and driver-suspension hooks will 'disable' the NIC),
        and it may cause recursion.

        In the network-class resume handler, prevent infinite
        recursion through if_init() by getting out early if we are
        self-suspending (PMF_F_SELF).

rtw(4) improvements:

        Destroy rtw(4) callouts when we detach it.  Make rtw at
        pci detachable.  Print some more information with the "rx
        frame too long" warning.

Remove activate() methods:

        Get rid of rtw_activate() and ath_activate().  The device
        activate() methods are not good for much these days.

Make ath at cardbus resume with crypto functions intact:

        Introduce a boolean device property, "pmf-powerdown".  If
        pmf-powerdown is present and false, it indicates that a
        bus back-end should not remove power from a device.

        Honor this property in cardbus_child_suspend().

        Set this property to 'false' in ath_attach(), since removing
        power from an ath at cardbus seems to lobotomize the WPA
        crypto engine.  XXX Should the pmf-powerdown property
        propagate toward the root of the device tree?

Miscellaneous ath(4) changes:

        Warn if ath(4) tries to write crypto keys to suspended
        hardware.

        Reduce differences between FreeBSD and NetBSD in ath(4)
        multicast filter setup.

        Make ath_printrxbuf() print an rx descriptor's status &
        key index, to help debug crypto errors.

        Shorten a staircase in ath_ioctl().  Don't check for
        ieee80211_ioctl() return code ERESTART, it never happens.
2008-03-12 18:02:21 +00:00
dyoung 4902571538 Synchronize readers and writers of the device tree.
Add a device iterator object, deviter_t, and methods deviter_init(),
deviter_first(), and deviter_next() for visiting each device in
the device tree.

Take care not to re-shutdown a device in the event that the machine
panics during reboot and the operator types 'reboot' at the kernel
debugger prompt.

While I'm here, sprinkle PMF_FN_ARGS, PMF_FN_PROTO, et cetera.
2008-03-05 07:09:18 +00:00
joerg e69482d49d Introduce device_find_by_xname and device_find_by_driver_unit to replace
alldevs iterations all over src.

Patch discussed with and improved on suggestioned from cube@.
2008-02-12 17:30:57 +00:00
drochner 214b89d525 The tricks done in device_foreach_child() still don't make it safe to use
by config_detach_children(), because the latter can work recursively
and remove any number of devices, so rewrite config_detach_children()
to restart list traversal after each call of config_detach(), and since
only one user of device_foreach_child() is left (in kern_drvctl.c),
and it is simpler to open-code the loop than to deal with callbacks,
just remove it.
2008-02-06 20:24:17 +00:00
dyoung ae1c071d6f Patch /dev/drvctl and drvctl(8) to let us suspend/resume device
sub-trees, and to let us list the children of a device.

While I am here, add -p to the drvctl(8) usage message.
2008-01-27 01:38:33 +00:00
rmind 497adf4cc1 drvctlioctl: Plug a possible memory leak.
CID: 4363
2007-04-03 23:02:39 +00:00
christos 53524e44ef Kill caddr_t; there will be some MI fallout, but it will be fixed shortly. 2007-03-04 05:59:00 +00:00
yamt 1a7bc55dcc remove some __unused from function parameters. 2006-11-01 10:17:58 +00:00
thorpej 1342c5a275 Use prop_dictionary_set_int32() to set the error number. 2006-10-26 05:08:01 +00:00
thorpej 435147e718 Add __unused as necessary. 2006-10-12 04:29:37 +00:00
gdt faa429b9b4 add missing d_type member in cdevsw initializer 2006-10-06 17:54:05 +00:00
thorpej ef731d9e00 - Add a new DRVCTLCOMMAND ioctl to /dev/drvctl. This is a generic
"execute a command" ioctl that takes a dictionary as an argument
  (specifying the command and arguments) and returns a dictionary
  with the results (error code, optional error message, optional
  result data).

- Define and implement a "get-properties" command for DRVCTLCOMMAND
  that returns the properties dictionary of the specified device.

- Add a -p flag to drvctl(8) to fetch and display the properties of
  the specified device.

This is a great example of how to use prop_dictionary_sendrecv_ioctl().
2006-09-22 04:37:36 +00:00
cube c13d97c44b ktrace-lwp merge fallout. 2005-12-15 22:01:17 +00:00
christos 95e1ffb156 merge ktrace-lwp. 2005-12-11 12:16:03 +00:00
drochner 6036af9fc4 Replace the "locnames", attached to cfdata, which was solely good for
userconf, by more complete information (including default values) about
interface attributes, attached to the drivers which provide them.
2005-08-25 15:06:28 +00:00
drochner 4157766364 add a "drvctl" pseudo-device as userland interface to the autoconf
rescan() and detach() functions
2004-08-18 12:19:29 +00:00