fdtbus: Add ability to send/receive messages on parent busses.
This commit is contained in:
parent
4f8471532d
commit
c4313c812d
2 changed files with 34 additions and 19 deletions
|
@ -25,30 +25,22 @@ static grub_size_t root_address_cells, root_size_cells;
|
||||||
/* Pointer to this symbol signals invalid mapping. */
|
/* Pointer to this symbol signals invalid mapping. */
|
||||||
char grub_fdtbus_invalid_mapping[1];
|
char grub_fdtbus_invalid_mapping[1];
|
||||||
|
|
||||||
struct grub_fdtbus_dev
|
|
||||||
{
|
|
||||||
struct grub_fdtbus_dev *next;
|
|
||||||
struct grub_fdtbus_dev *parent;
|
|
||||||
int node;
|
|
||||||
struct grub_fdtbus_driver *driver;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct grub_fdtbus_dev *devs;
|
struct grub_fdtbus_dev *devs;
|
||||||
struct grub_fdtbus_driver *drivers;
|
struct grub_fdtbus_driver *drivers;
|
||||||
|
|
||||||
static int
|
int
|
||||||
is_compatible (struct grub_fdtbus_driver *driver,
|
grub_fdtbus_is_compatible (const char *compat_string,
|
||||||
int node)
|
const struct grub_fdtbus_dev *dev)
|
||||||
{
|
{
|
||||||
grub_size_t compatible_size;
|
grub_size_t compatible_size;
|
||||||
const char *compatible = grub_fdt_get_prop (dtb, node, "compatible",
|
const char *compatible = grub_fdt_get_prop (dtb, dev->node, "compatible",
|
||||||
&compatible_size);
|
&compatible_size);
|
||||||
if (!compatible)
|
if (!compatible)
|
||||||
return 0;
|
return 0;
|
||||||
const char *compatible_end = compatible + compatible_size;
|
const char *compatible_end = compatible + compatible_size;
|
||||||
while (compatible < compatible_end)
|
while (compatible < compatible_end)
|
||||||
{
|
{
|
||||||
if (grub_strcmp (driver->compatible, compatible) == 0)
|
if (grub_strcmp (compat_string, compatible) == 0)
|
||||||
return 1;
|
return 1;
|
||||||
compatible += grub_strlen (compatible) + 1;
|
compatible += grub_strlen (compatible) + 1;
|
||||||
}
|
}
|
||||||
|
@ -75,10 +67,12 @@ fdtbus_scan (struct grub_fdtbus_dev *parent)
|
||||||
dev->parent = parent;
|
dev->parent = parent;
|
||||||
devs = dev;
|
devs = dev;
|
||||||
FOR_LIST_ELEMENTS(driver, drivers)
|
FOR_LIST_ELEMENTS(driver, drivers)
|
||||||
if (!dev->driver && is_compatible (driver, node))
|
if (!dev->driver && grub_fdtbus_is_compatible (driver->compatible, dev))
|
||||||
{
|
{
|
||||||
if (driver->attach(dev) == GRUB_ERR_NONE)
|
grub_dprintf ("fdtbus", "Attaching %s\n", driver->compatible);
|
||||||
|
if (driver->attach (dev) == GRUB_ERR_NONE)
|
||||||
{
|
{
|
||||||
|
grub_dprintf ("fdtbus", "Attached %s\n", driver->compatible);
|
||||||
dev->driver = driver;
|
dev->driver = driver;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -92,13 +86,18 @@ void
|
||||||
grub_fdtbus_register (struct grub_fdtbus_driver *driver)
|
grub_fdtbus_register (struct grub_fdtbus_driver *driver)
|
||||||
{
|
{
|
||||||
struct grub_fdtbus_dev *dev;
|
struct grub_fdtbus_dev *dev;
|
||||||
|
grub_dprintf ("fdtbus", "Registering %s\n", driver->compatible);
|
||||||
grub_list_push (GRUB_AS_LIST_P (&drivers),
|
grub_list_push (GRUB_AS_LIST_P (&drivers),
|
||||||
GRUB_AS_LIST (driver));
|
GRUB_AS_LIST (driver));
|
||||||
for (dev = devs; dev; dev = dev->next)
|
for (dev = devs; dev; dev = dev->next)
|
||||||
if (!dev->driver && is_compatible (driver, dev->node))
|
if (!dev->driver && grub_fdtbus_is_compatible (driver->compatible, dev))
|
||||||
{
|
{
|
||||||
if (driver->attach(dev) == GRUB_ERR_NONE)
|
grub_dprintf ("fdtbus", "Attaching %s (%p)\n", driver->compatible, dev);
|
||||||
|
if (driver->attach (dev) == GRUB_ERR_NONE)
|
||||||
|
{
|
||||||
|
grub_dprintf ("fdtbus", "Attached %s\n", driver->compatible);
|
||||||
dev->driver = driver;
|
dev->driver = driver;
|
||||||
|
}
|
||||||
grub_print_error ();
|
grub_print_error ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,13 @@
|
||||||
#include <grub/fdt.h>
|
#include <grub/fdt.h>
|
||||||
#include <grub/err.h>
|
#include <grub/err.h>
|
||||||
|
|
||||||
struct grub_fdtbus_dev;
|
struct grub_fdtbus_dev
|
||||||
|
{
|
||||||
|
struct grub_fdtbus_dev *next;
|
||||||
|
struct grub_fdtbus_dev *parent;
|
||||||
|
int node;
|
||||||
|
struct grub_fdtbus_driver *driver;
|
||||||
|
};
|
||||||
|
|
||||||
struct grub_fdtbus_driver
|
struct grub_fdtbus_driver
|
||||||
{
|
{
|
||||||
|
@ -33,6 +39,12 @@ struct grub_fdtbus_driver
|
||||||
|
|
||||||
grub_err_t (*attach) (const struct grub_fdtbus_dev *dev);
|
grub_err_t (*attach) (const struct grub_fdtbus_dev *dev);
|
||||||
void (*detach) (const struct grub_fdtbus_dev *dev);
|
void (*detach) (const struct grub_fdtbus_dev *dev);
|
||||||
|
|
||||||
|
/* Message bus operations. */
|
||||||
|
grub_err_t (*send) (const struct grub_fdtbus_dev *dev, const void *data, grub_size_t sz);
|
||||||
|
grub_err_t (*receive) (const struct grub_fdtbus_dev *dev, void *data, grub_size_t sz);
|
||||||
|
grub_err_t (*start) (const struct grub_fdtbus_dev *dev);
|
||||||
|
void (*stop) (const struct grub_fdtbus_dev *dev);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern char EXPORT_VAR(grub_fdtbus_invalid_mapping)[1];
|
extern char EXPORT_VAR(grub_fdtbus_invalid_mapping)[1];
|
||||||
|
@ -63,6 +75,10 @@ EXPORT_FUNC(grub_fdtbus_register) (struct grub_fdtbus_driver *driver);
|
||||||
void
|
void
|
||||||
EXPORT_FUNC(grub_fdtbus_unregister) (struct grub_fdtbus_driver *driver);
|
EXPORT_FUNC(grub_fdtbus_unregister) (struct grub_fdtbus_driver *driver);
|
||||||
|
|
||||||
|
int
|
||||||
|
EXPORT_FUNC(grub_fdtbus_is_compatible) (const char *compat_string,
|
||||||
|
const struct grub_fdtbus_dev *dev);
|
||||||
|
|
||||||
/* Must be called before any register(). */
|
/* Must be called before any register(). */
|
||||||
/* dtb is assumed to be unfreeable and must remain
|
/* dtb is assumed to be unfreeable and must remain
|
||||||
valid for lifetime of GRUB.
|
valid for lifetime of GRUB.
|
||||||
|
|
Loading…
Reference in a new issue