Commit Graph

252 Commits

Author SHA1 Message Date
Konstantin Belousov
23b70c1ae2 Finish r210923, 210926. Mark some devices as eternal.
MFC after:	2 weeks
2011-01-04 10:59:38 +00:00
Warner Losh
704c91294b removed tag is '-', not '+'.
remove extra return.
2010-12-02 04:28:01 +00:00
Warner Losh
5cb51b647c Remove redundant (and bogus) insertion of pnp info when announcing new
and retiring devices.  That's already inserted elsewhere.

Submitted by:	n_hibma
MFC after:	3 days
2010-11-30 05:54:21 +00:00
John Baldwin
144df3a28f Add a resource_list_reserved() method that returns true if a resource
list entry contains a reserved resource.
2010-11-17 22:28:04 +00:00
Warner Losh
5ff4999243 By popular demand, kill all the non GIANT related interrupt messages.
They are confusing and add little value.

Reviewed by:	jhb@
2010-09-17 16:05:25 +00:00
Andriy Gapon
3d844eddb7 bus_add_child: change type of order parameter to u_int
This reflects actual type used to store and compare child device orders.
Change is mostly done via a Coccinelle (soon to be devel/coccinelle)
semantic patch.
Verified by LINT+modules kernel builds.

Followup to:	r212213
MFC after:	10 days
2010-09-10 11:19:03 +00:00
Andriy Gapon
3b0620e06c subr_bus: use hexadecimal representation for bit flags
It seems that this format is more custom in our code, and it is more
convenient too.

Suggested by:	jhb
No objection:	imp
MFC after:	1 week
2010-09-08 17:35:06 +00:00
Andriy Gapon
ef3b7ba04f struct device: widen type of flags and order fields to u_int
Also change int -> u_int for order parameter in device_add_child_ordered.
There should not be any ABI change as struct device is private to subr_bus.c
and the API change should be compatible.

To do: change int -> u_int for order parameter of bus_add_child method
and its implementations.  The change should also be API compatible, but
is a bit more churn.

Suggested by:	imp, jhb
MFC after:	1 week
2010-09-04 17:28:29 +00:00
Justin T. Gibbs
74ec46dff4 Properly indent a continue statement. No functional changes. 2010-08-12 19:26:27 +00:00
Ed Schouten
60ae52f785 Use ISO C99 integer types in sys/kern where possible.
There are only about 100 occurences of the BSD-specific u_int*_t
datatypes in sys/kern. The ISO C99 integer types are used here more
often.
2010-06-21 09:55:56 +00:00
Konstantin Belousov
bebc339116 Add modifications of devctl_notify(9) functions that take flags. Use
flags to specify M_WAITOK/M_NOWAIT. M_WAITOK allows devctl to sleep for
the memory allocation.

As Warner noted, allowing the functions to sleep might cause
reordering of the queued notifications.

Reviewed by:	imp, jh
MFC after:	3 weeks
2010-06-12 13:20:38 +00:00
Alexander Motin
e7d83347c0 Call BUS_PROBE_NOMATCH() when device detached due to driver unload.
This allows bus to power-down device when driver unloaded on-flight.
2010-06-07 18:47:53 +00:00
Warner Losh
e8b93e4257 Make sure that we free the passed in data message if we don't actually
insert it onto the queue.  Also, fix a mtx leak if someone turns off
devctl while we're processing a messages.

MFC after:	5 days
2010-04-20 20:39:42 +00:00
Gavin Atkinson
03be779506 Spelling nit 2010-02-07 18:00:13 +00:00
John Baldwin
6a41dc1043 Actually set RLE_ALLOCATED when allocating a reserved resource so that
resource_list_release() will later release the resource instead of failing.
2009-12-30 22:37:28 +00:00
John Baldwin
0eb9893a80 - Assert that a reserved resource returned via resource_list_alloc() is not
active.
- Fix bus_generic_rl_(alloc|release)_resource() to not attempt to fetch a
  resource list for grandchild devices, but just pass those requests up to
  the parent directly.  This worked by accident previously, but it is
  better to not let bus drivers try to operate on devices they do not
  manage.
