1 | Templates to help porting freebsd networking drivers |
---|
2 | to rtems (focus on i386 and powerpc) using a 'quick and dirty' |
---|
3 | approach. |
---|
4 | This is not an elegant piece of software -- be warned. |
---|
5 | |
---|
6 | /* Copyright: Till Straumann <strauman@slac.stanford.edu>, 2005; |
---|
7 | * License: see LICENSE file. |
---|
8 | */ |
---|
9 | |
---|
10 | Release info: $Name$ |
---|
11 | |
---|
12 | Usage: |
---|
13 | |
---|
14 | A obtain the freebsd driver source. It usually is made |
---|
15 | up of a |
---|
16 | if_XXX.c -- core driver |
---|
17 | if_XXXreg.h -- core header |
---|
18 | if_XXXvar.h -- some have it, some don't |
---|
19 | if_XXX_<bus>.c -- glue to integrate the core |
---|
20 | driver with different environments |
---|
21 | (such as pccard, pci, ...). There |
---|
22 | are several of these. |
---|
23 | |
---|
24 | Note that you might have to get an older version |
---|
25 | as some structures and interfaces may have undergone |
---|
26 | significant changes since the bsd/networking version that |
---|
27 | was ported to rtems. |
---|
28 | |
---|
29 | B Copy the Makefile and rtemscompat_defs.h templates to the |
---|
30 | driver source dir and edit them. |
---|
31 | |
---|
32 | C Edit if_XXXreg.h and comment all unneeded fields from the |
---|
33 | 'softc' structure declaration with |
---|
34 | |
---|
35 | #ifndef __rtems__ |
---|
36 | #endif |
---|
37 | |
---|
38 | In particular, the bushandle field (as defined in rtemscompat_defs.h) |
---|
39 | above, see comments in the template) must be re-declared: |
---|
40 | |
---|
41 | #ifndef __rtems__ |
---|
42 | bus_space_handle_t XXX_bhandle; |
---|
43 | #else |
---|
44 | unsigned XXX_bhandle; |
---|
45 | unsigned char irq_no; |
---|
46 | unsigned char b,d,f; /* PCI tuple; needed for PCI only */ |
---|
47 | rtems_id tid; /* driver task id */ |
---|
48 | #endif |
---|
49 | |
---|
50 | Later, the compilation attempts will help identifying |
---|
51 | fields that need to be removed. |
---|
52 | |
---|
53 | I like the #ifdef __rtems__ construct as it minimizes changes |
---|
54 | to the source thus making merging updated driver versions easier. |
---|
55 | |
---|
56 | D Edit if_XXX.c; at the very top, include the lines |
---|
57 | |
---|
58 | #ifdef __rtems__ |
---|
59 | #include <rtemscompat.h> |
---|
60 | #endif |
---|
61 | |
---|
62 | use the #ifndef __rtems__ #endif construct to comment |
---|
63 | unneeded / unsupported inclusion of headers and code pieces. |
---|
64 | |
---|
65 | - inclusion of net/if_media.h must usually be mapped to |
---|
66 | libchip/if_media.h |
---|
67 | |
---|
68 | comment all vm, machine, bus, mii etc. related headers. |
---|
69 | |
---|
70 | - replace inclusion of if_XXXreg.h by |
---|
71 | |
---|
72 | #include "if_XXXreg.h" |
---|
73 | #include <rtemscompat1.h> |
---|
74 | |
---|
75 | - work through the if_XXX.c and if_XXXreg.h files commenting |
---|
76 | stuff until if_XXX.c compiles. This might involve hacking |
---|
77 | the helper headers. |
---|
78 | |
---|
79 | - pay attention to endian issues; things may need to be fixed! |
---|
80 | |
---|
81 | - at the top where the freebsd 'methods' and the like are |
---|
82 | commented, add a definition of the driver methods for RTEMS: |
---|
83 | |
---|
84 | #ifdef __rtems__ |
---|
85 | net_drv_tbl_t METHODS = { |
---|
86 | n_probe : XXX_probe, |
---|
87 | n_attach : XXX_attach, |
---|
88 | n_detach : XXX_detach, /* optional; */ |
---|
89 | n_intr : XXX_intr, /* freebsd ISR; executed from daemon under RTEMS */ |
---|
90 | }; |
---|
91 | #endif |
---|
92 | |
---|
93 | - make sure all the if_xxx methods are set; in particular, |
---|
94 | set |
---|
95 | sc->if_output = ether_output; |
---|
96 | |
---|
97 | - on input: |
---|
98 | you can use DO_ETHER_INPUT_SKIPPING_ETHER_HEADER() macro |
---|
99 | -- if you don't MAKE SURE THE RECEIVING INTERFACE IS SET |
---|
100 | in the mbuf packet header!!! |
---|
101 | |
---|
102 | E create 'rtems_<chip>_setup()' to probe for devices and |
---|
103 | set the softc struct's base address, interrupt line and |
---|
104 | bus/dev/fun triple (PCI only). |
---|
105 | For PCI devices, a generic setup routine already comes with |
---|
106 | porting/if_xxx_rtems.c -> nothing needs to be written! |
---|