Fix cross compilation (e.g. on Darwin). Following changes to make.tmpl,
[AROS.git] / arch / all-pc / boot / grub2-aros / include / grub / serial.h
blob67379de45dd1fef846e062cb9959d541bf5c3b31
1 /* serial.h - serial device interface */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2010 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef GRUB_SERIAL_HEADER
21 #define GRUB_SERIAL_HEADER 1
23 #include <grub/types.h>
24 #if defined(__mips__) || defined (__i386__) || defined (__x86_64__)
25 #include <grub/cpu/io.h>
26 #endif
27 #include <grub/usb.h>
28 #include <grub/list.h>
29 #include <grub/term.h>
30 #ifdef GRUB_MACHINE_IEEE1275
31 #include <grub/ieee1275/ieee1275.h>
32 #endif
33 #ifdef GRUB_MACHINE_ARC
34 #include <grub/arc/arc.h>
35 #endif
37 struct grub_serial_port;
38 struct grub_serial_config;
40 struct grub_serial_driver
42 grub_err_t (*configure) (struct grub_serial_port *port,
43 struct grub_serial_config *config);
44 int (*fetch) (struct grub_serial_port *port);
45 void (*put) (struct grub_serial_port *port, const int c);
46 void (*fini) (struct grub_serial_port *port);
49 /* The type of parity. */
50 typedef enum
52 GRUB_SERIAL_PARITY_NONE,
53 GRUB_SERIAL_PARITY_ODD,
54 GRUB_SERIAL_PARITY_EVEN,
55 } grub_serial_parity_t;
57 typedef enum
59 GRUB_SERIAL_STOP_BITS_1,
60 GRUB_SERIAL_STOP_BITS_1_5,
61 GRUB_SERIAL_STOP_BITS_2,
62 } grub_serial_stop_bits_t;
64 struct grub_serial_config
66 unsigned speed;
67 int word_len;
68 grub_serial_parity_t parity;
69 grub_serial_stop_bits_t stop_bits;
70 grub_uint64_t base_clock;
71 int rtscts;
74 struct grub_serial_port
76 struct grub_serial_port *next;
77 struct grub_serial_port **prev;
78 char *name;
79 struct grub_serial_driver *driver;
80 struct grub_serial_config config;
81 int configured;
82 int broken;
84 /* This should be void *data but since serial is useful as an early console
85 when malloc isn't available it's a union.
87 union
89 #if defined(__mips__) || defined (__i386__) || defined (__x86_64__)
90 grub_port_t port;
91 #endif
92 struct
94 grub_usb_device_t usbdev;
95 int configno;
96 int interfno;
97 char buf[64];
98 int bufstart, bufend;
99 struct grub_usb_desc_endp *in_endp;
100 struct grub_usb_desc_endp *out_endp;
102 struct grub_escc_descriptor *escc_desc;
103 #ifdef GRUB_MACHINE_IEEE1275
104 struct
106 grub_ieee1275_ihandle_t handle;
107 struct ofserial_hash_ent *elem;
109 #endif
110 #ifdef GRUB_MACHINE_EFI
111 struct grub_efi_serial_io_interface *interface;
112 #endif
113 #ifdef GRUB_MACHINE_ARC
114 struct
116 grub_arc_fileno_t handle;
117 int handle_valid;
119 #endif
121 grub_term_output_t term_out;
122 grub_term_input_t term_in;
125 grub_err_t EXPORT_FUNC(grub_serial_register) (struct grub_serial_port *port);
127 void EXPORT_FUNC(grub_serial_unregister) (struct grub_serial_port *port);
129 /* Convenience functions to perform primitive operations on a port. */
130 static inline grub_err_t
131 grub_serial_port_configure (struct grub_serial_port *port,
132 struct grub_serial_config *config)
134 return port->driver->configure (port, config);
137 static inline int
138 grub_serial_port_fetch (struct grub_serial_port *port)
140 return port->driver->fetch (port);
143 static inline void
144 grub_serial_port_put (struct grub_serial_port *port, const int c)
146 port->driver->put (port, c);
149 static inline void
150 grub_serial_port_fini (struct grub_serial_port *port)
152 port->driver->fini (port);
155 /* Set default settings. */
156 static inline grub_err_t
157 grub_serial_config_defaults (struct grub_serial_port *port)
159 struct grub_serial_config config =
161 #ifdef GRUB_MACHINE_MIPS_LOONGSON
162 .speed = 115200,
163 /* On Loongson machines serial port has only 3 wires. */
164 .rtscts = 0,
165 #else
166 .speed = 9600,
167 .rtscts = 1,
168 #endif
169 .word_len = 8,
170 .parity = GRUB_SERIAL_PARITY_NONE,
171 .stop_bits = GRUB_SERIAL_STOP_BITS_1,
172 .base_clock = 0
175 return port->driver->configure (port, &config);
178 #if defined(__mips__) || defined (__i386__) || defined (__x86_64__)
179 void grub_ns8250_init (void);
180 char *grub_serial_ns8250_add_port (grub_port_t port);
181 #endif
182 #ifdef GRUB_MACHINE_IEEE1275
183 void grub_ofserial_init (void);
184 #endif
185 #ifdef GRUB_MACHINE_EFI
186 void
187 grub_efiserial_init (void);
188 #endif
189 #ifdef GRUB_MACHINE_ARC
190 void
191 grub_arcserial_init (void);
192 const char *
193 grub_arcserial_add_port (const char *path);
194 #endif
196 struct grub_serial_port *grub_serial_find (const char *name);
197 extern struct grub_serial_driver grub_ns8250_driver;
198 void EXPORT_FUNC(grub_serial_unregister_driver) (struct grub_serial_driver *driver);
200 #ifndef GRUB_MACHINE_EMU
201 extern void grub_serial_init (void);
202 extern void grub_serial_fini (void);
203 #endif
205 #endif