2009-12-30 19:44:31 +00:00
John Baldwin
42a346fa63 For some buses, devices may have active resources assigned even though they
are not allocated by the device driver.  These resources should still appear
allocated from the system's perspective so that their assigned ranges are
not reused by other resource requests.  The PCI bus driver has used a hack
to effect this for a while now where it uses rman_set_device() to assign
devices to the PCI bus when they are first encountered and later assigns
them to the actual device when a driver allocates a BAR.  A few downsides of
this approach is that it results in somewhat confusing devinfo -r output as
well as not being very easily portable to other bus drivers.

This commit adds generic support for "reserved" resources to the resource
list API used by many bus drivers to manage the resources of child devices.
A resource may be reserved via resource_list_reserve().  This will allocate
the resource from the bus' parent without activating it.
resource_list_alloc() recognizes an attempt to allocate a reserved resource.
When this happens it activates the resource (if requested) and then returns
the reserved resource.  Similarly, when a reserved resource is released via
resource_list_release(), it is deactivated (if it is active) and the
resource is then marked reserved again, but is left allocated from the
bus' parent.  To completely remove a reserved resource, a bus driver may
use resource_list_unreserve().  A bus driver may use resource_list_busy()
to determine if a reserved resource is allocated by a child device or if
it can be unreserved.

The PCI bus driver has been changed to use this framework instead of
abusing rman_set_device() to keep track of reserved vs allocated resources.

Submitted by:	imp (an older version many moons ago)
MFC after:	1 month
2009-12-09 21:52:53 +00:00
Attilio Rao
023c800576 The building the dev nameunit string, in devclass_add_device() is based
on the assumption that the unit linked with the device is invariant but
that can change when calling devclass_alloc_unit() (because -1 is passed
or, more simply, because the unit choosen is beyond the table limits).
This results in a completely bogus string building.

Fix this by reserving the necessary room for all the possible characters
printable by a positive integer (we do not allow for negative unit
number).

Reported by:	Sandvine Incorporated
Reviewed by:	emaste
Sponsored by:	Sandvine Incorporated
MFC:		1 week
2009-11-12 00:52:14 +00:00
John Baldwin
5ca4819ddf - Fix several off-by-one errors when using MAXCOMLEN. The p_comm[] and
td_name[] arrays are actually MAXCOMLEN + 1 in size and a few places that
  created shadow copies of these arrays were just using MAXCOMLEN.
- Prefer using sizeof() of an array type to explicit constants for the
  array length in a few places.
- Ensure that all of p_comm[] and td_name[] is always zero'd during
  execve() to guard against any possible information leaks.  Previously
  trailing garbage in p_comm[] could be leaked to userland in ktrace
  record headers via td_name[].

Reviewed by:	bde
2009-10-23 15:14:54 +00:00
John Baldwin
3eec6f034a Set the devclass_t pointer specified in the DRIVER_MODULE() macro
sooner so it is always valid when a driver's identify routine is
called.  Previously, new-bus would attempt to create the devclass for
a newly loaded driver in two separate places, once in
devclass_add_driver(), and again after devclass_add_driver() returned
in driver_module_handler().  Only the second lookup attempted to set a
device class' parent and set the devclass_t pointer specified in the
DRIVER_MODULE() macro.  However, by the time it was executed, the
driver was already added to existing instances of the parent driver at
which point in time the new driver's identify routine would have been
invoked.  The fix is to merge the two attempts and only create the
devclass once in devclass_add_driver() including setting the
devclass_t pointer passed to DRIVER_MODULE() before the driver is
added to any existing bus devices.

Reported by:	avg
Reviewed by:	imp
MFC after:	2 weeks
2009-10-22 14:53:44 +00:00
John Baldwin
37b8ef16cd Add a facility for associating optional descriptions with active interrupt
handlers.  This is primarily intended as a way to allow devices that use
multiple interrupts (e.g. MSI) to meaningfully distinguish the various
interrupt handlers.
- Add a new BUS_DESCRIBE_INTR() method to the bus interface to associate
  a description with an active interrupt handler setup by BUS_SETUP_INTR.
  It has a default method (bus_generic_describe_intr()) which simply passes
  the request up to the parent device.
- Add a bus_describe_intr() wrapper around BUS_DESCRIBE_INTR() that supports
  printf(9) style formatting using var args.
- Reserve MAXCOMLEN bytes in the intr_handler structure to hold the name of
  an interrupt handler and copy the name passed to intr_event_add_handler()
  into that buffer instead of just saving the pointer to the name.
