Commit Graph

205 Commits

Author SHA1 Message Date
Michal Meloun
0b757c475b OFW: Add helper functions for parsing xref based lists.
By using this functions, we can parse a list of tuples, each of them holds
xref and variable number of values.
This kind of list is used in DT for clocks, gpios, resets ...

Discussed with:	ian, nwhitehorn
Approved by:	kib (mentor)
Differential Revision: https://reviews.freebsd.org/D4316
2015-12-13 08:17:49 +00:00
Michal Meloun
821a61efa0 OFW: Move code for searching interrupt parent into separate function.
It can be used by interrupt controller drivers.

Approved by:	kib (mentor)
2015-12-02 14:21:16 +00:00
Andreas Tobler
ad52ee58e1 Improve r290373, do a runtime check rather than a compile time switch. I
learned that the Power8 and the PS3 have a mix of OFW and FDT. Both have AIM
defined. But currently they are not affected. They have no I2C devices under
OFW.

This version was tested on a Quad G5 and build tested for armv6*.

Discussed with	nwhitehorn@
Reviewed by:	ian@
2015-11-08 21:06:51 +00:00
Andreas Tobler
e1034e1460 Add a compile time switch to distinguish between 7-bit and 8-bit I2C address
usage. The comment in the code should explain the situation.

Discussed with:	 ian@
2015-11-04 22:46:30 +00:00
Ian Lepore
9a2bb68894 Fix parsing of I2C addresses properties in fdt data. I2C address is
represented in 7-bits format in DT files, but system expect it in 8-bit
format.  Also, fix two drivers that locally hack around this bug.

Submitted by:	Michal Meloun <meloun@miracle.cz>
2015-10-21 15:41:16 +00:00
Zbigniew Bodek
8b21d6ae5a Limit ofw_cpu_early_foreach() to CPUs only
On some platforms, the /cpus node contains cpu-to-cluster
map which deffinitely is not a CPU node. Its presence was
causing incrementing of "id" variable and reporting more
CPUs available than it should.
To make "id" valid, increment it only when an entry really
is a CPU device.

Reviewed by:   andrew
Obtained from: Semihalf
Sponsored by:  The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D3216
2015-07-28 13:16:08 +00:00
Oleksandr Tymoshenko
7339f7821b OF_getencprop_alloc shouldn't be used to get string value. If string
length + 1 is not divisible by 4 this function returns NULL property
value. Otherwise - string with each 4 letters inverted
2015-07-25 00:58:50 +00:00
Andrew Turner
63e8633e80 Fix an infinite loop when a node doesn't have an interrupt-parent property.
Submitted by:	Aleksey Kuleshov <rndfax@yandex.ru>
Differential Revision: https://reviews.freebsd.org/D3041
2015-07-15 13:28:25 +00:00
Andrew Turner
f3856d8fcb Also accept "ok" to enable a device, some vendor device trees use this when
they mean "okay"
2015-07-14 19:11:16 +00:00
Warner Losh
bb39ff4c36 Add ofw_bus_find_child_by_phandle, a helper routine to find a device_t
child matchig a given phandle_t.

Differential Revision: https://reviews.freebsd.org/D2871
2015-06-20 04:48:48 +00:00
Oleksandr Tymoshenko
37c1967c5b Rename fdt_find_child to ofw_bus_find_child. There is nothing FDT-specific
in this function.

Suggested by: andrew@
2015-05-24 23:53:10 +00:00
Ruslan Bukin
a8c5ea04b4 Provide the number of interrupt resources added to the list
by using extra argument, so caller will know that.
2015-05-15 13:55:18 +00:00
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