Move to more hookless approach in IEEE1275 devices handling.

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-03-02 23:51:19 +01:00
parent 99fcda8a7b
commit 6e4146c41e
9 changed files with 390 additions and 353 deletions

View file

@ -1,3 +1,7 @@
2013-03-02 Vladimir Serbinenko <phcoder@gmail.com>
Move to more hookless approach in IEEE1275 devices handling.
2013-03-02 Vladimir Serbinenko <phcoder@gmail.com> 2013-03-02 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/kern/term.c (grub_term_normal_color), * grub-core/kern/term.c (grub_term_normal_color),

View file

@ -36,22 +36,29 @@ static int
grub_nand_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data, grub_nand_iterate (grub_disk_dev_iterate_hook_t hook, void *hook_data,
grub_disk_pull_t pull) grub_disk_pull_t pull)
{ {
auto int dev_iterate (struct grub_ieee1275_devalias *alias); static int have_nand = -1;
int dev_iterate (struct grub_ieee1275_devalias *alias)
{
if (grub_strcmp (alias->name, "nand") == 0)
{
hook (alias->name, hook_data);
return 1;
}
return 0;
}
if (pull != GRUB_DISK_PULL_NONE) if (pull != GRUB_DISK_PULL_NONE)
return 0; return 0;
return grub_devalias_iterate (dev_iterate); if (have_nand == -1)
{
struct grub_ieee1275_devalias alias;
have_nand = 0;
FOR_IEEE1275_DEVALIASES(alias)
if (grub_strcmp (alias->name, "nand") == 0)
{
have_nand = 1;
break;
}
grub_ieee1275_devalias_free (&alias);
}
if (have_nand)
return hook ("nand", hook_data);
return 0;
} }
static grub_err_t static grub_err_t

View file

