Commit Graph

243 Commits

Author SHA1 Message Date
Andrew Turner
a5b53ce40c Use the correct node wen reading the compatible property. 2015-05-13 16:02:55 +00:00
Andrew Turner
8a56ddde27 Add the ofw_bus_subr.h change missed in r282770. 2015-05-11 15:47:55 +00:00
Andrew Turner
72a638c7f4 Add ofw_bus_find_compatible to find a compatible ofw node. This will be
used on ARM to help find the correct node to use to start secondary CPUs
as this happens before device enumeration.
2015-05-11 14:10:54 +00:00
Luiz Otavio O Souza
1b53f6c5a3 Remove unnecessary code and make use of generic implementations for
bus_alloc_resource(), bus_release_resource() and bus_set_resource()
(bus_generic_rl_alloc_resource(), bus_generic_rl_release_resource() and
bus_generic_rl_set_resource() respectively).

Do not print the resources for nomatch devices.

Use the inherited method for bus_get_resource_list() on ofw_iicbus.c.

Submitted by:	jhb and Michal Meloun (D2033)
2015-05-10 02:19:27 +00:00
Luiz Otavio O Souza
3bb6bf473f Handle IRQ resources on iicbus and ofw_iicbus.
Based on a patch submitted by Michal Meloun <meloun@miracle.cz>.
2015-05-09 03:05:44 +00:00
Andrew Turner
2c0d026b52 Move the point we attach the ofw driver on arm64 to nexus.c. This will
allow us to have a single place to decide to use ofw or acpi.
2015-05-05 11:13:16 +00:00
Zbigniew Bodek
a83592093c Fix bug in xrefinfo_find() for 64-bit platforms
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
2015-03-30 09:49:54 +00:00
Ian Lepore
ecaecbc7d8 Make simplebus a base class of ofwbus. This allows the elimination of
duplicated code in the two classes, and also allows devices in FDT-based
systems to declare simplebus as their parent and still work correctly
when the FDT data describes the device at the root of the tree rather
than as a child of a simplebus (which is common for interrupt, clock,
and power controllers).

Differential Revision:	https://reviews.freebsd.org/D1990
Submitted by:	Michal Meloun
2015-03-27 23:10:15 +00:00
Andrew Turner
16a1c0a829 Adda function to iterate over the cpu nodes in the OFW or FDT data. This
will be used with arm64 to find which cpus to enable, and could also be
used with 32-bit arm and mips for the same purpose.

Differential Revision:	https://reviews.freebsd.org/D1825
Sponsored by:	The FreeBSD Foundation
2015-02-19 16:34:48 +00:00
Andrew Turner
deb7728379 Add support to get the cpu ID from its device driver in a generic way.
This will be needed by arm64 to find the value to pass to the psci (Power
State Coordination Interface) driver, among other things, used to enable
cores.

Differential Revision:	https://reviews.freebsd.org/D1824
Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
2015-02-19 12:47:48 +00:00
Luiz Otavio O Souza
9855acef2a Do not leak the OFW memory when the result does not satisfy our alignment
requirement.

While here, fix style(9) issues.
2015-01-30 14:09:07 +00:00
Andrew Turner
5b86b0eaba Update the parsing of the cpu node. We are unable to use the reg property
as the cpu id on arm64 as it may use two cells. In it's place we can use
the device id.

It is expected we will use the reg data on arm64 to enable cores so we
still need to read and store it even if it is not yet used.

Differential Revision:	https://reviews.freebsd.org/D1555
Reviewed by:	nwhitehorn
Sponsored by:	The FreeBSD Foundation
2015-01-21 16:52:24 +00:00
Andrew Turner
09eb425a04 Make the clock-frequency property optional as it may not be present on FDT
systems.

Sponsored by:	The FreeBSD Foundation
2015-01-19 11:06:56 +00:00
Nathan Whitehorn
d2d3e9b818 Return an appropriate error code in the case of a missing property rather
than random numbers.

