Merge branch 'master' of git://git.denx.de/u-boot-dm

This commit is contained in:
Tom Rini 2014-06-20 20:03:51 -04:00
commit 39b6d07fd7
38 changed files with 831 additions and 61 deletions

28
README
View file

@ -1000,6 +1000,7 @@ The following options need to be configured:
CONFIG_CMD_IMLS List all images found in NOR flash
CONFIG_CMD_IMLS_NAND * List all images found in NAND flash
CONFIG_CMD_IMMAP * IMMR dump support
CONFIG_CMD_IOTRACE * I/O tracing for debugging
CONFIG_CMD_IMPORTENV * import an environment
CONFIG_CMD_INI * import data from an ini file into the env
CONFIG_CMD_IRQ * irqinfo
@ -1171,6 +1172,28 @@ The following options need to be configured:
Note that if the GPIO device uses I2C, then the I2C interface
must also be configured. See I2C Support, below.
- I/O tracing:
When CONFIG_IO_TRACE is selected, U-Boot intercepts all I/O
accesses and can checksum them or write a list of them out
to memory. See the 'iotrace' command for details. This is
useful for testing device drivers since it can confirm that
the driver behaves the same way before and after a code
change. Currently this is supported on sandbox and arm. To
add support for your architecture, add '#include <iotrace.h>'
to the bottom of arch/<arch>/include/asm/io.h and test.
Example output from the 'iotrace stats' command is below.
Note that if the trace buffer is exhausted, the checksum will
still continue to operate.
iotrace is enabled
Start: 10000000 (buffer start address)
Size: 00010000 (buffer size)
Offset: 00000120 (current buffer offset)
Output: 10000120 (start + offset)
Count: 00000018 (number of trace records)
CRC32: 9526fb66 (CRC32 of all trace records)
- Timestamp Support:
When CONFIG_TIMESTAMP is selected, the timestamp
@ -5308,6 +5331,11 @@ Information structure as we define in include/asm-<arch>/u-boot.h,
and make sure that your definition of IMAP_ADDR uses the same value
as your U-Boot configuration in CONFIG_SYS_IMMR.
Note that U-Boot now has a driver model, a unified model for drivers.
If you are adding a new driver, plumb it into driver model. If there
is no uclass available, you are encouraged to create one. See
doc/driver-model.
Configuring the Linux kernel:
-----------------------------

View file

@ -0,0 +1 @@
../../../../include/dt-bindings

View file