@ -114,107 +114,113 @@ ofdisk_hash_add (char *devpath, char *curcan)
} }
static void static void
scan (void) dev_iterate_real (const char *name, const char *path)
{ {
auto int dev_iterate_real (const char *name, const char *path); struct ofdisk_hash_ent *op;
int dev_iterate_real (const char *name, const char *path) grub_dprintf ("disk", "disk name = %s, path = %s\n", name,
path);
op = ofdisk_hash_find (path);
if (!op)
{ {
struct ofdisk_hash_ent *op; char *name_dup = grub_strdup (name);
char *can = grub_strdup (path);
grub_dprintf ("disk", "disk name = %s, path = %s\n", name, if (!name_dup || !can)
path);
op = ofdisk_hash_find (path);
if (!op)
{ {
char *name_dup = grub_strdup (name); grub_errno = GRUB_ERR_NONE;
char *can = grub_strdup (path); grub_free (name_dup);
if (!name_dup || !can) grub_free (can);
{ return;
grub_errno = GRUB_ERR_NONE;
grub_free (name_dup);
grub_free (can);
return 0;
}
op = ofdisk_hash_add (name_dup, can);
} }
return 0; op = ofdisk_hash_add (name_dup, can);
}
return;
}
static void
dev_iterate (const struct grub_ieee1275_devalias *alias)
{
if (grub_strcmp (alias->type, "vscsi") == 0)
{
static grub_ieee1275_ihandle_t ihandle;
struct set_color_args
{
struct grub_ieee1275_common_hdr common;
grub_ieee1275_cell_t method;
grub_ieee1275_cell_t ihandle;
grub_ieee1275_cell_t catch_result;
grub_ieee1275_cell_t nentries;
grub_ieee1275_cell_t table;
}
args;
char *buf, *bufptr;
unsigned i;
if (grub_ieee1275_open (alias->path, &ihandle))
return;
INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3);
args.method = (grub_ieee1275_cell_t) "vscsi-report-luns";
args.ihandle = ihandle;
args.table = 0;
args.nentries = 0;
if (IEEE1275_CALL_ENTRY_FN (&args) == -1 || args.catch_result)
{
grub_ieee1275_close (ihandle);
return;
}
buf = grub_malloc (grub_strlen (alias->path) + 32);
if (!buf)
return;
bufptr = grub_stpcpy (buf, alias->path);
for (i = 0; i < args.nentries; i++)
{
grub_uint64_t *ptr;
ptr = *(grub_uint64_t **) (args.table + 4 + 8 * i);
while (*ptr)
{
grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr++);
dev_iterate_real (buf, buf);
}
}
grub_ieee1275_close (ihandle);
grub_free (buf);
return;
}
if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
&& grub_strcmp (alias->type, "block") == 0)
{
dev_iterate_real (alias->path, alias->path);
return;
} }
auto int dev_iterate_alias (struct grub_ieee1275_devalias *alias);
int dev_iterate_alias (struct grub_ieee1275_devalias *alias)
{ {
if (grub_strcmp (alias->type, "block") != 0) struct grub_ieee1275_devalias child;
return 0;
return dev_iterate_real (alias->name, alias->path); FOR_IEEE1275_DEVCHILDREN(alias->path, child)
dev_iterate (&child);
} }
}
auto int dev_iterate (struct grub_ieee1275_devalias *alias); static void
int dev_iterate (struct grub_ieee1275_devalias *alias) scan (void)
{ {
if (grub_strcmp (alias->type, "vscsi") == 0) struct grub_ieee1275_devalias alias;
{ FOR_IEEE1275_DEVALIASES(alias)
static grub_ieee1275_ihandle_t ihandle; {
struct set_color_args if (grub_strcmp (alias.type, "block") != 0)
{ continue;
struct grub_ieee1275_common_hdr common; dev_iterate_real (alias.name, alias.path);
grub_ieee1275_cell_t method; }
grub_ieee1275_cell_t ihandle;
grub_ieee1275_cell_t catch_result;
grub_ieee1275_cell_t nentries;
grub_ieee1275_cell_t table;
}
args;
char *buf, *bufptr;
unsigned i;
if (grub_ieee1275_open (alias->path, &ihandle)) FOR_IEEE1275_DEVCHILDREN("/", alias)
return 0; dev_iterate (&alias);
INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3);
args.method = (grub_ieee1275_cell_t) "vscsi-report-luns";
args.ihandle = ihandle;
args.table = 0;
args.nentries = 0;
if (IEEE1275_CALL_ENTRY_FN (&args) == -1 || args.catch_result)
{
grub_ieee1275_close (ihandle);
return 0;
}
buf = grub_malloc (grub_strlen (alias->path) + 32);
if (!buf)
return 0;
bufptr = grub_stpcpy (buf, alias->path);
for (i = 0; i < args.nentries; i++)
{
grub_uint64_t *ptr;
ptr = *(grub_uint64_t **) (args.table + 4 + 8 * i);
while (*ptr)
{
grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr++);
if (dev_iterate_real (buf, buf))
return 1;
}
}
grub_ieee1275_close (ihandle);
grub_free (buf);
return 0;
}
if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
&& grub_strcmp (alias->type, "block") == 0)
return dev_iterate_real (alias->path, alias->path);
return grub_children_iterate (alias->path, dev_iterate);
}
grub_devalias_iterate (dev_iterate_alias);
grub_children_iterate ("/", dev_iterate);
} }
static int static int

View file