- Add a new intr_event_describe_handler() which appends a description string
  to an interrupt handler's name.
- Implement support for interrupt descriptions on amd64 and i386 by having
  the nexus(4) driver supply a custom bus_describe_intr method that invokes
  a new intr_describe() MD routine which in turn looks up the associated
  interrupt event and invokes intr_event_describe_handler().

Requested by:	many
Reviewed by:	scottl
MFC after:	2 weeks
2009-10-15 14:54:35 +00:00
Alexander Motin
6090db7d38 Do not call BUS_DRIVER_ADDED() for detached buses (attach failed) on
driver load. This fixes crash on atapicam module load on systems,
where some ata channels (usually ata1) was probed, but failed to attach.

Reviewed by:	jhb, imp
Tested by:	many
2009-09-24 17:03:32 +00:00
Attilio Rao
4c68dee0fb Revert r196779 in order to implement a different scheme for newbus locking
methodology.

Requested by:	imp
2009-09-13 15:08:19 +00:00
Attilio Rao
80002a63db Add intermediate states for attaching and detaching that will be
reused by the enhached newbus locking once it is checked in.
This change can be easilly MFCed to STABLE_8 at the appropriate moment.

Reviewed by:	jhb, scottl
Tested by:	Giovanni Trematerra <giovanni dot trematerra at gmail dot com>
2009-09-03 13:40:41 +00:00
Warner Losh
58a745889f Rather than havnig enabled/disabled, implement a max queue depth.
While usually not an issue, this firewalls bugs in the code that may
run us out of memory.

Fix a memory exhaustion in the case where devctl was disabled, but the
link was bouncing.  The check to queue was in the wrong place.

Implement a new sysctl hw.bus.devctl_queue to control the depth.  Make
compatibility hacks for hw.bus.devctl_disable to ease transition.

Reviewed by:	emaste@
Approved by:	re@ (kib)
MFC after:	asap
2009-08-25 06:25:59 +00:00
John Baldwin
a56fe095f0 Temporarily revert the new-bus locking for 8.0 release. It will be
reintroduced after HEAD is reopened for commits by re@.

Approved by:	re (kib), attilio
2009-08-20 19:17:53 +00:00
Ed Schouten
f6b3749db3 Fix small style regression introduced by the MPSAFE newbus code.
Approved by:	re (rwatson)
2009-08-16 19:55:53 +00:00
Attilio Rao
444b91868b Make the newbus subsystem Giant free by adding the new newbus sxlock.
The newbus lock is responsible for protecting newbus internIal structures,
device states and devclass flags. It is necessary to hold it when all
such datas are accessed. For the other operations, softc locking should
ensure enough protection to avoid races.

Newbus lock is automatically held when virtual operations on the device
and bus are invoked when loading the driver or when the suspend/resume
take place. For other 'spourious' operations trying to access/modify
the newbus topology, newbus lock needs to be automatically acquired and
dropped.

For the moment Giant is also acquired in some key point (modules subsystem)
in order to avoid problems before the 8.0 release as module handlers could
make assumptions about it. This Giant locking should go just after
the release happens.

Please keep in mind that the public interface can be expanded in order
to provide more support, if there are really necessities at some point
and also some bugs could arise as long as the patch needs a bit of
further testing.

Bump __FreeBSD_version in order to reflect the newbus lock introduction.

Reviewed by:    ed, hps, jhb, imp, mav, scottl
No answer by:   ariff, thompsa, yongari
Tested by:      pho,
                G. Trematerra <giovanni dot trematerra at gmail dot com>,
                Brandon Gooch <jamesbrandongooch at gmail dot com>
Sponsored by:   Yahoo! Incorporated
Approved by:	re (ksmith)
2009-08-02 14:28:40 +00:00
Warner Losh
72aee35323 We can actually remove devclass_find_driver. 2009-06-10 01:02:38 +00:00
Warner Losh
98266dcf99 As discussed on arch@, restire
devclass_{add,delete,find,quiesce}_driver.  They aren't needed or used
and complicate locking newbus.
2009-06-09 23:24:04 +00:00
John Baldwin
4ef60d2686 Add support for multiple passes of the device tree during the boot-time
probe.  The current device order is unchanged.  This commit just adds the
infrastructure and ABI changes so that it is easier to merge later changes
into 8.x.
- Driver attachments now have an associated pass level.  Attachments are
  not allowed to probe or attach to drivers until the system-wide pass level
  is >= the attachment's pass level.  By default driver attachments use the
  "last" pass level (BUS_PASS_DEFAULT).  Driver's that wish to probe during
  an earlier pass use EARLY_DRIVER_MODULE() instead of DRIVER_MODULE() which
  accepts the pass level as an additional parameter.
