Root/
Source at commit 555 created 13 years 8 months ago. By meklort, Removed recursion, already taken care of in the pci setup function. | |
---|---|
1 | /*␊ |
2 | * Copyright (c) 2009 Evan Lojewski. All rights reserved.␊ |
3 | *␊ |
4 | */␊ |
5 | ␊ |
6 | #include "libsaio.h"␊ |
7 | #include "modules.h"␊ |
8 | #include "boot.h"␊ |
9 | #include "bootstruct.h"␊ |
10 | #include "pci.h"␊ |
11 | #include "hpet.h"␊ |
12 | ␊ |
13 | #ifndef DEBUG_HPET␊ |
14 | #define DEBUG_HPET 0␊ |
15 | #endif␊ |
16 | ␊ |
17 | #if DEBUG_HPET␊ |
18 | #define DBG(x...) printf(x)␊ |
19 | #else␊ |
20 | #define DBG(x...)␊ |
21 | #endif␊ |
22 | ␊ |
23 | void set_eth_builtin(pci_dt_t *eth_dev);␊ |
24 | ␊ |
25 | ␊ |
26 | void Ethernet_hook(void* arg1, void* arg2, void* arg3, void* arg4)␊ |
27 | {␊ |
28 | ␉pci_dt_t* current = arg1;␊ |
29 | ␉␊ |
30 | ␉if(current->class_id != PCI_CLASS_NETWORK_ETHERNET) return;␊ |
31 | ␉␊ |
32 | ␉␊ |
33 | ␉bool do_eth_devprop = false;␉␊ |
34 | ␉getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, &bootInfo->bootConfig);␊ |
35 | ␉␊ |
36 | ␉if (do_eth_devprop)␊ |
37 | ␉␉set_eth_builtin(current);␊ |
38 | }␊ |
39 | ␊ |
40 | void Ethernet_start()␊ |
41 | {␊ |
42 | ␉register_hook_callback("PCIDevice", &Ethernet_hook);␊ |
43 | }␊ |
44 | ␊ |
45 | /* a fine place for this code */␊ |
46 | ␊ |
47 | int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id)␊ |
48 | {␊ |
49 | ␉uint8_t builtin = 0x0;␊ |
50 | ␊ |
51 | ␉if(device)␊ |
52 | ␉{␊ |
53 | ␉␉␊ |
54 | ␉␉if((vendor_id != 0x168c) && (builtin_set == 0)) ␊ |
55 | ␉␉{␊ |
56 | ␉␉␉builtin_set = 1;␊ |
57 | ␉␉␉builtin = 0x01;␊ |
58 | ␉␉}␊ |
59 | ␉␉␊ |
60 | ␉␉if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))␊ |
61 | ␉␉{␊ |
62 | ␉␉␉return 0;␊ |
63 | ␉␉}␊ |
64 | ␉␉␊ |
65 | ␉␉devices_number++;␊ |
66 | ␉␉return 1;␊ |
67 | ␉}␊ |
68 | ␉else␊ |
69 | ␉{␊ |
70 | ␉␉return 0;␊ |
71 | ␉}␊ |
72 | ␊ |
73 | }␊ |
74 | ␊ |
75 | void set_eth_builtin(pci_dt_t *eth_dev)␊ |
76 | {␊ |
77 | ␉char *devicepath = get_pci_dev_path(eth_dev);␊ |
78 | ␉struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice));␊ |
79 | ␉␊ |
80 | ␉verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);␊ |
81 | ␉␊ |
82 | ␉if (!string)␊ |
83 | ␉␉string = devprop_create_string();␊ |
84 | ␉␊ |
85 | ␉device = devprop_add_device(string, devicepath);␊ |
86 | ␉if(device)␊ |
87 | ␉{␊ |
88 | ␉␉verbose("Setting up lan keys\n");␊ |
89 | ␉␉devprop_add_network_template(device, eth_dev->vendor_id);␊ |
90 | ␉␉stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);␊ |
91 | ␉␉if(stringdata)␊ |
92 | ␉␉{␊ |
93 | ␉␉␉memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);␊ |
94 | ␉␉␉stringlength = string->length;␊ |
95 | ␉␉}␊ |
96 | ␉}␊ |
97 | }␊ |
98 |