Chameleon

Chameleon Svn Source Tree

Root/branches/meklort/i386/modules/Ethernet/Ethernet.c

Source at commit 543 created 13 years 7 months ago.
By meklort, Chameleon code shrinkage. Also moved a few things to modules.
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
23void set_eth_builtin(pci_dt_t *eth_dev);
24
25
26void Ethernet_hook(void* arg1, void* arg2, void* arg3, void* arg4)
27{
28pci_dt_t* current = arg1;
29
30if(current->class_id != PCI_CLASS_NETWORK_ETHERNET) return;
31
32
33bool do_eth_devprop = false;
34getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, &bootInfo->bootConfig);
35
36if (do_eth_devprop)
37set_eth_builtin(current);
38}
39
40void Ethernet_start()
41{
42register_hook_callback("PCIDevice", &Ethernet_hook);
43}
44
45/* a fine place for this code */
46
47int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id)
48{
49if(!device)
50return 0;
51uint8_t builtin = 0x0;
52if((vendor_id != 0x168c) && (builtin_set == 0))
53{
54builtin_set = 1;
55builtin = 0x01;
56}
57if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))
58return 0;
59devices_number++;
60return 1;
61}
62
63void set_eth_builtin(pci_dt_t *eth_dev)
64{
65char *devicepath = get_pci_dev_path(eth_dev);
66struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice));
67
68verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);
69
70if (!string)
71string = devprop_create_string();
72
73device = devprop_add_device(string, devicepath);
74if(device)
75{
76verbose("Setting up lan keys\n");
77devprop_add_network_template(device, eth_dev->vendor_id);
78stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);
79if(stringdata)
80{
81memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
82stringlength = string->length;
83}
84}
85}
86

Archive Download this file

Revision: 543