MFC after:	1 week
2015-01-17 07:01:51 +00:00
Nathan Whitehorn
c884d31122 Add two fake properties ("fdtbootcpu" and "fdtmemreserv") to the device
tree's /chosen node to provide out-of-band header fields of the FDT. This
emulation is not perfect without corresponding changes to ofw_fdt_nextprop(),
but is enough to enable lookup by memory-map-parsing code.

MFC after:	1 week
2015-01-16 18:47:20 +00:00
Zbigniew Bodek
4b3d916086 Introduce ofw_bus_reg_to_rl() to replace part of common bus code
Instead of reusing the same reg parsing code, create one, common function
that puts reg contents to the resource list. Address cells and size cells
are passed rather than acquired here so that any bus can have different
default values.

Obtained from:   Semihalf
Reviewed by:     andrew, ian, nwhitehorn
Sponsored by:    The FreeBSD Foundation
2015-01-13 00:00:09 +00:00
Nathan Whitehorn
08b96b9ff5 Restore use of ofw_bus_intr_to_rl() in the pseries vdevice driver after fixing
ofw_bus_intr_to_rl() to match the spec for unspecified interrupt-parent
properties.
2015-01-05 21:39:35 +00:00
Nathan Whitehorn
5499037c63 The path entry for a device tree node and its name property are usually,
but not always, identical. In particular, the path entry may contain a
unit address that the name does not. If the FDT node does have an explicit
name property, treat that as an override of the FDT path rather than
ignoring it.

MFC after:	2 weeks
2015-01-01 22:20:19 +00:00
Ian Lepore
cbe686f709 Don't assume required FDT properties are present. 2014-12-24 01:19:11 +00:00
Ed Maste
55629a87ab Use standard BSD license disclaimer text
Approved by:	benno, nwhitehorn
2014-12-15 22:20:14 +00:00
Rui Paulo
5cead939e9 Move ofw_cpu.c to sys/dev/ofw so that it can be used by other
architectures.

Differential Revision:	https://reviews.freebsd.org/D1307
Reviewed by:	jhibbits
2014-12-14 22:41:08 +00:00
Ian Lepore
844aff82a6 Allow i2c bus speed to be configured via hints, FDT data, and sysctl.
The current support for controlling i2c bus speed is an inconsistant mess.
There are 4 symbolic speed values defined, UNKNOWN, SLOW, FAST, FASTEST.
It seems to be universally assumed that SLOW means the standard 100KHz
rate from the original spec.  Nothing ever calls iicbus_reset() with a
speed of FAST, although some drivers would treat it as the 400KHz standard
speed.  Mostly iicbus_reset() is called with the speed set to UNKNOWN or
FASTEST, and there's really no telling what any individual driver will do
with those.

The speed of an i2c bus is limited by the speed of the slowest device on
the bus.  This means that generally the bus speed needs to be configured
based on the board/system and the components within it.  Historically for
i2c we've configured with device hints.  Newer systems use FDT data and it
documents a clock-frequency property for i2c busses.  Hobbyists and
developers are likely to want on the fly changes.  These changes provide
all 3 methods, but do not require any existing drivers to change to use
the new facilities.

This adds an iicbus method, iicbus_get_frequency(dev, speed) that gets the
frequency for the requested symbolic speed.  If the symbolic speed is SLOW
or if there is no speed configured for the bus, the returned value is
100KHz, always.  Otherwise, if bus speed is configured by hints, fdt,
tunable, or sysctl, that speed is returned.  It also adds a helper
function, iicbus_init_frequency() that any bus driver subclassed from
iicbus can initialize the frequency from some other source of info.

Initial driver implementations are provided for Freescale and TI.

Differential Revision:        https://reviews.freebsd.org/D1174
PR:		195009
2014-11-18 01:54:31 +00:00
Zbigniew Bodek
76a8ef267d Avoid panic in ofwbus caused by not released resource list entry
After resource allocation and release, resource list entry
stays non-NULL. This causes panic in ofwbus_alloc_resource()
on subsequent resource allocation.
Clean appropriate list entry on release to avoid this.