@ -1,3 +1,6 @@
#include <dt-bindings/gpio/tegra-gpio.h>
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include "skeleton.dtsi"
/ {
@ -46,17 +49,17 @@
0 143 0x04>;
};
gpio: gpio {
gpio: gpio@6000d000 {
compatible = "nvidia,tegra114-gpio", "nvidia,tegra30-gpio";
reg = <0x6000d000 0x1000>;
interrupts = <0 32 0x04
0 33 0x04
0 34 0x04
0 35 0x04
0 55 0x04
0 87 0x04
0 89 0x04
0 125 0x04>;
interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 34 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 55 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 125 IRQ_TYPE_LEVEL_HIGH>;
#gpio-cells = <2>;
gpio-controller;
#interrupt-cells = <2>;

View file

@ -1,3 +1,6 @@
#include <dt-bindings/gpio/tegra-gpio.h>
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include "skeleton.dtsi"
/ {
@ -49,14 +52,14 @@
gpio: gpio@6000d000 {
compatible = "nvidia,tegra124-gpio", "nvidia,tegra30-gpio";
reg = <0x6000d000 0x1000>;
interrupts = <0 32 0x04
0 33 0x04
0 34 0x04
0 35 0x04
0 55 0x04
0 87 0x04
0 89 0x04
0 125 0x04>;
interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 34 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 55 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 125 IRQ_TYPE_LEVEL_HIGH>;
#gpio-cells = <2>;
gpio-controller;
#interrupt-cells = <2>;

View file

@ -1,3 +1,6 @@
#include <dt-bindings/gpio/tegra-gpio.h>
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include "skeleton.dtsi"
/ {
@ -139,10 +142,18 @@
gpio: gpio@6000d000 {
compatible = "nvidia,tegra20-gpio";
reg = < 0x6000d000 0x1000 >;
interrupts = < 64 65 66 67 87 119 121 >;
reg = <0x6000d000 0x1000>;
interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 34 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 55 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>;
#gpio-cells = <2>;
gpio-controller;
#interrupt-cells = <2>;
interrupt-controller;
};
pinmux: pinmux@70000000 {

View file

@ -1,3 +1,6 @@
#include <dt-bindings/gpio/tegra-gpio.h>
#include <dt-bindings/interrupt-controller/arm-gic.h>
#include "skeleton.dtsi"
/ {
@ -47,17 +50,17 @@
clocks = <&tegra_car 34>;
};
gpio: gpio {
gpio: gpio@6000d000 {
compatible = "nvidia,tegra30-gpio";
reg = <0x6000d000 0x1000>;
interrupts = <0 32 0x04
0 33 0x04
0 34 0x04
0 35 0x04
0 55 0x04
0 87 0x04
0 89 0x04
0 125 0x04>;
interrupts = <GIC_SPI 32 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 33 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 34 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 35 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 55 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 87 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 125 IRQ_TYPE_LEVEL_HIGH>;
#gpio-cells = <2>;
gpio-controller;
#interrupt-cells = <2>;

View file

@ -437,4 +437,7 @@ out:
#endif /* __mem_isa */
#endif /* __KERNEL__ */
#include <iotrace.h>
#endif /* __ASM_ARM_IO_H */

View file

@ -0,0 +1 @@
../../../../include/dt-bindings

View file

@ -0,0 +1 @@
../../../../include/dt-bindings

View file

@ -40,4 +40,14 @@ static inline void unmap_sysmem(const void *vaddr)
/* Map from a pointer to our RAM buffer */
phys_addr_t map_to_sysmem(const void *ptr);
/* Define nops for sandbox I/O access */
#define readb(addr) 0
#define readw(addr) 0
#define readl(addr) 0
#define writeb(v, addr)
#define writew(v, addr)
#define writel(v, addr)
#include <iotrace.h>
#endif

View file

@ -0,0 +1 @@
../../../../include/dt-bindings

View file

@ -114,6 +114,7 @@ obj-$(CONFIG_CMD_FUSE) += cmd_fuse.o
obj-$(CONFIG_CMD_GETTIME) += cmd_gettime.o
obj-$(CONFIG_CMD_GPIO) += cmd_gpio.o
obj-$(CONFIG_CMD_I2C) += cmd_i2c.o
obj-$(CONFIG_CMD_IOTRACE) += cmd_iotrace.o
obj-$(CONFIG_CMD_HASH) += cmd_hash.o
obj-$(CONFIG_CMD_IDE) += cmd_ide.o
obj-$(CONFIG_CMD_IMMAP) += cmd_immap.o
@ -261,6 +262,7 @@ obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o
obj-$(CONFIG_OF_LIBFDT) += image-fdt.o
obj-$(CONFIG_FIT) += image-fit.o
obj-$(CONFIG_FIT_SIGNATURE) += image-sig.o
obj-$(CONFIG_IO_TRACE) += iotrace.o
obj-y += memsize.o
obj-y += stdio.o

73
common/cmd_iotrace.c Normal file
View file

@ -0,0 +1,73 @@
/*
* Copyright (c) 2014 Google, Inc
*
* SPDX-License-Identifier: GPL-2.0+
*/
#include <common.h>
#include <command.h>
#include <iotrace.h>
static void do_print_stats(void)
{
ulong start, size, offset, count;
printf("iotrace is %sabled\n", iotrace_get_enabled() ? "en" : "dis");
iotrace_get_buffer(&start, &size, &offset, &count);
printf("Start: %08lx\n", start);
printf("Size: %08lx\n", size);
printf("Offset: %08lx\n", offset);
printf("Output: %08lx\n", start + offset);
printf("Count: %08lx\n", count);
printf("CRC32: %08lx\n", (ulong)iotrace_get_checksum());
}
static int do_set_buffer(int argc, char * const argv[])
{
ulong addr = 0, size = 0;
if (argc == 2) {
addr = simple_strtoul(*argv++, NULL, 16);
size = simple_strtoul(*argv++, NULL, 16);
} else if (argc != 0) {
return CMD_RET_USAGE;
}
iotrace_set_buffer(addr, size);
return 0;
}
int do_iotrace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
const char *cmd = argc < 2 ? NULL : argv[1];
if (!cmd)
return cmd_usage(cmdtp);
switch (*cmd) {
case 'b':
return do_set_buffer(argc - 2, argv + 2);
case 'p':
iotrace_set_enabled(0);
break;
case 'r':
iotrace_set_enabled(1);
break;
case 's':
do_print_stats();
break;
default:
return CMD_RET_USAGE;
}
return 0;
}
U_BOOT_CMD(
iotrace, 4, 1, do_iotrace,
"iotrace utility commands",
"stats - display iotrace stats\n"
"iotrace buffer <address> <size> - set iotrace buffer\n"
"iotrace pause - pause tracing\n"
"iotrace resume - resume tracing"
);

169
common/iotrace.c Normal file
View file

@ -0,0 +1,169 @@
/*
* Copyright (c) 2014 Google, Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#define IOTRACE_IMPL
#include <common.h>
#include <asm/io.h>
DECLARE_GLOBAL_DATA_PTR;
/* Support up to the machine word length for now */
typedef ulong iovalue_t;
enum iotrace_flags {
IOT_8 = 0,
IOT_16,
IOT_32,
IOT_READ = 0 << 3,
IOT_WRITE = 1 << 3,
};
/**
* struct iotrace_record - Holds a single I/O trace record
*
* @flags: I/O access type
* @addr: Address of access
* @value: Value written or read
*/
struct iotrace_record {
enum iotrace_flags flags;
phys_addr_t addr;
iovalue_t value;
};
/**
* struct iotrace - current trace status and checksum
*
* @start: Start address of iotrace buffer
* @size: Size of iotrace buffer in bytes
* @offset: Current write offset into iotrace buffer
* @crc32: Current value of CRC chceksum of trace records
* @enabled: true if enabled, false if disabled
*/
static struct iotrace {
ulong start;
ulong size;
ulong offset;
u32 crc32;
bool enabled;
} iotrace;
static void add_record(int flags, const void *ptr, ulong value)
{
struct iotrace_record srec, *rec = &srec;
/*
* We don't support iotrace before relocation. Since the trace buffer
* is set up by a command, it can't be enabled at present. To change
* this we would need to set the iotrace buffer at build-time. See
* lib/trace.c for how this might be done if you are interested.
*/
if (!(gd->flags & GD_FLG_RELOC) || !iotrace.enabled)
return;
/* Store it if there is room */
if (iotrace.offset + sizeof(*rec) < iotrace.size) {
rec = (struct iotrace_record *)map_sysmem(
iotrace.start + iotrace.offset,
sizeof(value));
}
rec->flags = flags;
rec->addr = map_to_sysmem(ptr);
rec->value = value;
/* Update our checksum */
iotrace.crc32 = crc32(iotrace.crc32, (unsigned char *)rec,
sizeof(*rec));
iotrace.offset += sizeof(struct iotrace_record);
}
u32 iotrace_readl(const void *ptr)
{
u32 v;
v = readl(ptr);
add_record(IOT_32 | IOT_READ, ptr, v);
return v;
}
void iotrace_writel(ulong value, const void *ptr)
{
add_record(IOT_32 | IOT_WRITE, ptr, value);
writel(value, ptr);
}
u16 iotrace_readw(const void *ptr)
{
u32 v;
v = readw(ptr);
add_record(IOT_16 | IOT_READ, ptr, v);
return v;
}
void iotrace_writew(ulong value, const void *ptr)
{
add_record(IOT_16 | IOT_WRITE, ptr, value);
writew(value, ptr);
}
u8 iotrace_readb(const void *ptr)
{
u32 v;
v = readb(ptr);
add_record(IOT_8 | IOT_READ, ptr, v);
return v;
}
void iotrace_writeb(ulong value, const void *ptr)
{
add_record(IOT_8 | IOT_WRITE, ptr, value);
writeb(value, ptr);
}
void iotrace_reset_checksum(void)
{
iotrace.crc32 = 0;
}
u32 iotrace_get_checksum(void)
{
return iotrace.crc32;
}
void iotrace_set_enabled(int enable)
{
iotrace.enabled = enable;
}
int iotrace_get_enabled(void)
{
return iotrace.enabled;
}
void iotrace_set_buffer(ulong start, ulong size)
{
iotrace.start = start;
iotrace.size = size;
iotrace.offset = 0;
iotrace.crc32 = 0;
}
void iotrace_get_buffer(ulong *start, ulong *size, ulong *offset, ulong *count)
{
*start = iotrace.start;
*size = iotrace.size;
*offset = iotrace.offset;
*count = iotrace.offset / sizeof(struct iotrace_record);
}

View file

@ -222,7 +222,44 @@ device tree) and probe.
Platform Data
-------------
Where does the platform data come from? See demo-pdata.c which
Platform data is like Linux platform data, if you are familiar with that.
It provides the board-specific information to start up a device.
Why is this information not just stored in the device driver itself? The
idea is that the device driver is generic, and can in principle operate on
any board that has that type of device. For example, with modern
highly-complex SoCs it is common for the IP to come from an IP vendor, and
therefore (for example) the MMC controller may be the same on chips from
different vendors. It makes no sense to write independent drivers for the
MMC controller on each vendor's SoC, when they are all almost the same.
Similarly, we may have 6 UARTs in an SoC, all of which are mostly the same,
but lie at different addresses in the address space.
Using the UART example, we have a single driver and it is instantiated 6
times by supplying 6 lots of platform data. Each lot of platform data
gives the driver name and a pointer to a structure containing information
about this instance - e.g. the address of the register space. It may be that
one of the UARTS supports RS-485 operation - this can be added as a flag in
the platform data, which is set for this one port and clear for the rest.
Think of your driver as a generic piece of code which knows how to talk to
a device, but needs to know where it is, any variant/option information and
so on. Platform data provides this link between the generic piece of code
and the specific way it is bound on a particular board.
Examples of platform data include:
- The base address of the IP block's register space
- Configuration options, like:
- the SPI polarity and maximum speed for a SPI controller
- the I2C speed to use for an I2C device
- the number of GPIOs available in a GPIO device
Where does the platform data come from? It is either held in a structure
which is compiled into U-Boot, or it can be parsed from the Device Tree
(see 'Device Tree' below).
For an example of how it can be compiled in, see demo-pdata.c which
sets up a table of driver names and their associated platform data.
The data can be interpreted by the drivers however they like - it is
basically a communication scheme between the board-specific code and
@ -259,21 +296,30 @@ following device tree fragment:
sides = <4>;
};
This means that instead of having lots of U_BOOT_DEVICE() declarations in
the board file, we put these in the device tree. This approach allows a lot
more generality, since the same board file can support many types of boards
(e,g. with the same SoC) just by using different device trees. An added
benefit is that the Linux device tree can be used, thus further simplifying
the task of board-bring up either for U-Boot or Linux devs (whoever gets to
the board first!).
The easiest way to make this work it to add a few members to the driver:
.platdata_auto_alloc_size = sizeof(struct dm_test_pdata),
.ofdata_to_platdata = testfdt_ofdata_to_platdata,
.probe = testfdt_drv_probe,
The 'auto_alloc' feature allowed space for the platdata to be allocated
and zeroed before the driver's ofdata_to_platdata method is called. This
method reads the information out of the device tree and puts it in
dev->platdata. Then the probe method is called to set up the device.
and zeroed before the driver's ofdata_to_platdata() method is called. The
ofdata_to_platdata() method, which the driver write supplies, should parse
the device tree node for this device and place it in dev->platdata. Thus
when the probe method is called later (to set up the device ready for use)
the platform data will be present.
Note that both methods are optional. If you provide an ofdata_to_platdata
method then it will be called first (after bind). If you provide a probe
method it will be called next.
method then it will be called first (during activation). If you provide a
probe method it will be called next. See Driver Lifecycle below for more
details.
If you don't want to have the platdata automatically allocated then you
can leave out platdata_auto_alloc_size. In this case you can use malloc
@ -295,6 +341,166 @@ numbering comes from include/dm/uclass.h. To add a new uclass, add to the
end of the enum there, then declare your uclass as above.
Driver Lifecycle
----------------
Here are the stages that a device goes through in driver model. Note that all
methods mentioned here are optional - e.g. if there is no probe() method for
a device then it will not be called. A simple device may have very few
methods actually defined.
1. Bind stage
A device and its driver are bound using one of these two methods:
- Scan the U_BOOT_DEVICE() definitions. U-Boot It looks up the
name specified by each, to find the appropriate driver. It then calls
device_bind() to create a new device and bind' it to its driver. This will
call the device's bind() method.
- Scan through the device tree definitions. U-Boot looks at top-level
nodes in the the device tree. It looks at the compatible string in each node
and uses the of_match part of the U_BOOT_DRIVER() structure to find the
right driver for each node. It then calls device_bind() to bind the
newly-created device to its driver (thereby creating a device structure).
This will also call the device's bind() method.
At this point all the devices are known, and bound to their drivers. There
is a 'struct udevice' allocated for all devices. However, nothing has been
activated (except for the root device). Each bound device that was created
from a U_BOOT_DEVICE() declaration will hold the platdata pointer specified
in that declaration. For a bound device created from the device tree,
platdata will be NULL, but of_offset will be the offset of the device tree
node that caused the device to be created. The uclass is set correctly for
the device.
The device's bind() method is permitted to perform simple actions, but
should not scan the device tree node, not initialise hardware, nor set up
structures or allocate memory. All of these tasks should be left for
the probe() method.
Note that compared to Linux, U-Boot's driver model has a separate step of
probe/remove which is independent of bind/unbind. This is partly because in
U-Boot it may be expensive to probe devices and we don't want to do it until
they are needed, or perhaps until after relocation.
2. Activation/probe
When a device needs to be used, U-Boot activates it, by following these
steps (see device_probe()):
a. If priv_auto_alloc_size is non-zero, then the device-private space
is allocated for the device and zeroed. It will be accessible as
dev->priv. The driver can put anything it likes in there, but should use
it for run-time information, not platform data (which should be static
and known before the device is probed).
b. If platdata_auto_alloc_size is non-zero, then the platform data space
is allocated. This is only useful for device tree operation, since
otherwise you would have to specific the platform data in the
U_BOOT_DEVICE() declaration. The space is allocated for the device and
zeroed. It will be accessible as dev->platdata.
c. If the device's uclass specifies a non-zero per_device_auto_alloc_size,
then this space is allocated and zeroed also. It is allocated for and
stored in the device, but it is uclass data. owned by the uclass driver.
It is possible for the device to access it.
d. All parent devices are probed. It is not possible to activate a device
unless its predecessors (all the way up to the root device) are activated.
This means (for example) that an I2C driver will require that its bus
be activated.
e. If the driver provides an ofdata_to_platdata() method, then this is
called to convert the device tree data into platform data. This should
do various calls like fdtdec_get_int(gd->fdt_blob, dev->of_offset, ...)
to access the node and store the resulting information into dev->platdata.
After this point, the device works the same way whether it was bound
using a device tree node or U_BOOT_DEVICE() structure. In either case,
the platform data is now stored in the platdata structure. Typically you
will use the platdata_auto_alloc_size feature to specify the size of the
platform data structure, and U-Boot will automatically allocate and zero
it for you before entry to ofdata_to_platdata(). But if not, you can
allocate it yourself in ofdata_to_platdata(). Note that it is preferable
to do all the device tree decoding in ofdata_to_platdata() rather than
in probe(). (Apart from the ugliness of mixing configuration and run-time
data, one day it is possible that U-Boot will cache platformat data for
devices which are regularly de/activated).
f. The device's probe() method is called. This should do anything that
is required by the device to get it going. This could include checking
that the hardware is actually present, setting up clocks for the
hardware and setting up hardware registers to initial values. The code
in probe() can access:
- platform data in dev->platdata (for configuration)
- private data in dev->priv (for run-time state)
- uclass data in dev->uclass_priv (for things the uclass stores
about this device)
Note: If you don't use priv_auto_alloc_size then you will need to
allocate the priv space here yourself. The same applies also to
platdata_auto_alloc_size. Remember to free them in the remove() method.
g. The device is marked 'activated'
h. The uclass's post_probe() method is called, if one exists. This may
cause the uclass to do some housekeeping to record the device as
activated and 'known' by the uclass.
3. Running stage
The device is now activated and can be used. From now until it is removed
all of the above structures are accessible. The device appears in the
uclass's list of devices (so if the device is in UCLASS_GPIO it will appear
as a device in the GPIO uclass). This is the 'running' state of the device.
4. Removal stage
When the device is no-longer required, you can call device_remove() to
remove it. This performs the probe steps in reverse:
a. The uclass's pre_remove() method is called, if one exists. This may
cause the uclass to do some housekeeping to record the device as
deactivated and no-longer 'known' by the uclass.
b. All the device's children are removed. It is not permitted to have
an active child device with a non-active parent. This means that
device_remove() is called for all the children recursively at this point.
c. The device's remove() method is called. At this stage nothing has been
deallocated so platform data, private data and the uclass data will all
still be present. This is where the hardware can be shut down. It is
intended that the device be completely inactive at this point, For U-Boot
to be sure that no hardware is running, it should be enough to remove
all devices.
d. The device memory is freed (platform data, private data, uclass data).
Note: Because the platform data for a U_BOOT_DEVICE() is defined with a
static pointer, it is not de-allocated during the remove() method. For
a device instantiated using the device tree data, the platform data will
be dynamically allocated, and thus needs to be deallocated during the
remove() method, either:
1. if the platdata_auto_alloc_size is non-zero, the deallocation
happens automatically within the driver model core; or
2. when platdata_auto_alloc_size is 0, both the allocation (in probe()
or preferably ofdata_to_platdata()) and the deallocation in remove()
are the responsibility of the driver author.
e. The device is marked inactive. Note that it is still bound, so the
device structure itself is not freed at this point. Should the device be
activated again, then the cycle starts again at step 2 above.
5. Unbind stage
The device is unbound. This is the step that actually destroys the device.
If a parent has children these will be destroyed first. After this point
the device does not exist and its memory has be deallocated.
Data Structures
---------------
@ -315,7 +521,7 @@ is little or no 'driver model' code to write.
- Moved some data from code into data structure - e.g. store a pointer to
the driver operations structure in the driver, rather than passing it
to the driver bind function.
- Rename some structures to make them more similar to Linux (struct device
- Rename some structures to make them more similar to Linux (struct udevice
instead of struct instance, struct platdata, etc.)
- Change the name 'core' to 'uclass', meaning U-Boot class. It seems that
this concept relates to a class of drivers (or a subsystem). We shouldn't

View file

@ -14,6 +14,7 @@
#include <dm/platdata.h>
#include <dm/uclass.h>
#include <dm/util.h>
#include <fdtdec.h>
#include <linux/compiler.h>
struct driver *lists_driver_lookup_name(const char *name)
@ -94,7 +95,7 @@ int lists_bind_drivers(struct udevice *parent)
* tree error
*/
static int driver_check_compatible(const void *blob, int offset,
const struct device_id *of_match)
const struct udevice_id *of_match)
{
int ret;

View file

@ -10,6 +10,7 @@
#include <common.h>
#include <errno.h>
#include <malloc.h>
#include <libfdt.h>
#include <dm/device.h>
#include <dm/device-internal.h>
#include <dm/lists.h>
@ -42,9 +43,9 @@ int dm_init(void)
dm_warn("Virtual root driver already exists!\n");
return -EINVAL;
}
INIT_LIST_HEAD(&gd->uclass_root);
INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST);
ret = device_bind_by_name(NULL, &root_info, &gd->dm_root);
ret = device_bind_by_name(NULL, &root_info, &DM_ROOT_NON_CONST);
if (ret)
return ret;
@ -55,7 +56,7 @@ int dm_scan_platdata(void)
{
int ret;
ret = lists_bind_drivers(gd->dm_root);
ret = lists_bind_drivers(DM_ROOT_NON_CONST);
if (ret == -ENOENT) {
dm_warn("Some drivers were not found\n");
ret = 0;

View file

@ -75,7 +75,7 @@ static int uclass_add(enum uclass_id id, struct uclass **ucp)
uc->uc_drv = uc_drv;
INIT_LIST_HEAD(&uc->sibling_node);
INIT_LIST_HEAD(&uc->dev_head);
list_add(&uc->sibling_node, &gd->uclass_root);
list_add(&uc->sibling_node, &DM_UCLASS_ROOT_NON_CONST);
if (uc_drv->init) {
ret = uc_drv->init(uc);

View file

@ -111,7 +111,7 @@ static int shape_ofdata_to_platdata(struct udevice *dev)
return 0;
}
static const struct device_id demo_shape_id[] = {
static const struct udevice_id demo_shape_id[] = {
{ "demo-shape", 0 },
{ },
};

View file

@ -32,7 +32,7 @@ static int demo_shape_ofdata_to_platdata(struct udevice *dev)
return demo_parse_dt(dev);
}
static const struct device_id demo_shape_id[] = {
static const struct udevice_id demo_shape_id[] = {
{ "demo-simple", 0 },
{ },
};

View file

@ -58,7 +58,7 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
uc_priv = dev->uclass_priv;
len = uc_priv->bank_name ? strlen(uc_priv->bank_name) : 0;
if (!strncmp(name, uc_priv->bank_name, len)) {
if (!strncasecmp(name, uc_priv->bank_name, len)) {
if (strict_strtoul(name + len, 10, &offset))
continue;
if (devp)

View file

@ -239,7 +239,7 @@ static int gpio_sandbox_probe(struct udevice *dev)
return 0;
}
static const struct device_id sandbox_gpio_ids[] = {
static const struct udevice_id sandbox_gpio_ids[] = {
{ .compatible = "sandbox,gpio" },
{ }
};

View file

@ -16,6 +16,9 @@
#endif
#define CONFIG_IO_TRACE
#define CONFIG_CMD_IOTRACE
#define CONFIG_SYS_TIMER_RATE 1000000
#define CONFIG_BOOTSTAGE

View file

@ -19,6 +19,9 @@
#include <asm/arch/tegra.h> /* get chip and board defs */
#define CONFIG_DM
#define CONFIG_CMD_DM
#define CONFIG_SYS_TIMER_RATE 1000000
#define CONFIG_SYS_TIMER_COUNTER NV_PA_TMRUS_BASE

View file

@ -84,4 +84,8 @@ int device_remove(struct udevice *dev);
*/
int device_unbind(struct udevice *dev);
/* Cast away any volatile pointer */
#define DM_ROOT_NON_CONST (((gd_t *)gd)->dm_root)
#define DM_UCLASS_ROOT_NON_CONST (((gd_t *)gd)->uclass_root)
#endif

View file

@ -21,7 +21,7 @@ struct driver_info;
#define DM_FLAG_ACTIVATED (1 << 0)
/* DM is responsible for allocating and freeing platdata */
#define DM_FLAG_ALLOC_PDATA (2 << 0)
#define DM_FLAG_ALLOC_PDATA (1 << 1)
/**
* struct udevice - An instance of a driver
@ -75,11 +75,11 @@ struct udevice {
#define device_active(dev) ((dev)->flags & DM_FLAG_ACTIVATED)
/**
* struct device_id - Lists the compatible strings supported by a driver
* struct udevice_id - Lists the compatible strings supported by a driver
* @compatible: Compatible string
* @data: Data for this compatible string
*/
struct device_id {
struct udevice_id {
const char *compatible;
ulong data;
};
@ -121,7 +121,7 @@ struct device_id {
struct driver {
char *name;
enum uclass_id id;
const struct device_id *of_match;
const struct udevice_id *of_match;
int (*bind)(struct udevice *dev);
int (*probe)(struct udevice *dev);
int (*remove)(struct udevice *dev);

View file

@ -32,8 +32,28 @@ struct driver *lists_driver_lookup_name(const char *name);
*/
struct uclass_driver *lists_uclass_lookup(enum uclass_id id);
/**
* lists_bind_drivers() - search for and bind all drivers to parent
*
* This searches the U_BOOT_DEVICE() structures and creates new devices for
* each one. The devices will have @parent as their parent.
*
* @parent: parent driver (root)
* @early_only: If true, bind only drivers with the DM_INIT_F flag. If false
* bind all drivers.
*/
int lists_bind_drivers(struct udevice *parent);
/**
* lists_bind_fdt() - bind a device tree node
*
* This creates a new device bound to the given device tree node, with
* @parent as its parent.
*
* @parent: parent driver (root)
* @blob: device tree blob
* @offset: offset of this device tree node
*/
int lists_bind_fdt(struct udevice *parent, const void *blob, int offset);
#endif

View file

@ -41,7 +41,7 @@ int dm_scan_platdata(void);
int dm_scan_fdt(const void *blob);
/**
* dm_init() - Initialize Driver Model structures
* dm_init() - Initialise Driver Model structures
*
* This function will initialize roots of driver tree and class tree.
* This needs to be called before anything uses the DM

View file

@ -26,7 +26,7 @@
* @priv: Private data for this uclass
* @uc_drv: The driver for the uclass itself, not to be confused with a
* 'struct driver'
* dev_head: List of devices in this uclass (devices are attached to their
* @dev_head: List of devices in this uclass (devices are attached to their
* uclass when their bind method is called)
* @sibling_node: Next uclass in the linked list of uclasses
*/
@ -96,12 +96,14 @@ int uclass_get(enum uclass_id key, struct uclass **ucp);
/**
* uclass_get_device() - Get a uclass device based on an ID and index
*
* The device is probed to activate it ready for use.
*
* id: ID to look up
* @index: Device number within that uclass (0=first)
* @ucp: Returns pointer to uclass (there is only one per for each ID)
* @devp: Returns pointer to device (there is only one per for each ID)
* @return 0 if OK, -ve on error
*/
int uclass_get_device(enum uclass_id id, int index, struct udevice **ucp);
int uclass_get_device(enum uclass_id id, int index, struct udevice **devp);
/**
* uclass_first_device() - Get the first device in a uclass
@ -129,7 +131,7 @@ int uclass_next_device(struct udevice **devp);
*
* @pos: struct udevice * to hold the current device. Set to NULL when there
* are no more devices.
* uc: uclass to scan
* @uc: uclass to scan
*/
#define uclass_foreach_dev(pos, uc) \
for (pos = list_entry((&(uc)->dev_head)->next, typeof(*pos), \

View file

@ -0,0 +1,15 @@
/*
* This header provides constants for most GPIO bindings.
*
* Most GPIO bindings include a flags cell as part of the GPIO specifier.
* In most cases, the format of the flags cell uses the standard values
* defined in this header.
*/
#ifndef _DT_BINDINGS_GPIO_GPIO_H
#define _DT_BINDINGS_GPIO_GPIO_H
#define GPIO_ACTIVE_HIGH 0
#define GPIO_ACTIVE_LOW 1
#endif

View file

@ -0,0 +1,51 @@
/*
* This header provides constants for binding nvidia,tegra*-gpio.
*
* The first cell in Tegra's GPIO specifier is the GPIO ID. The macros below
* provide names for this.
*
* The second cell contains standard flag values specified in gpio.h.
*/
#ifndef _DT_BINDINGS_GPIO_TEGRA_GPIO_H
#define _DT_BINDINGS_GPIO_TEGRA_GPIO_H
#include <dt-bindings/gpio/gpio.h>
#define TEGRA_GPIO_BANK_ID_A 0
#define TEGRA_GPIO_BANK_ID_B 1
#define TEGRA_GPIO_BANK_ID_C 2
#define TEGRA_GPIO_BANK_ID_D 3
#define TEGRA_GPIO_BANK_ID_E 4
#define TEGRA_GPIO_BANK_ID_F 5
#define TEGRA_GPIO_BANK_ID_G 6
#define TEGRA_GPIO_BANK_ID_H 7
#define TEGRA_GPIO_BANK_ID_I 8
#define TEGRA_GPIO_BANK_ID_J 9
#define TEGRA_GPIO_BANK_ID_K 10
#define TEGRA_GPIO_BANK_ID_L 11
#define TEGRA_GPIO_BANK_ID_M 12
#define TEGRA_GPIO_BANK_ID_N 13
#define TEGRA_GPIO_BANK_ID_O 14
#define TEGRA_GPIO_BANK_ID_P 15
#define TEGRA_GPIO_BANK_ID_Q 16
#define TEGRA_GPIO_BANK_ID_R 17
#define TEGRA_GPIO_BANK_ID_S 18
#define TEGRA_GPIO_BANK_ID_T 19
#define TEGRA_GPIO_BANK_ID_U 20
#define TEGRA_GPIO_BANK_ID_V 21
#define TEGRA_GPIO_BANK_ID_W 22
#define TEGRA_GPIO_BANK_ID_X 23
#define TEGRA_GPIO_BANK_ID_Y 24
#define TEGRA_GPIO_BANK_ID_Z 25
#define TEGRA_GPIO_BANK_ID_AA 26
#define TEGRA_GPIO_BANK_ID_BB 27
#define TEGRA_GPIO_BANK_ID_CC 28
#define TEGRA_GPIO_BANK_ID_DD 29
#define TEGRA_GPIO_BANK_ID_EE 30
#define TEGRA_GPIO_BANK_ID_FF 31
#define TEGRA_GPIO(bank, offset) \
((TEGRA_GPIO_BANK_ID_##bank * 8) + offset)
#endif

View file

@ -0,0 +1,22 @@
/*
* This header provides constants for the ARM GIC.
*/
#ifndef _DT_BINDINGS_INTERRUPT_CONTROLLER_ARM_GIC_H
#define _DT_BINDINGS_INTERRUPT_CONTROLLER_ARM_GIC_H
#include <dt-bindings/interrupt-controller/irq.h>
/* interrupt specific cell 0 */
#define GIC_SPI 0
#define GIC_PPI 1
/*
* Interrupt specifier cell 2.
* The flaggs in irq.h are valid, plus those below.
*/
#define GIC_CPU_MASK_RAW(x) ((x) << 8)
#define GIC_CPU_MASK_SIMPLE(num) GIC_CPU_MASK_RAW((1 << (num)) - 1)
#endif

View file

@ -0,0 +1,19 @@
/*
* This header provides constants for most IRQ bindings.
*
* Most IRQ bindings include a flags cell as part of the IRQ specifier.
* In most cases, the format of the flags cell uses the standard values
* defined in this header.
*/
#ifndef _DT_BINDINGS_INTERRUPT_CONTROLLER_IRQ_H
#define _DT_BINDINGS_INTERRUPT_CONTROLLER_IRQ_H
#define IRQ_TYPE_NONE 0
#define IRQ_TYPE_EDGE_RISING 1
#define IRQ_TYPE_EDGE_FALLING 2
#define IRQ_TYPE_EDGE_BOTH (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)
#define IRQ_TYPE_LEVEL_HIGH 4
#define IRQ_TYPE_LEVEL_LOW 8
#endif

104
include/iotrace.h Normal file
View file

@ -0,0 +1,104 @@
/*
* Copyright (c) 2014 Google, Inc.
*
* SPDX-License-Identifier: GPL-2.0+
*/
#ifndef __IOTRACE_H
#define __IOTRACE_H
#include <linux/types.h>
/*
* This file is designed to be included in arch/<arch>/include/asm/io.h.
* It redirects all IO access through a tracing/checksumming feature for
* testing purposes.
*/
#if defined(CONFIG_IO_TRACE) && !defined(IOTRACE_IMPL) && \
!defined(CONFIG_SPL_BUILD)
#undef readl
#define readl(addr) iotrace_readl((const void *)(addr))
#undef writel
#define writel(val, addr) iotrace_writel(val, (const void *)(addr))
#undef readw
#define readw(addr) iotrace_readw((const void *)(addr))
#undef writew
#define writew(val, addr) iotrace_writew(val, (const void *)(addr))
#undef readb
#define readb(addr) iotrace_readb((const void *)(addr))
#undef writeb
#define writeb(val, addr) iotrace_writeb(val, (const void *)(addr))
#endif
/* Tracing functions which mirror their io.h counterparts */
u32 iotrace_readl(const void *ptr);
void iotrace_writel(ulong value, const void *ptr);
u16 iotrace_readw(const void *ptr);
void iotrace_writew(ulong value, const void *ptr);
u8 iotrace_readb(const void *ptr);
void iotrace_writeb(ulong value, const void *ptr);
/**
* iotrace_reset_checksum() - Reset the iotrace checksum
*/
void iotrace_reset_checksum(void);
/**
* iotrace_get_checksum() - Get the current checksum value
*
* @return currect checksum value
*/
u32 iotrace_get_checksum(void);
/**
* iotrace_set_enabled() - Set whether iotracing is enabled or not
*
* This controls whether the checksum is updated and a trace record added
* for each I/O access.
*
* @enable: true to enable iotracing, false to disable
*/
void iotrace_set_enabled(int enable);
/**
* iotrace_get_enabled() - Get whether iotracing is enabled or not
*
* @return true if enabled, false if disabled
*/
int iotrace_get_enabled(void);
/**
* iotrace_set_buffer() - Set position and size of iotrace buffer
*
* Defines where the iotrace buffer goes, and resets the output pointer to
* the start of the buffer.
*
* The buffer can be 0 size in which case the checksum is updated but no
* trace records are writen. If the buffer is exhausted, the offset will
* continue to increase but not new data will be written.
*
* @start: Start address of buffer
* @size: Size of buffer in bytes
*/
void iotrace_set_buffer(ulong start, ulong size);
/**
* iotrace_get_buffer() - Get buffer information
*
* @start: Returns start address of buffer
* @size: Returns size of buffer in bytes
* @offset: Returns the byte offset where the next output trace record will
* @count: Returns the number of trace records recorded
* be written (or would be if the buffer was large enough)
*/
void iotrace_get_buffer(ulong *start, ulong *size, ulong *offset, ulong *count);
#endif /* __IOTRACE_H */

View file

@ -153,6 +153,7 @@ ld_flags = $(LDFLAGS) $(ldflags-y)
# Modified for U-Boot
dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \
-I$(srctree)/arch/$(ARCH)/dts \
-I$(srctree)/arch/$(ARCH)/dts/include \
-undef -D__DTS__
# Finds the multi-part object the current object will be linked into

View file

@ -15,4 +15,6 @@ obj-$(CONFIG_DM_TEST) += ut.o
# subsystem you must add sandbox tests here.
obj-$(CONFIG_DM_TEST) += core.o
obj-$(CONFIG_DM_TEST) += ut.o
ifneq ($(CONFIG_SANDBOX),)
obj-$(CONFIG_DM_GPIO) += gpio.o
endif

View file

@ -23,7 +23,7 @@ static int display_succ(struct udevice *in, char *buf)
char local[16];
struct udevice *pos, *n, *prev = NULL;
printf("%s- %s @ %08x", buf, in->name, map_to_sysmem(in));
printf("%s- %s @ %08lx", buf, in->name, (ulong)map_to_sysmem(in));
if (in->flags & DM_FLAG_ACTIVATED)
puts(" - activated");
puts("\n");
@ -62,7 +62,7 @@ static int do_dm_dump_all(cmd_tbl_t *cmdtp, int flag, int argc,
struct udevice *root;
root = dm_root();
printf("ROOT %08x\n", map_to_sysmem(root));
printf("ROOT %08lx\n", (ulong)map_to_sysmem(root));
return dm_dump(root);
}
@ -84,8 +84,8 @@ static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
for (ret = uclass_first_device(id, &dev);
dev;
ret = uclass_next_device(&dev)) {
printf(" %s @ %08x:\n", dev->name,
map_to_sysmem(dev));
printf(" %s @ %08lx:\n", dev->name,
(ulong)map_to_sysmem(dev));
}
puts("\n");
}
@ -93,16 +93,23 @@ static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
return 0;
}
#ifdef CONFIG_DM_TEST
static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
return dm_test_main();
}
#define TEST_HELP "\ndm test Run tests"
#else
#define TEST_HELP
#endif
static cmd_tbl_t test_commands[] = {
U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
#ifdef CONFIG_DM_TEST
U_BOOT_CMD_MKENT(test, 1, 1, do_dm_test, "", ""),
#endif
};
static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
@ -128,6 +135,6 @@ U_BOOT_CMD(
dm, 2, 1, do_dm,
"Driver model low level access",
"tree Dump driver model tree\n"
"dm uclass Dump list of instances for each uclass\n"
"dm test Run tests"
"dm uclass Dump list of instances for each uclass"
TEST_HELP
);

View file

@ -53,7 +53,7 @@ static int testfdt_drv_probe(struct udevice *dev)
return 0;
}
static const struct device_id testfdt_ids[] = {
static const struct udevice_id testfdt_ids[] = {
{
.compatible = "denx,u-boot-fdt-test",
.data = DM_TEST_TYPE_FIRST },