|
|
1.1 root 1: /******************************************************************************
2: * Copyright (c) 2011 IBM Corporation
3: * All rights reserved.
4: * This program and the accompanying materials
5: * are made available under the terms of the BSD License
6: * which accompanies this distribution, and is available at
7: * http://www.opensource.org/licenses/bsd-license.php
8: *
9: * Contributors:
10: * IBM Corporation - initial implementation
11: *****************************************************************************/
12: /*
13: * A pseudo-module that uses the the "write" and "read" functions via the
14: * client interface to handle the given device.
15: * Normally the net-snk uses the various net_xxx modules from the romfs to
16: * drive the network cards. However, in case we do not have a net-snk driver
17: * for the given card and it has been initialized via FCODE instead, we've
18: * got to use the Open Firmware Client Interface "write" and "read" functions
19: * to talk to the NIC. This is achieved via this pseudo-module here.
20: */
21:
22: #include <of.h>
23: #include <string.h>
24: #include <netdriver_int.h>
25: #include <fileio.h>
26: #include <stdint.h>
27: #include <kernel.h>
28:
29: #define DEBUG 0
30: #if DEBUG
31: #define dprintf(str, ...) snk_kernel_interface.print(str, ## __VA_ARGS__)
32: #else
33: #define dprintf(str, ...) do{}while(0)
34: #endif
35:
36: extern snk_kernel_t snk_kernel_interface;
37:
38: snk_module_t * cimod_check_and_install(void);
39: static int cimod_init(void);
40: static int cimod_term(void);
41: static int cimod_read(char *buffer, int len);
42: static int cimod_write(char *buffer, int len);
43: static int cimod_ioctl(int request, void *data);
44:
45: snk_module_t ci_module = {
46: .version = 1,
47: .type = MOD_TYPE_NETWORK,
48: .running = 0,
49: .link_addr = (char*) 1,
50: .init = cimod_init,
51: .term = cimod_term,
52: .write = cimod_write,
53: .read = cimod_read,
54: .ioctl = cimod_ioctl
55: };
56:
57: static ihandle_t myself;
58:
59:
60: snk_module_t *
61: cimod_check_and_install(void)
62: {
63: uint8_t tmpbuf[8];
64:
65: dprintf("entered cimod_check_and_install!\n");
66:
67: myself = of_interpret_1("my-parent", tmpbuf);
68: dprintf("cimod: myself=%lx\n", myself);
69:
70: /* Check whether "read" and "write" functions are provided by the
71: * device tree node: */
72: if (of_read(myself, tmpbuf, 0) == -1
73: || of_write(myself, tmpbuf, 0) == -1) {
74: dprintf("cimod: missing read or write!\n");
75: return NULL;
76: }
77:
78: return &ci_module;
79: }
80:
81: static int
82: cimod_init(void)
83: {
84: ci_module.running = 1;
85: snk_kernel_interface.print("client-interface module initialized!\n");
86: return 0;
87: }
88:
89: static int
90: cimod_term(void)
91: {
92: ci_module.running = 0;
93: dprintf("cimod term called!\n");
94: return 0;
95: }
96:
97: static int
98: cimod_read(char *buffer, int len)
99: {
100: int ret;
101:
102: ret = of_read(myself, buffer, len);
103: dprintf("cimod read returned: %i!\n", ret);
104:
105: return ret;
106: }
107:
108: static int
109: cimod_write(char *buffer, int len)
110: {
111: int ret;
112:
113: ret = of_write(myself, buffer, len);
114: dprintf("cimod write returned: %i!\n", ret);
115:
116: return ret;
117: }
118:
119: static int
120: cimod_ioctl(int request, void *data)
121: {
122: dprintf("cimod ioctl called!\n");
123:
124: return 0;
125: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.