- A new method BUS_NEW_PASS has been added to the bus interface.  This
  method is invoked when the system-wide pass level is changed to kick off
  a rescan of the device tree so that drivers that have just been made
  "eligible" can probe and attach.
- The bus_generic_new_pass() function provides a default implementation of
  BUS_NEW_PASS().  It first allows drivers that were just made eligible for
  this pass to identify new child devices.  Then it propogates the rescan to
  child devices that already have an attached driver by invoking their
  BUS_NEW_PASS() method.  It also reprobes devices without a driver.
- BUS_PROBE_NOMATCH() is only invoked for devices that do not have
  an attached driver after being scanned during the final pass.
- The bus_set_pass() function is used during boot to raise the pass level.
  Currently it is only called once during root_bus_configure() to raise
  the pass level to BUS_PASS_DEFAULT.  This has the effect of probing all
  devices in a single pass identical to previous behavior.

Reviewed by:	imp
Approved by:	re (kib)
2009-06-09 14:26:23 +00:00
John Baldwin
4ab9c8af92 Fix a typo. 2009-05-20 17:19:30 +00:00
Warner Losh
248343f9d1 We no longer need to use d_thread_t for portability here, switch to
struct thread *.
2009-05-20 16:58:16 +00:00
John Baldwin
2401c73637 When looking up the parent devclass of a new devclass, create the parent
devclass if it doesn't already exist.
2009-03-25 17:02:05 +00:00
Alexander Kabaev
9999864a87 Add safety check that does not allow empty strings to be queued
to the devctl notification queue. Empty strings cause devctl read
call to return 0 and result in devd exiting prematurely.

The actual offender (ugen notes for root hubs) will be fixed
by separate commit.
2009-03-23 01:13:34 +00:00
Warner Losh
4782ea6768 Minor nits notice by jhb@ 2009-03-11 08:19:31 +00:00
Warner Losh
2a7e13e5ad Fix a long-standing bug in newbus. It was introduced when subclassing
was introduced.  If you have a bus, say cardbus, that is derived from
a base-bus (say PCI), then ordinarily all PCI drivers would attach to
cardbus devices.  However, there had been one exception: kldload
wouldn't work.

The problem is in devclass_add_driver.  In this routine, all we did
was call to the pci device's BUS_DRIVER_ADDED routine.  However, since
cardbus bus instances had a different devclass, none of them were
called.

The solution is to call all subclass devclasses, recursively down the
tree, of the class that was loaded.  Since we don't have a 'children
class' pointer, we search the whole list of devclasses for a class
whose parent matches.  Since just done a kldload time, this isn't as
bad as it sounds.  In addition, we short-circuit the whole process by
marking those classes with subclasses with a flag.  We'll likely have
to reevaluate this method the number of devclasses with subclasses
gets large.

This means we can remove the "cardbus" lines from all the PCI drivers
since we have no cardbus specific attach device attachments in the
tree.

# Also: minor tweak to an error message
2009-03-09 13:20:23 +00:00
Warner Losh
c9584ebe61 o Use NULL in pereference to 0 in pointer contexts.
o Use newly minted KOBJMETHOD_END as appropriate
o fix prototype for root_setup_intr.
2009-02-11 04:54:02 +00:00
Alexander Motin
e05e00bcae Check for device_set_devclass() errors and skip driver probe/attach if any.
Attach call without devclass set crashes the system.

On resume AHCI driver sometimes tries to create duplicate adX device.
It is surely his own problem, but IMHO it is not a reason to crash here.
Other reasons are also possible.
2009-02-10 23:22:29 +00:00
Warner Losh
bdf331d450 Declare bus_data_devices to be static: it isn't used elsewhere.
Use NULL in a couple of places rather than 0 in the context of
pointers to be consistent with the rest of the file.
2009-02-03 00:10:21 +00:00
John Baldwin
0d484d249f Allow device hints to wire the unit numbers of devices.
- An "at" hint now reserves a device name.
- A new BUS_HINT_DEVICE_UNIT method is added to the bus interface.  When
  determining the unit number of a device, this method is invoked to
  let the bus driver specify the unit of a device given a specific
  devclass.  This is the only way a device can be given a name reserved
  via an "at" hint.
