Chameleon

Chameleon Svn Source Tree

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

Source at commit 551 created 13 years 7 months ago.
By meklort, More bugfixes. more modules should work now. Memory module temperarily disabled.
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{
49uint8_t builtin = 0x0;
50
51if(device)
52{
53
54if((vendor_id != 0x168c) && (builtin_set == 0))
55{
56builtin_set = 1;
57builtin = 0x01;
58}
59
60if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))
61{
62return 0;
63}
64
65devices_number++;
66return 1;
67}
68else
69{
70return 0;
71}
72
73}
74
75void set_eth_builtin(pci_dt_t *eth_dev)
76{
77char *devicepath = get_pci_dev_path(eth_dev);
78struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice));
79
80verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);
81
82if (!string)
83string = devprop_create_string();
84
85device = devprop_add_device(string, devicepath);
86if(device)
87{
88verbose("Setting up lan keys\n");
89devprop_add_network_template(device, eth_dev->vendor_id);
90stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);
91if(stringdata)
92{
93memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
94stringlength = string->length;
95}
96}
97}
98

Archive Download this file

Revision: 551