fdtbus: Add ability to send/receive messages on parent busses.

This commit is contained in:
Vladimir Serbinenko 2017-05-09 08:40:29 +02:00
parent 4f8471532d
commit c4313c812d
2 changed files with 34 additions and 19 deletions

View file

@ -25,30 +25,22 @@ static grub_size_t root_address_cells, root_size_cells;
/* Pointer to this symbol signals invalid mapping. */
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_driver *drivers;
static int
is_compatible (struct grub_fdtbus_driver *driver,
int node)
int
grub_fdtbus_is_compatible (const char *compat_string,
const struct grub_fdtbus_dev *dev)
{
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);
if (!compatible)
return 0;
const char *compatible_end = compatible + compatible_size;
while (compatible < compatible_end)
{
if (grub_strcmp (driver->compatible, compatible) == 0)
if (grub_strcmp (compat_string, compatible) == 0)
return 1;
compatible += grub_strlen (compatible) + 1;
}
@ -75,10 +67,12 @@ fdtbus_scan (struct grub_fdtbus_dev *parent)
dev->parent = parent;
devs = dev;
FOR_LIST_ELEMENTS(driver, drivers)
if (!dev->driver && is_compatible (driver, node))
if (!dev->driver && grub_fdtbus_is_compatible (driver->compatible, dev))
{
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;
break;
}
@ -92,13 +86,18 @@ void
grub_fdtbus_register (struct grub_fdtbus_driver *driver)
{
struct grub_fdtbus_dev *dev;
grub_dprintf ("fdtbus", "Registering %s\n", driver->compatible);
grub_list_push (GRUB_AS_LIST_P (&drivers),
GRUB_AS_LIST (driver));
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))
{
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;
}
grub_print_error ();
}
}

View file

@ -22,7 +22,13 @@
#include <grub/fdt.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
{
@ -33,6 +39,12 @@ struct grub_fdtbus_driver
grub_err_t (*attach) (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];
@ -63,6 +75,10 @@ EXPORT_FUNC(grub_fdtbus_register) (struct grub_fdtbus_driver *driver);
void
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(). */
/* dtb is assumed to be unfreeable and must remain
valid for lifetime of GRUB.