Obtained from:	Semihalf
Reviewed by:	ian
Sponsored by:	The FreeBSD Foundation
2014-11-07 19:34:10 +00:00
Ian Lepore
c47d4cde39 Replace multiple nearly-identical copies of code to walk through an FDT
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
2014-09-25 15:02:33 +00:00
Ian Lepore
26511eb02e When registering an association between a device and an xref phandle, create
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.
2014-09-06 18:43:17 +00:00
Ian Lepore
f021180bfb Revert rr271190, it was based on a misunderstanding. The problem of
non-existant device<->xref info needs to be handled by creating the info,
which will come in a subsequent commit.
2014-09-06 17:50:59 +00:00
Ian Lepore
00eea22f11 Add OF_xref_from_node_strict() which returns -1 if there is no xref handle
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.
2014-09-06 15:11:35 +00:00
John Baldwin
a272a81370 Use callout(9) instead of timeout(9).
Tested by:	danfe
2014-09-02 18:57:19 +00:00
Ian Lepore
b9819c95d1 Fix typo.
Pointy hat:	ian
2014-09-02 03:51:12 +00:00
Ian Lepore
937f32c079 Add OF_xref_from_device() so that there's no need to have an intermediate
call to ofw_bus_get_node() to lookup info that's already in the xreflist.
2014-09-02 03:45:01 +00:00
Ian Lepore
274245c881 Create a mechanism for looking up a device_t associated with an ofw/fdt
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
2014-09-01 22:40:31 +00:00
Ian Lepore
752ba93078 Rename OF_xref_phandle() to OF_node_from_xref() and add a new function
that provides the inverse translation, OF_xref_from_node().

Discussed with:	nwhitehorn
2014-09-01 18:51:01 +00:00
Ian Lepore
c654477e64 Handle various ways that interrupt config data can be malformed by
warning and assuming more or less reasonable values.
2014-08-10 00:30:12 +00:00
Ian Lepore
1fb6bc18cb Use a separate variable for resource id, because 'i' may increment at a
rate greater than 1 on each iteration.
2014-08-10 00:23:57 +00:00
Ian Lepore
633dbf2e1b Adjust ofwbus and simplebus to attach at BUS_PASS_ORDER_MIDDLE, so that
a platform can attach some other bus first if necessary.
2014-08-05 17:32:47 +00:00
Ian Lepore
2d12d35cf8 Set ofwbus and simplebus to attach during BUS_PASS_BUS. 2014-08-05 16:31:03 +00:00
Nathan Whitehorn
e2fc1af45e OF_peer() in IEEE 1275 returns 0 if no peer exists, not -1. 2014-05-11 18:22:05 +00:00
Luiz Otavio O Souza
8d25059572 Move gpiobus routines to dev/gpio. Avoid polluting ofw_bus with bus
specific parts.

Requested by:	nwhitehorn
2014-05-04 04:01:26 +00:00
Luiz Otavio O Souza
628a40b5c4 Fix the gpio-specifier decoding by respecting the GPIO controller's
#gpio-cells property.

Add a new ofw_bus method (OFW_BUS_MAP_GPIOS()) that allows the GPIO
controller to implement its own mapping to deal with gpio-specifiers,
allowing the decoding of gpio-specifiers to be controller specific.