@ -32,184 +32,227 @@ enum grub_ieee1275_parse_type
GRUB_PARSE_DEVICE_TYPE GRUB_PARSE_DEVICE_TYPE
}; };
/* Walk children of 'devpath', calling hook for each. */ static int
int fill_alias (struct grub_ieee1275_devalias *alias)
grub_children_iterate (const char *devpath, {
int (*hook) (struct grub_ieee1275_devalias *alias)) grub_ssize_t actual;
if (grub_ieee1275_get_property (alias->phandle, "device_type", alias->type,
IEEE1275_MAX_PROP_LEN, &actual))
alias->type[0] = 0;
if (alias->parent_dev == alias->phandle)
return 0;
if (grub_ieee1275_package_to_path (alias->phandle, alias->path,
IEEE1275_MAX_PATH_LEN, &actual))
return 0;
if (grub_strcmp (alias->parent_path, alias->path) == 0)
return 0;
if (grub_ieee1275_get_property (alias->phandle, "name", alias->name,
IEEE1275_MAX_PROP_LEN, &actual))
return 0;
grub_dprintf ("devalias", "device path=%s\n", alias->path);
return 1;
}
void
grub_ieee1275_devalias_free (struct grub_ieee1275_devalias *alias)
{
grub_free (alias->name);
grub_free (alias->type);
grub_free (alias->path);
grub_free (alias->parent_path);
alias->name = 0;
alias->type = 0;
alias->path = 0;
alias->parent_path = 0;
alias->phandle = GRUB_IEEE1275_PHANDLE_INVALID;
}
void
grub_ieee1275_children_peer (struct grub_ieee1275_devalias *alias)
{
while (grub_ieee1275_peer (alias->phandle, &alias->phandle) != -1)
if (fill_alias (alias))
return;
grub_ieee1275_devalias_free (alias);
}
void
grub_ieee1275_children_first (const char *devpath,
struct grub_ieee1275_devalias *alias)
{ {
grub_ieee1275_phandle_t dev; grub_ieee1275_phandle_t dev;
grub_ieee1275_phandle_t child;
char *childtype, *childpath; grub_dprintf ("devalias", "iterating children of %s\n",
char *childname; devpath);
int ret = 0;
alias->name = 0;
alias->path = 0;
alias->parent_path = 0;
alias->type = 0;
if (grub_ieee1275_finddevice (devpath, &dev)) if (grub_ieee1275_finddevice (devpath, &dev))
return 0; return;
if (grub_ieee1275_child (dev, &child)) if (grub_ieee1275_child (dev, &alias->phandle))
return 0; return;
childtype = grub_malloc (IEEE1275_MAX_PROP_LEN); alias->type = grub_malloc (IEEE1275_MAX_PROP_LEN);
if (!childtype) if (!alias->type)
return 0; return;
childpath = grub_malloc (IEEE1275_MAX_PATH_LEN); alias->path = grub_malloc (IEEE1275_MAX_PATH_LEN);
if (!childpath) if (!alias->path)
{ {
grub_free (childtype); grub_free (alias->type);
return 0; return;
} }
childname = grub_malloc (IEEE1275_MAX_PROP_LEN); alias->parent_path = grub_strdup (devpath);
if (!childname) if (!alias->parent_path)
{ {
grub_free (childpath); grub_free (alias->path);
grub_free (childtype); grub_free (alias->type);
return 0; return;
} }
do alias->name = grub_malloc (IEEE1275_MAX_PROP_LEN);
if (!alias->name)
{ {
struct grub_ieee1275_devalias alias; grub_free (alias->path);
grub_ssize_t actual; grub_free (alias->type);
grub_free (alias->parent_path);
return;
}
if (!fill_alias (alias))
grub_ieee1275_children_peer (alias);
}
if (grub_ieee1275_get_property (child, "device_type", childtype, static int
IEEE1275_MAX_PROP_LEN, &actual)) iterate_recursively (const char *path,
childtype[0] = 0; int (*hook) (struct grub_ieee1275_devalias *alias))
{
struct grub_ieee1275_devalias alias;
int ret = 0;
if (dev == child) FOR_IEEE1275_DEVCHILDREN(path, alias)
continue; {
if (grub_ieee1275_package_to_path (child, childpath,
IEEE1275_MAX_PATH_LEN, &actual))
continue;
if (grub_strcmp (devpath, childpath) == 0)
continue;
if (grub_ieee1275_get_property (child, "name", childname,
IEEE1275_MAX_PROP_LEN, &actual))
continue;
alias.type = childtype;
alias.path = childpath;
alias.name = childname;
ret = hook (&alias); ret = hook (&alias);
if (ret) if (ret)
break; break;
ret = iterate_recursively (alias.path, hook);
if (ret)
break;
} }
while (grub_ieee1275_peer (child, &child) != -1); grub_ieee1275_devalias_free (&alias);
grub_free (childname);
grub_free (childpath);
grub_free (childtype);
return ret; return ret;
} }
int int
grub_ieee1275_devices_iterate (int (*hook) (struct grub_ieee1275_devalias *alias)) grub_ieee1275_devices_iterate (int (*hook) (struct grub_ieee1275_devalias *alias))
{ {
auto int it_through (struct grub_ieee1275_devalias *alias); return iterate_recursively ("/", hook);
int it_through (struct grub_ieee1275_devalias *alias)
{
if (hook (alias))
return 1;
return grub_children_iterate (alias->path, it_through);
}
return grub_children_iterate ("/", it_through);
} }
/* Iterate through all device aliases. This function can be used to void
find a device of a specific type. */ grub_ieee1275_devalias_init_iterator (struct grub_ieee1275_devalias *alias)
int
grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias))
{ {
grub_ieee1275_phandle_t aliases; alias->name = 0;
char *aliasname, *devtype; alias->path = 0;
grub_ssize_t actual; alias->parent_path = 0;
struct grub_ieee1275_devalias alias; alias->type = 0;
int ret = 0;
if (grub_ieee1275_finddevice ("/aliases", &aliases)) grub_dprintf ("devalias", "iterating aliases\n");
return 0;
aliasname = grub_malloc (IEEE1275_MAX_PROP_LEN); if (grub_ieee1275_finddevice ("/aliases", &alias->parent_dev))
if (!aliasname) return;
return 0;
devtype = grub_malloc (IEEE1275_MAX_PROP_LEN); alias->name = grub_malloc (IEEE1275_MAX_PROP_LEN);
if (!devtype) if (!alias->name)
return;
alias->type = grub_malloc (IEEE1275_MAX_PROP_LEN);
if (!alias->type)
{ {
grub_free (aliasname); grub_free (alias->name);
return 0; alias->name = 0;
return;
} }
/* Find the first property. */ alias->name[0] = '\0';
aliasname[0] = '\0'; }
while (grub_ieee1275_next_property (aliases, aliasname, aliasname) > 0) int
grub_ieee1275_devalias_next (struct grub_ieee1275_devalias *alias)
{
if (!alias->name)
return 0;
while (1)
{ {
grub_ieee1275_phandle_t dev;
grub_ssize_t pathlen; grub_ssize_t pathlen;
char *devpath; grub_ssize_t actual;
grub_dprintf ("devalias", "devalias name = %s\n", aliasname); if (alias->path)
{
grub_free (alias->path);
alias->path = 0;
}
if (grub_ieee1275_next_property (alias->parent_dev, alias->name,
alias->name) <= 0)
{
grub_ieee1275_devalias_free (alias);
return 0;
}
grub_ieee1275_get_property_length (aliases, aliasname, &pathlen); grub_dprintf ("devalias", "devalias name = %s\n", alias->name);
grub_ieee1275_get_property_length (alias->parent_dev, alias->name, &pathlen);
/* The property `name' is a special case we should skip. */ /* The property `name' is a special case we should skip. */
if (!grub_strcmp (aliasname, "name")) if (grub_strcmp (alias->name, "name") == 0)
continue; continue;
/* Sun's OpenBoot often doesn't zero terminate the device alias /* Sun's OpenBoot often doesn't zero terminate the device alias
strings, so we will add a NULL byte at the end explicitly. */ strings, so we will add a NULL byte at the end explicitly. */
pathlen += 1; pathlen += 1;
devpath = grub_malloc (pathlen + 1); alias->path = grub_malloc (pathlen + 1);
if (! devpath) if (! alias->path)
{ {
grub_free (devtype); grub_ieee1275_devalias_free (alias);
grub_free (aliasname);
return 0; return 0;
} }
if (grub_ieee1275_get_property (aliases, aliasname, devpath, pathlen, if (grub_ieee1275_get_property (alias->parent_dev, alias->name, alias->path,
&actual) || actual < 0) pathlen, &actual) || actual < 0)
{ {
grub_dprintf ("devalias", "get_property (%s) failed\n", aliasname); grub_dprintf ("devalias", "get_property (%s) failed\n", alias->name);
goto nextprop; grub_free (alias->path);
continue;
} }
if (actual > pathlen) if (actual > pathlen)
actual = pathlen; actual = pathlen;
devpath[actual] = '\0'; alias->path[actual] = '\0';
devpath[pathlen] = '\0'; alias->path[pathlen] = '\0';
if (grub_ieee1275_finddevice (devpath, &dev)) if (grub_ieee1275_finddevice (alias->path, &alias->phandle))
{ {
grub_dprintf ("devalias", "finddevice (%s) failed\n", devpath); grub_dprintf ("devalias", "finddevice (%s) failed\n", alias->path);
goto nextprop; grub_free (alias->path);
alias->path = 0;
continue;
} }
if (grub_ieee1275_get_property (dev, "device_type", devtype, if (grub_ieee1275_get_property (alias->phandle, "device_type", alias->type,
IEEE1275_MAX_PROP_LEN, &actual)) IEEE1275_MAX_PROP_LEN, &actual))
{ {
/* NAND device don't have device_type property. */ /* NAND device don't have device_type property. */
devtype[0] = 0; alias->type[0] = 0;
} }
return 1;
alias.name = aliasname;
alias.path = devpath;
alias.type = devtype;
ret = hook (&alias);
nextprop:
grub_free (devpath);
if (ret)
break;
} }
grub_free (devtype);
grub_free (aliasname);
return ret;
} }
/* Call the "map" method of /chosen/mmu. */ /* Call the "map" method of /chosen/mmu. */
@ -286,37 +329,28 @@ grub_ieee1275_get_devargs (const char *path)
} }
/* Get the device path of the Open Firmware node name `path'. */ /* Get the device path of the Open Firmware node name `path'. */
static char * char *
grub_ieee1275_get_devname (const char *path) grub_ieee1275_get_devname (const char *path)
{ {
char *colon = grub_strchr (path, ':'); char *colon = grub_strchr (path, ':');
char *newpath = 0;
int pathlen = grub_strlen (path); int pathlen = grub_strlen (path);
auto int match_alias (struct grub_ieee1275_devalias *alias); struct grub_ieee1275_devalias curalias;
int match_alias (struct grub_ieee1275_devalias *curalias)
{
/* briQ firmware can change capitalization in /chosen/bootpath. */
if (grub_strncasecmp (curalias->path, path, pathlen) == 0
&& curalias->path[pathlen] == 0)
{
newpath = grub_strdup (curalias->name);
return 1;
}
return 0;
}
if (colon) if (colon)
pathlen = (int)(colon - path); pathlen = (int)(colon - path);
/* Try to find an alias for this device. */ /* Try to find an alias for this device. */
grub_devalias_iterate (match_alias); FOR_IEEE1275_DEVALIASES (curalias)
/* briQ firmware can change capitalization in /chosen/bootpath. */
if (grub_strncasecmp (curalias.path, path, pathlen) == 0
&& curalias.path[pathlen] == 0)
{
char *newpath;
newpath = grub_strdup (curalias.name);
grub_ieee1275_devalias_free (&curalias);
return newpath;
}
if (! newpath) return grub_strndup (path, pathlen);
newpath = grub_strndup (path, pathlen);
return newpath;
} }
static char * static char *

