summaryrefslogtreecommitdiff
path: root/src/bios_device.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bios_device.c')
-rw-r--r--src/bios_device.c156
1 files changed, 58 insertions, 98 deletions
diff --git a/src/bios_device.c b/src/bios_device.c
index 5c275c8..24b0a77 100644
--- a/src/bios_device.c
+++ b/src/bios_device.c
@@ -6,12 +6,12 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <pci/pci.h>
#include <net/if.h>
#include "list.h"
#include "bios_device.h"
#include "state.h"
#include "libbiosdevname.h"
-#include "dmidecode/dmidecode.h"
void free_bios_devices(void *cookie)
{
@@ -28,8 +28,9 @@ void free_bios_devices(void *cookie)
static void unparse_bios_device(struct bios_device *dev)
{
- char buf[200];
- printf("BIOS device: %s\n", dev->bios_name);
+ char buf[8192];
+ memset(buf, 0, sizeof(buf));
+ printf("BIOS device: %s\n", dev->bios_name ? dev->bios_name : "");
if (dev->netdev) {
unparse_network_device(buf, sizeof(buf), dev->netdev);
printf("%s", buf);
@@ -41,12 +42,9 @@ static void unparse_bios_device(struct bios_device *dev)
unparse_pci_device(buf, sizeof(buf), dev->pcidev);
printf("%s", buf);
}
- else if (is_pcmcia(dev)) {
- unparse_pcmcia_device(buf, sizeof(buf), dev->pcmciadev);
- printf("%s", buf);
- }
-
printf("\n");
+ if (dev->duplicate)
+ printf("Duplicate: True\n");
}
void unparse_bios_devices(void *cookie)
@@ -82,8 +80,11 @@ char * kern_to_bios(void *cookie,
if (!state)
return NULL;
list_for_each_entry(dev, &state->bios_devices, node) {
- if (dev->netdev && !strcmp(dev->netdev->kernel_name, name))
+ if (dev->netdev && !strcmp(dev->netdev->kernel_name, name)) {
+ if (dev->duplicate)
+ return NULL;
return dev->bios_name;
+ }
}
return NULL;
}
@@ -116,17 +117,17 @@ static int sort_pci(const struct bios_device *bdev_a, const struct bios_device *
if (a->physical_slot < b->physical_slot) return -1;
else if (a->physical_slot > b->physical_slot) return 1;
- if (a->pci_dev.domain < b->pci_dev.domain) return -1;
- else if (a->pci_dev.domain > b->pci_dev.domain) return 1;
+ if (a->pci_dev->domain < b->pci_dev->domain) return -1;
+ else if (a->pci_dev->domain > b->pci_dev->domain) return 1;
- if (a->pci_dev.bus < b->pci_dev.bus) return -1;
- else if (a->pci_dev.bus > b->pci_dev.bus) return 1;
+ if (a->pci_dev->bus < b->pci_dev->bus) return -1;
+ else if (a->pci_dev->bus > b->pci_dev->bus) return 1;
- if (a->pci_dev.dev < b->pci_dev.dev) return -1;
- else if (a->pci_dev.dev > b->pci_dev.dev) return 1;
+ if (a->pci_dev->dev < b->pci_dev->dev) return -1;
+ else if (a->pci_dev->dev > b->pci_dev->dev) return 1;
- if (a->pci_dev.func < b->pci_dev.func) return -1;
- else if (a->pci_dev.func > b->pci_dev.func) return 1;
+ if (a->pci_dev->func < b->pci_dev->func) return -1;
+ else if (a->pci_dev->func > b->pci_dev->func) return 1;
return 0;
}
@@ -155,24 +156,8 @@ static int sort_smbios(const struct bios_device *x, const struct bios_device *y)
return sort_pci(x, y);
}
-
-static int sort_pcmcia(const struct bios_device *bdev_a, const struct bios_device *bdev_b)
-{
- const struct pcmcia_device *a = bdev_a->pcmciadev;
- const struct pcmcia_device *b = bdev_b->pcmciadev;
-
- if (a->socket < b->socket) return -1;
- else if (a->socket > b->socket) return 1;
-
- if (a->function < b->function) return -1;
- else if (a->function > b->function) return 1;
-
- return 0;
-}
-
enum bios_device_types {
IS_PCI,
- IS_PCMCIA,
IS_UNKNOWN_TYPE,
};
@@ -180,8 +165,6 @@ static int bios_device_type_num(const struct bios_device *dev)
{
if (is_pci(dev))
return IS_PCI;
- else if (is_pcmcia(dev))
- return IS_PCMCIA;
return IS_UNKNOWN_TYPE;
}
@@ -192,8 +175,6 @@ static int sort_by_type(const struct bios_device *a, const struct bios_device *b
else if (bios_device_type_num(a) == bios_device_type_num(b)) {
if (is_pci(a))
return sort_smbios(a, b);
- else if (is_pcmcia(a))
- return sort_pcmcia(a, b);
else return 0;
}
else if (bios_device_type_num(a) > bios_device_type_num(b))
@@ -215,24 +196,6 @@ static void insertion_sort_devices(struct bios_device *a, struct list_head *list
list_move_tail(&a->node, list);
}
-static int set_slot_index(struct libbiosdevname_state *state)
-{
- struct bios_device *dev;
- int prevslot=-1;
- int index=0;
-
- list_for_each_entry(dev, &state->bios_devices, node) {
- if (!dev->pcidev)
- continue;
- if (dev->pcidev->physical_slot != prevslot)
- index=0;
- else
- index++;
- dev->pcidev->index_in_slot = index;
- prevslot = dev->pcidev->physical_slot;
- }
- return 0;
-}
static void sort_device_list(struct libbiosdevname_state *state)
{
@@ -242,7 +205,6 @@ static void sort_device_list(struct libbiosdevname_state *state)
insertion_sort_devices(dev, &sorted_devices, sort_by_type);
}
list_splice(&sorted_devices, &state->bios_devices);
- set_slot_index(state);
}
static void match_eth_and_pci_devs(struct libbiosdevname_state *state)
@@ -256,7 +218,7 @@ static void match_eth_and_pci_devs(struct libbiosdevname_state *state)
if (!is_pci_network(p))
continue;
- unparse_pci_name(pci_name, sizeof(pci_name), &p->pci_dev);
+ unparse_pci_name(pci_name, sizeof(pci_name), p->pci_dev);
n = find_net_device_by_bus_info(state, pci_name);
if (!n)
continue;
@@ -273,32 +235,6 @@ static void match_eth_and_pci_devs(struct libbiosdevname_state *state)
}
}
-static void match_eth_and_pcmcia(struct libbiosdevname_state *state)
-{
- struct pcmcia_device *p;
- struct bios_device *b;
- char pcmcia_name[40];
-
- list_for_each_entry(p, &state->pcmcia_devices, node) {
- if (!is_pcmcia_network(p))
- continue;
-
- b = malloc(sizeof(*b));
- if (!b)
- continue;
- memset(b, 0, sizeof(*b));
- INIT_LIST_HEAD(&b->node);
- b->pcmciadev = p;
-
- unparse_pcmcia_name(pcmcia_name, sizeof(pcmcia_name), p);
- b->netdev = find_net_device_by_bus_info(state, pcmcia_name);
-
- memset(b->bios_name, 0, sizeof(b->bios_name));
- claim_netdev(b->netdev);
- list_add(&b->node, &state->bios_devices);
- }
-}
-
static void match_unknown_eths(struct libbiosdevname_state *state)
{
struct bios_device *b;
@@ -325,7 +261,6 @@ static void match_unknown_eths(struct libbiosdevname_state *state)
static void match_all(struct libbiosdevname_state *state)
{
match_eth_and_pci_devs(state);
- match_eth_and_pcmcia(state);
match_unknown_eths(state);
}
@@ -338,7 +273,8 @@ static struct libbiosdevname_state * alloc_state(void)
INIT_LIST_HEAD(&state->bios_devices);
INIT_LIST_HEAD(&state->pci_devices);
INIT_LIST_HEAD(&state->network_devices);
- INIT_LIST_HEAD(&state->pcmcia_devices);
+ state->pacc = NULL;
+ state->pirq_table = NULL;
return state;
}
@@ -349,11 +285,41 @@ void cleanup_bios_devices(void *cookie)
return;
free_bios_devices(state);
free_eths(state);
- free_pcmcia_devices(state);
free_pci_devices(state);
+ if (state->pacc)
+ pci_cleanup(state->pacc);
+ if (state->pirq_table)
+ pirq_free_table(state->pirq_table);
+}
+
+static int duplicates(struct bios_device *a, struct bios_device *b)
+{
+ int lenA = -1, lenB = -1, rc = -1;
+ if (a->bios_name)
+ lenA = strlen(a->bios_name);
+ if (b->bios_name)
+ lenB = strlen(b->bios_name);
+ if (lenA == lenB && lenA > 0)
+ rc = strncmp(a->bios_name, b->bios_name, lenA);
+ return !rc;
}
-void * setup_bios_devices(int sortroutine, int namingpolicy)
+static void find_duplicates(struct libbiosdevname_state *state)
+{
+ struct bios_device *a = NULL, *b = NULL;
+ list_for_each_entry(a, &state->bios_devices, node) {
+ list_for_each_entry(b, &state->bios_devices, node) {
+ if (a == b)
+ continue;
+ if (duplicates(a, b)) {
+ a->duplicate = 1;
+ b->duplicate = 1;
+ }
+ }
+ }
+}
+
+void * setup_bios_devices(int namingpolicy, const char *prefix)
{
int rc=1;
struct libbiosdevname_state *state = alloc_state();
@@ -365,18 +331,13 @@ void * setup_bios_devices(int sortroutine, int namingpolicy)
if (rc)
goto out;
- rc = get_pcmcia_devices(state);
- if (rc)
- goto out;
- rc = dmidecode_main(state);
- if (rc)
- goto out;
get_eths(state);
match_all(state);
- if (sortroutine != nosort) {
- sort_device_list(state);
- }
- assign_bios_network_names(state, sortroutine, namingpolicy);
+ sort_device_list(state);
+ rc = assign_bios_network_names(state, namingpolicy, prefix);
+ if (rc)
+ goto out;
+ find_duplicates(state);
return state;
out:
@@ -384,4 +345,3 @@ out:
free(state);
return NULL;
}
-