The default ofw_bus_map_gpios() decodes the linux standard (#gpio-cells =
<2>) and the FreeBSD standard (#gpio-cells = <3>).

It pass the gpio-specifier flag field to the children as an ivar variable so
they can act upon.
2014-04-27 12:11:00 +00:00
Luiz Otavio O Souza
bf17755477 Allow the use of OFW I2C bus together with iicbb(4) on OFW-based systems.
This change makes ofw_iicbus attach to iicbb(4) controllers in addition to
the already supported i2c host bridges (iichb).

On iicbb(4) allow the direct access of the OFW parent node by its children,
so they can be directly attached to iicbb(4) node on the DTS without the
need of describing the i2c bus.

Approved by:	adrian (mentor, implicit)
2014-02-13 18:22:49 +00:00
Nathan Whitehorn
65d08437ef Move Open Firmware device root on PowerPC, ARM, and MIPS systems to
a sub-node of nexus (ofwbus) rather than direct attach under nexus. This
fixes FDT on x86 and will make coexistence with ACPI on ARM systems easier.
SPARC is unchanged.

Reviewed by:	imp, ian
2014-02-05 14:44:22 +00:00
Nathan Whitehorn
e4be5a1636 Add a set of helpers (ofw_bus_get_status() and ofw_bus_status_okay()) to
process "status" properties of OF nodes.

I've avoided adding new KOBJ methods here so that we don't have to modify
every ofw_bus in the tree. Since 100% of implementations of ofw_bus use
only ofw_bus_gen_*(), it might be worth garbage-collecting the other
methods as well.
2014-02-02 16:41:54 +00:00
Nathan Whitehorn
bbc6da03ef Open Firmware interrupt specifiers can consist of arbitrary-length byte
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.
2014-02-01 17:17:35 +00:00
Nathan Whitehorn
95e3bfe889 Simplify the ofw_bus_lookup_imap() API slightly: make it allocate maskbuf
internally instead of requiring the caller to allocate it.
2013-12-17 15:11:24 +00:00
Nathan Whitehorn
cb6d9d6cb1 Configure interrupt sense based on device tree information. This extends
the OF interrupt map API to return sense information to the caller and
the PowerPC Open Firmware PCI base driver to use it to program the PIC.
2013-12-17 14:50:35 +00:00
Nathan Whitehorn
e14376e4dd Avoid warning about insecure format with clang. 2013-12-14 22:28:32 +00:00
Nathan Whitehorn
641ed4622f Return the correct IEEE 1275 code for "nextprop". 2013-12-10 21:01:28 +00:00
Nathan Whitehorn
fb5b9994b3 Open Firmware mandates that certain cross-references, in particular those
in /chosen, be ihandles. The ePAPR spec makes those cross-reference phandles,
since FDT has no concept of ihandles. Have the OF FDT CI module interpret
queries about ihandles as cross-reference phandles.
2013-12-01 19:03:20 +00:00
Luiz Otavio O Souza
8ad579cac3 Fix a typo on a comment in ofw_bus_if.m, the default method will return -1
when a node doesn't exist.

Reviewed by:	nwhitehorn
Approved by:	adrian (mentor)
2013-11-12 13:44:50 +00:00
Nathan Whitehorn
c67919895d An addendum: it is possible, though of questionable utility, for a node
to have no properties at all. Do the right thing in such cases.
2013-11-06 14:38:53 +00:00
Nathan Whitehorn
1b12f87dbb Make OF_nextprop() work correctly for FDT by using the libfdt
fdt_next_property_offset() API. The old code would sometimes (e.g. on
the device tree supplied by the RB800 boot loader) get confused and stop
partway through listing properties.

MFC after:	1 week
2013-11-06 14:33:37 +00:00
Ian Lepore
498fa7c1f9 Add a helper routine to search for a compat string in a table that
associates compat strings with arbitrary values that mean something to
the driver.  This is handy for drivers that support several variations
of similar hardware and need to know which one matched.

Reviewed by:	imp, jmg, nwhitehorn
2013-10-25 19:15:21 +00:00
Nathan Whitehorn
6ad36cf2c8 Make sure to get the right node when looking up #interrupt-cells. 2013-10-25 15:37:58 +00:00
Nathan Whitehorn
e3f4d74e21 Remove some of the code required for supporting ssm(4) on SPARC in favor
of a more PowerPC/FDT-focused design. Whenever SPARC64 is integrated
into this rework, this should be (trivially) revisited.
2013-10-24 21:49:23 +00:00
Nathan Whitehorn
863527800c interrupt-parent and #interrupt-cells are written to the tree using
encode-int.
2013-10-24 14:15:05 +00:00
Nathan Whitehorn
a8126ae500 Factor out MI portions of the PowerPC nexus device into /sys/dev/ofw. The
sparc64 driver will be modified to use this shortly.
2013-10-23 20:00:14 +00:00
Nathan Whitehorn
f214848258 Add two new interfaces to ofw_bus:
- ofw_bus_map_intr()
  Maps an (iparent, IRQ) tuple to a system-global interrupt number in some
  platform dependent way. This is meant to be implemented as a replacement
  for [FDT_]MAP_IRQ() that is an MI interface that knows about the bus
  hierarchy.
- ofw_bus_config_intr()
  Configures an interrupt (previously mapped) based on firmware sense flags.
  This replaces manual interpretation of the sense field in bus drivers and
  will, in a follow-up, allow that interpretation to be redirected to the PIC
  drivers where it belongs. This will eventually replace the tables in
  /sys/dev/fdt/fdt_ARCH.c

The PowerPC/AIM code has been converted to use these globally, with an
implementation in terms of MAP_IRQ() and powerpc_config_intr(), assuming
OpenPIC, at the bus root in nexus(4). The ofw_bus_config_intr() will shortly
be integrated into pic_if.m and bounced through nexus into the PIC tree.

FDT integration will happen significantly later due to larger testing
requirements. This patch in general also lays the groundwork for the removal
of /sys/dev/fdt/fdt_ARCH.c and machine/fdt.h.
2013-10-23 17:24:21 +00:00
Nathan Whitehorn
755c959170 Remove OF_instance_to_package() hack for FDT and replace with use of the
generic OF_xref_phandle() API universally. Also replace some related
explicit uses of fdt32_to_cpu() with OF_getencprop() calls.
2013-10-23 14:04:09 +00:00
Nathan Whitehorn
d3a0a0f37e Make all Open Firmware internal interfaces endian-safe by using the new
OF_getencprop() API. This removes one explicit endianness conversion in
ofw_iicbus.c.
2013-10-23 13:55:41 +00:00
Andreas Tobler
5e40646cc3 Fix build. 2013-10-23 03:59:51 +00:00
Nathan Whitehorn
4231c48fa1 A few other common cases for encode-int decoding: OF_getencprop_alloc()
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
2013-10-22 21:20:05 +00:00
Nathan Whitehorn
29fdf9ef00 Add a new function (OF_getencprop()) that undoes the transformation applied
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.
2013-10-22 20:57:24 +00:00
Nathan Whitehorn
bb512af9ec Return standards-compliant code from OF_nextprop() with FDT when no
properties remain on this node.
2013-10-22 02:39:56 +00:00
Nathan Whitehorn
6064b6ac48 Allow the OFW interrupt mapping code to work with PCI devices not enumerated
by Open Firmware, as in the case of FDT.
2013-10-21 00:04:26 +00:00
Nathan Whitehorn
c088841850 Add a kernel interface (OF_xref_phandle()) for systems where phandles
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
2013-09-15 14:19:17 +00:00
Nathan Whitehorn
22b256dfcb Make the primary name of the OF console device /dev/ofwcons, and only
alias it to the contents of the output property if it is defined. This
avoids a panic when booting machines (QEMU) where the output-device
property is not defined.

Since output-device is free-form and potentially conflicts with other
entries in /dev, I also am not sure we should be doing the aliasing at
all, but this at least makes things work again.

Approved by:	re (kib)
2013-09-09 16:51:35 +00:00
Hiroki Sato
26ca49652b - Add OF_hasprop() and ofw_bus_has_prop(). These can be used to check
existence of the property.

- Fix ofw_bus_is_compatible{,_strict}() to prevent substring match in the
  compatible string.

Reviewed by:	raj
2012-08-18 11:25:07 +00:00
Oleksandr Tymoshenko
3c92de458b Merging of projects/armv6, part 4
r232281:
Fix byte order.
2012-08-15 03:33:57 +00:00
Nathan Whitehorn
0d8d9edaaa Make ofw_bus_get_node() consistently return -1 when there is no associated
OF node, instead of a random mixture of 0 and -1. Update all checks for 0
to check for -1 instead.

MFC after:	4 weeks
2012-03-15 22:53:39 +00:00
Marius Strobl
1cbb2a2408 Implement OF_printf() using kvprintf() directly, avoiding to use a
buffer and allowing to handle newlines properly
2012-01-27 22:29:29 +00:00
Andriy Gapon
9976156f12 kern cons: introduce infrastructure for console grabbing by kernel
At the moment grab and ungrab methods of all console drivers are no-ops.

Current intended meaning of the calls is that the kernel takes control of
console input.  In the future the semantics may be extended to mean that
the calling thread takes full ownership of the console (e.g. console
output from other threads could be suspended).

Inspired by:	bde
MFC after:	2 months
2011-12-17 15:08:43 +00:00
Jayachandran C.
07042bef45 Fix OF_finddevice error return value in case of FDT.
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
2011-12-02 15:24:39 +00:00
Marius Strobl
848e30ff51 s,KOBJMETHOD_END,DEVMETHOD_END,g in order to fully hide the explicit mention
of kobj(9) from device drivers.
2011-11-22 21:55:40 +00:00
Marius Strobl
d7ecd801ed As it turns out, r186347 actually is insufficient to avoid the use of the
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
2011-11-15 20:11:03 +00:00
Jayachandran C.
af6edc2854 FDT changes for 64 bit kernel
Use the offset into the device tree from fdtp as the phandle instead
of using pointer into the device tree.  This will make sure that the
phandle fits into a uint32_t type, even when compiled for 64bit.

Reviewed by:	raj, nathanw, marcel
2011-10-17 13:44:33 +00:00
Robert Watson
e5a0927394 Follow up to r225203 refining break-to-debugger run-time configuration
improvements:

(1) Implement new model in previously missed at91 UART driver
(2) Move BREAK_TO_DEBUGGER and ALT_BREAK_TO_DEBUGGER from opt_comconsole.h
    to opt_kdb.h (spotted by np)
(3) Garbage collect now-unused opt_comconsole.h

MFC after:	3 weeks
Approved by:	re (bz)
2011-08-27 14:24:27 +00:00
Robert Watson
4cf7545589 Attempt to make break-to-debugger and alternative break-to-debugger more
accessible:

(1) Always compile in support for breaking into the debugger if options
    KDB is present in the kernel.

(2) Disable both by default, but allow them to be enabled via tunables
    and sysctls debug.kdb.break_to_debugger and
    debug.kdb.alt_break_to_debugger.

(3) options BREAK_TO_DEBUGGER and options ALT_BREAK_TO_DEBUGGER continue
    to behave as before -- only now instead of compiling in
    break-to-debugger support, they change the default values of the
    above sysctls to enable those features by default.  Current kernel
    configurations should, therefore, continue to behave as expected.

(4) Migrate alternative break-to-debugger state machine logic out of
    individual device drivers into centralised KDB code.  This has a
    number of upsides, but also one downside: it's now tricky to release
    sio spin locks when entering the debugger, so we don't.  However,
    similar logic does not exist in other device drivers, including uart.

(5) dcons requires some special handling; unlike other console types, it
    allows overriding KDB's own debugger selection, so we need a new
    interface to KDB to allow that to work.

GENERIC kernels in -CURRENT will now support break-to-debugger as long as
appropriate boot/run-time options are set, which should improve the
debuggability of BETA kernels significantly.

MFC after:	3 weeks
Reviewed by:	kib, nwhitehorn
Approved by:	re (bz)
2011-08-26 21:46:36 +00:00
Rafal Jaworowski
96fe0b3552 Return IEEE 1275 compliant error codes.
Submitted by:	nwhitehorn
2010-11-11 13:42:46 +00:00
Nathan Whitehorn
0bad71a347 Make all OF client interface calls return the maximum kind of
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.
2010-11-09 19:45:29 +00:00
Marius Strobl
cdb25d827e Change OF_interpret() to also take an array of cell_t (missed in r209801).
Reviewed by:	nwhitehorn
2010-09-11 18:55:00 +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
Nathan Whitehorn
a26209a43a Missed a file in r209803: this header contains a definition of
OFW_STD_32BIT.

Pointy hat to:	me
2010-07-08 18:15:06 +00:00
Nathan Whitehorn
054e5dcbe4 Change the argument type to OF_call_method to take an array of cell_t
instead of unsigned longs to prepare for platforms where they are not
the same.
2010-07-08 14:29:23 +00:00
Nathan Whitehorn
eaef5f0af8 Provide for multiple, cascaded PICs on PowerPC systems, and extend the
OFW interrupt map interface to also return the device's interrupt parent.

MFC after:	8.1-RELEASE
2010-06-18 14:06:27 +00:00
Rafal Jaworowski
6365985dfc Initial implementation of the OFW i/f methods for FDT back-end.
Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
2010-05-28 10:51:44 +00:00
Rafal Jaworowski
8297758a22 Prepare and extend OFW layer for FDT support.
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
2010-05-28 10:43:56 +00:00
Nathan Whitehorn
4a26780b9a Pull OF_quiesce() out of the MI Open Firmware layer and entirely into
PPC ofw_machdep.c, in recognition of its state as a machine specific hack.

Requested by:	marius
2010-05-16 22:01:43 +00:00
Nathan Whitehorn
79bf3fcd18 On PowerMac11,2 and (presumably) PowerMac12,1, we need to quiesce the
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.
2010-05-16 15:56:59 +00:00
Marius Strobl
bd7e69e4c5 With r205496 in place we should ensure that nargs and nreturns are always
set to sane values as they no longer default to 0, otherwise some OFW
implementation might copy in or out arguments not based on what the actual
function takes but what ever stack garbage nargs and nreturns supply.

Reviewed by:	nwhitehorn
2010-04-02 21:48:27 +00:00
Nathan Whitehorn
d4bccd63a2 Do not declare the various OFW command buffers static. It does not
appear to be necessary on either sparc64 or powerpc, and is a
concurrency nightmare.

Reviewed by:	marius
2010-03-23 01:09:45 +00:00
Joel Dahl
eac073cde2 The NetBSD Foundation has granted permission to remove clause 3 and 4 from
their software.

Obtained from:	NetBSD
2010-03-01 16:52:11 +00:00
Marius Strobl
9f91930a85 Missed style fixes. 2009-06-14 00:15:26 +00:00
Marius Strobl
481d6b549b Fix style. 2009-06-14 00:05:38 +00:00
Andriy Gapon
4fc23012c6 strict kobj signatures: some ofw_setprop fixes
propname parameter is const

Reviewed by:	imp, current@
Approved by:	jhb (mentor)
2009-06-11 17:15:20 +00:00
Ed Schouten
c5e30cc02b Last minute TTY API change: remove mutex argument from tty_alloc().
I don't want people to override the mutex when allocating a TTY. It has
to be there, to keep drivers like syscons happy. So I'm creating a
tty_alloc_mutex() which can be used in those cases. tty_alloc_mutex()
should eventually be removed.

The advantage of this approach, is that we can just remove a function,
without breaking the regular API in the future.
2009-05-29 06:41:23 +00:00
Marius Strobl
49bbb93c07 Unbreak OF_interpret() and its standard implementation after r186347. 2009-03-29 15:10:49 +00:00
Nathan Whitehorn
e2c10e7d4a Some Apple I2C buses give the device's I2C address in a property with the
name i2c-address instead of reg. Change the OFW I2C probe to check both
locations for the address.

Submitted by:	Marco Trillo
Reported by:	Justin Hibbits
2009-03-02 15:22:01 +00:00
Nathan Whitehorn
ed366ae5c8 Set the wrong softc size when defining the ofw_iicbus class. Change it to
the correct value.
2009-01-20 14:06:30 +00:00
Nathan Whitehorn
3bb481ffb0 Import an Open Firmware I2C bus module. This attaches firmware device tree
indicated I2C devices, and provides an ofw_bus interface for driver probing.
This should be MI, but is currently provided only on PowerPC due to lack of
sparc64 hardware with an I2C controller.

Discussed on:	freebsd-arch
2009-01-15 02:46:43 +00:00
Nathan Whitehorn
acb97117e3 Fix the OFW interrupt map parser to use its own idea of the number of interrupt
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
2009-01-03 19:38:47 +00:00