boot: Reorder functions in boot.c

Currently glob_prefix() and build_pci_path() are under the "Boot
priority ordering" section.
Move them to a new "Helper search functions" section since we will reuse
them in the next commit.

Reviewed-by: Karl Heubaum <karl.heubaum@oracle.com>
Reviewed-by: Arbel Moshe <arbel.moshe@oracle.com>
Signed-off-by: Sam Eiderman <shmuel.eiderman@oracle.com>
Message-Id: <20190612093704.47175-3-shmuel.eiderman@oracle.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Sam Eiderman 2019-06-12 12:37:01 +03:00 committed by Gerd Hoffmann
parent 7c66a439c0
commit b3d21205b7
1 changed files with 49 additions and 45 deletions

View File

@ -22,6 +22,55 @@
#include "util.h" // irqtimer_calc
#include "tcgbios.h" // tpm_*
/****************************************************************
* Helper search functions
****************************************************************/
// See if 'str' starts with 'glob' - if glob contains an '*' character
// it will match any number of characters in str that aren't a '/' or
// the next glob character.
static char *
glob_prefix(const char *glob, const char *str)
{
for (;;) {
if (!*glob && (!*str || *str == '/'))
return (char*)str;
if (*glob == '*') {
if (!*str || *str == '/' || *str == glob[1])
glob++;
else
str++;
continue;
}
if (*glob != *str)
return NULL;
glob++;
str++;
}
}
#define FW_PCI_DOMAIN "/pci@i0cf8"
static char *
build_pci_path(char *buf, int max, const char *devname, struct pci_device *pci)
{
// Build the string path of a bdf - for example: /pci@i0cf8/isa@1,2
char *p = buf;
if (pci->parent) {
p = build_pci_path(p, max, "pci-bridge", pci->parent);
} else {
p += snprintf(p, buf+max-p, "%s", FW_PCI_DOMAIN);
if (pci->rootbus)
p += snprintf(p, buf+max-p, ",%x", pci->rootbus);
}
int dev = pci_bdf_to_dev(pci->bdf), fn = pci_bdf_to_fn(pci->bdf);
p += snprintf(p, buf+max-p, "/%s@%x", devname, dev);
if (fn)
p += snprintf(p, buf+max-p, ",%x", fn);
return p;
}
/****************************************************************
* Boot device parameters
@ -154,29 +203,6 @@ loadBootOrder(void)
} while (f);
}
// See if 'str' starts with 'glob' - if glob contains an '*' character
// it will match any number of characters in str that aren't a '/' or
// the next glob character.
static char *
glob_prefix(const char *glob, const char *str)
{
for (;;) {
if (!*glob && (!*str || *str == '/'))
return (char*)str;
if (*glob == '*') {
if (!*str || *str == '/' || *str == glob[1])
glob++;
else
str++;
continue;
}
if (*glob != *str)
return NULL;
glob++;
str++;
}
}
// Search the bootorder list for the given glob pattern.
static int
find_prio(const char *glob)
@ -189,28 +215,6 @@ find_prio(const char *glob)
return -1;
}
#define FW_PCI_DOMAIN "/pci@i0cf8"
static char *
build_pci_path(char *buf, int max, const char *devname, struct pci_device *pci)
{
// Build the string path of a bdf - for example: /pci@i0cf8/isa@1,2
char *p = buf;
if (pci->parent) {
p = build_pci_path(p, max, "pci-bridge", pci->parent);
} else {
p += snprintf(p, buf+max-p, "%s", FW_PCI_DOMAIN);
if (pci->rootbus)
p += snprintf(p, buf+max-p, ",%x", pci->rootbus);
}
int dev = pci_bdf_to_dev(pci->bdf), fn = pci_bdf_to_fn(pci->bdf);
p += snprintf(p, buf+max-p, "/%s@%x", devname, dev);
if (fn)
p += snprintf(p, buf+max-p, ",%x", fn);
return p;
}
int bootprio_find_pci_device(struct pci_device *pci)
{
if (CONFIG_CSM)