View file

@ -198,27 +198,6 @@ grub_ieee1275_net_config_real (const char *devpath, char **device, char **path)
} }
} }
static char *
find_alias (const char *fullname)
{
char *ret = NULL;
auto int find_alias_hook (struct grub_ieee1275_devalias *alias);
int find_alias_hook (struct grub_ieee1275_devalias *alias)
{
if (grub_strcmp (alias->path, fullname) == 0)
{
ret = grub_strdup (alias->name);
return 1;
}
return 0;
}
grub_devalias_iterate (find_alias_hook);
grub_errno = GRUB_ERR_NONE;
return ret;
}
static int static int
search_net_devices (struct grub_ieee1275_devalias *alias) search_net_devices (struct grub_ieee1275_devalias *alias)
{ {
@ -308,7 +287,7 @@ search_net_devices (struct grub_ieee1275_devalias *alias)
card->driver = NULL; card->driver = NULL;
card->data = ofdata; card->data = ofdata;
card->flags = 0; card->flags = 0;
shortname = find_alias (alias->path); shortname = grub_ieee1275_get_devname (alias->path);
card->name = grub_xasprintf ("ofnet_%s", shortname ? : alias->path); card->name = grub_xasprintf ("ofnet_%s", shortname ? : alias->path);
card->idle_poll_delay_ms = 10; card->idle_poll_delay_ms = 10;
grub_free (shortname); grub_free (shortname);

View file

@ -200,6 +200,7 @@ struct grub_serial_driver grub_escc_driver =
}; };
static struct grub_escc_descriptor escc_descs[2]; static struct grub_escc_descriptor escc_descs[2];
static char *macio = 0;
static void static void
add_device (grub_addr_t addr, int channel) add_device (grub_addr_t addr, int channel)
@ -243,38 +244,34 @@ add_device (grub_addr_t addr, int channel)
grub_serial_register (port); grub_serial_register (port);
} }
static int
find_macio (struct grub_ieee1275_devalias *alias)
{
if (grub_strcmp (alias->type, "mac-io") != 0)
return 0;
macio = grub_strdup (alias->path);
return 1;
}
GRUB_MOD_INIT (escc) GRUB_MOD_INIT (escc)
{ {
char *macio = 0;
char *escc = 0;
grub_uint32_t macio_addr[4]; grub_uint32_t macio_addr[4];
grub_uint32_t escc_addr[2]; grub_uint32_t escc_addr[2];
grub_ieee1275_phandle_t dev; grub_ieee1275_phandle_t dev;
struct grub_ieee1275_devalias alias;
auto int find_macio (struct grub_ieee1275_devalias *alias); char *escc = 0;
auto int find_escc (struct grub_ieee1275_devalias *alias);
int find_macio (struct grub_ieee1275_devalias *alias)
{
if (grub_strcmp (alias->type, "mac-io") != 0)
return 0;
macio = grub_strdup (alias->path);
return 1;
}
int find_escc (struct grub_ieee1275_devalias *alias)
{
if (grub_strcmp (alias->type, "escc") != 0)
return 0;
escc = grub_strdup (alias->path);
return 1;
}
grub_ieee1275_devices_iterate (find_macio); grub_ieee1275_devices_iterate (find_macio);
if (!macio) if (!macio)
return; return;
grub_children_iterate (macio, find_escc); FOR_IEEE1275_DEVCHILDREN(macio, alias)
if (grub_strcmp (alias.type, "escc") == 0)
{
escc = grub_strdup (alias.path);
break;
}
grub_ieee1275_devalias_free (&alias);
if (!escc) if (!escc)
{ {
grub_free (macio); grub_free (macio);

View file

@ -180,58 +180,53 @@ ofserial_hash_add (char *devpath, char *curcan)
return p; return p;
} }
static void
dev_iterate_real (struct grub_ieee1275_devalias *alias,
int use_name)
{
struct ofserial_hash_ent *op;
if (grub_strcmp (alias->type, "serial") != 0)
return;
grub_dprintf ("serial", "serial name = %s, path = %s\n", alias->name,
alias->path);
op = ofserial_hash_find (alias->path);
if (!op)
{
char *name = grub_strdup (use_name ? alias->name : alias->path);
char *can = grub_strdup (alias->path);
if (!name || !can)
{
grub_errno = GRUB_ERR_NONE;
grub_free (name);
grub_free (can);
return;
}
op = ofserial_hash_add (name, can);
}
return;
}
static int
dev_iterate (struct grub_ieee1275_devalias *alias)
{
dev_iterate_real (alias, 0);
return 0;
}
void void
grub_ofserial_init (void) grub_ofserial_init (void)
{ {
auto int dev_iterate_real (struct grub_ieee1275_devalias *alias,
int use_name);
int dev_iterate_real (struct grub_ieee1275_devalias *alias,
int use_name)
{
struct ofserial_hash_ent *op;
if (grub_strcmp (alias->type, "serial") != 0)
return 0;
grub_dprintf ("serial", "serial name = %s, path = %s\n", alias->name,
alias->path);
op = ofserial_hash_find (alias->path);
if (!op)
{
char *name = grub_strdup (use_name ? alias->name : alias->path);
char *can = grub_strdup (alias->path);
if (!name || !can)
{
grub_errno = GRUB_ERR_NONE;
grub_free (name);
grub_free (can);
return 0;
}
op = ofserial_hash_add (name, can);
}
return 0;
}
auto int dev_iterate_alias (struct grub_ieee1275_devalias *alias);
int dev_iterate_alias (struct grub_ieee1275_devalias *alias)
{
return dev_iterate_real (alias, 1);
}
auto int dev_iterate (struct grub_ieee1275_devalias *alias);
int dev_iterate (struct grub_ieee1275_devalias *alias)
{
return dev_iterate_real (alias, 0);
}
unsigned i; unsigned i;
grub_err_t err; grub_err_t err;
struct grub_ieee1275_devalias alias;
FOR_IEEE1275_DEVALIASES(alias)
dev_iterate_real (&alias, 1);
grub_devalias_iterate (dev_iterate_alias);
grub_ieee1275_devices_iterate (dev_iterate); grub_ieee1275_devices_iterate (dev_iterate);
for (i = 0; i < ARRAY_SIZE (ofserial_hash); i++) for (i = 0; i < ARRAY_SIZE (ofserial_hash); i++)
{ {

View file

@ -54,22 +54,22 @@ set_video_mode (unsigned width __attribute__ ((unused)),
/* TODO */ /* TODO */
} }
static int
find_display_hook (struct grub_ieee1275_devalias *alias)
{
if (grub_strcmp (alias->type, "display") == 0)
{
grub_dprintf ("video", "Found display %s\n", alias->path);
display = grub_strdup (alias->path);
return 1;
}
return 0;
}
static void static void
find_display (void) find_display (void)
{ {
auto int hook (struct grub_ieee1275_devalias *alias); grub_ieee1275_devices_iterate (find_display_hook);
int hook (struct grub_ieee1275_devalias *alias)
{
if (grub_strcmp (alias->type, "display") == 0)
{
grub_dprintf ("video", "Found display %s\n", alias->path);
display = grub_strdup (alias->path);
return 1;
}
return 0;
}
grub_ieee1275_devices_iterate (hook);
} }
static grub_err_t static grub_err_t

View file

@ -24,13 +24,6 @@
#include <grub/types.h> #include <grub/types.h>
#include <grub/machine/ieee1275.h> #include <grub/machine/ieee1275.h>
struct grub_ieee1275_devalias
{
char *name;
char *path;
char *type;
};
struct grub_ieee1275_mem_region struct grub_ieee1275_mem_region
{ {
unsigned int start; unsigned int start;
@ -64,6 +57,18 @@ struct grub_ieee1275_common_hdr
typedef grub_uint32_t grub_ieee1275_ihandle_t; typedef grub_uint32_t grub_ieee1275_ihandle_t;
typedef grub_uint32_t grub_ieee1275_phandle_t; typedef grub_uint32_t grub_ieee1275_phandle_t;
#define GRUB_IEEE1275_PHANDLE_INVALID ((grub_ieee1275_phandle_t) -1)
struct grub_ieee1275_devalias
{
char *name;
char *path;
char *type;
char *parent_path;
grub_ieee1275_phandle_t phandle;
grub_ieee1275_phandle_t parent_dev;
};
extern void (*EXPORT_VAR(grub_ieee1275_net_config)) (const char *dev, extern void (*EXPORT_VAR(grub_ieee1275_net_config)) (const char *dev,
char **device, char **device,
char **path); char **path);
@ -192,10 +197,6 @@ int EXPORT_FUNC(grub_ieee1275_set_color) (grub_ieee1275_ihandle_t ihandle,
int EXPORT_FUNC(grub_ieee1275_milliseconds) (grub_uint32_t *msecs); int EXPORT_FUNC(grub_ieee1275_milliseconds) (grub_uint32_t *msecs);
int EXPORT_FUNC(grub_devalias_iterate)
(int (*hook) (struct grub_ieee1275_devalias *alias));
int EXPORT_FUNC(grub_children_iterate) (const char *devpath,
int (*hook) (struct grub_ieee1275_devalias *alias));
grub_err_t EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size); grub_err_t EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size);
int int
@ -210,5 +211,19 @@ int EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook)
char *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path); char *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path);
char *EXPORT_FUNC(grub_ieee1275_canonicalise_devname) (const char *path); char *EXPORT_FUNC(grub_ieee1275_canonicalise_devname) (const char *path);
char *EXPORT_FUNC(grub_ieee1275_get_device_type) (const char *path); char *EXPORT_FUNC(grub_ieee1275_get_device_type) (const char *path);
char *EXPORT_FUNC(grub_ieee1275_get_devname) (const char *path);
void EXPORT_FUNC(grub_ieee1275_devalias_init_iterator) (struct grub_ieee1275_devalias *alias);
void EXPORT_FUNC(grub_ieee1275_devalias_free) (struct grub_ieee1275_devalias *alias);
int EXPORT_FUNC(grub_ieee1275_devalias_next) (struct grub_ieee1275_devalias *alias);
void EXPORT_FUNC(grub_ieee1275_children_peer) (struct grub_ieee1275_devalias *alias);
void EXPORT_FUNC(grub_ieee1275_children_first) (const char *devpath,
struct grub_ieee1275_devalias *alias);
#define FOR_IEEE1275_DEVALIASES(alias) for (grub_ieee1275_devalias_init_iterator (&(alias)); grub_ieee1275_devalias_next (&(alias));)
#define FOR_IEEE1275_DEVCHILDREN(devpath, alias) for (grub_ieee1275_children_first ((devpath), &(alias)); \
(alias).name; \
grub_ieee1275_children_peer (&(alias)))
#endif /* ! GRUB_IEEE1275_HEADER */ #endif /* ! GRUB_IEEE1275_HEADER */