- Implement BUS_HINT_DEVICE_UNIT() for the acpi(4) and isa(4) bus drivers.
  Both of these busses implement this by comparing the resources for a
  given hint device with the resources enumerated by ACPI/PnPBIOS and
  wire a unit if the hint resources are a subset of the "real" resources.
- Use bus_hinted_children() for adding hinted devices on isa(4) busses
  now instead of doing it by hand.
- Remove the unit kludging from sio(4) as it is no longer necessary.

Prodding from:	peter, imp
OK'd by:	marcel
MFC after:	1 month
2008-11-18 21:01:54 +00:00
Nick Hibma
eaa5bb21ca Silence detach messages if the device has marked itself quiet (u3g).
MFC after:	3 weeks
2008-11-13 21:46:19 +00:00
Warner Losh
53366abd02 Close, but not eliminate, a race condition. It is one that properly
designed drivers would never hit, but was exposed in diving into
another problem...

When expanding the devclass array, free the old memory after updating
the pointer to the new memory.  For the following single race case,
this helps:

	allocate new memory
	copy to new memory
	free old memory
<interrupt>				read pointer to freed memory
	update pointer to new memory

Now we do
	allocate new memory
	copy to new memory
	update pointer to new memory
	free old memory

Which closes this problem, but doesn't even begin to address the
multicpu races, which all should be covered by Giant at the moment,
but likely aren't completely.

Note: reviewers were ok with this fix, but suggested the use case
wasn't one we wanted to encourage.

Reviewed by:	jhb, scottl.
2008-10-10 17:49:47 +00:00
Warner Losh
c14909b6e2 Split out the probing magic of device_probe_and_attach into
device_probe() so that it can be used by busses that may wish to do
additional processing between probe and attach.

Reviewed by:	dfr@
2008-06-20 16:58:15 +00:00
Rui Paulo
221351b7a5 devctl_process_running(): Check for devsoftc.inuse == 1 instead of
devsoftc.async_proc != NULL because the latter might not be true
sometimes.
This way /etc/rc.suspend gets executed.

Reviwed	by:	njl
Submitted by:	Mitsuru IWASAKI <iwasaki at jp.FreeBSD.org>
Tested also by:	Andreas Wetzel <mickey242 at gmx.net>
MFC after:	1 week
2008-05-18 13:55:51 +00:00
John Baldwin
dcc8106854 Implement a BUS_BIND_INTR() method in the bus interface to bind an IRQ
resource to a CPU.  The default method is to pass the request up to the
parent similar to BUS_CONFIG_INTR() so that all busses don't have to
explicitly implement bus_bind_intr.  A bus_bind_intr(9) wrapper routine
similar to bus_setup/teardown_intr() is added for device drivers to use.
Unbinding an interrupt is done by binding it to NOCPU.  The IRQ resource
must be allocated, but it can happen in any order with respect to
bus_setup_intr().  Currently it is only supported on amd64 and i386 via
nexus(4) methods that simply call the intr_bind() routine.

Tested by:	gallatin
2008-03-20 21:24:32 +00:00
Warner Losh
9ab8f3544a Tiny bit of KNF to make bus_setup_intr() look like the rest of this
function.
2008-03-10 01:48:25 +00:00
Warner Losh
908e1e5df5 Any driver that relies on its parent to set the devclass has no way to
know if has siblings that need an actual probe.  Introduce a specail
return value called BUS_PROBE_NOOWILDCARD.  If the driver returns
this, the probe is only successful for devices that have had a
specific devclass set for them.

Reviewed by: current@, jhb@, grehan@
2008-03-09 05:10:22 +00:00
Mitsuru IWASAKI
4f7f6238af Add devctl_process_running() so that power management system driver
can check whether devd(8) is running.

MFC after:	1 week
2008-01-27 16:06:37 +00:00
Warner Losh
d4277fef7b When devclass_get_maxunit is passed a NULL, return -1 to indicate that
there's nothing allocated at all yet.
2007-12-19 22:05:07 +00:00