]> git.ozlabs.org Git - yaboot.git/blob - include/prom.h
yaboot-1.3.17
[yaboot.git] / include / prom.h
1 /*
2  *  prom.h - Routines for talking to the Open Firmware PROM
3  *
4  *  Copyright (C) 2001 Ethan Benson
5  *
6  *  Copyright (C) 1999 Benjamin Herrenschmidt
7  *
8  *  Copyright (C) 1999 Marius Vollmer
9  *
10  *  Copyright (C) 1996 Paul Mackerras.
11  *
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifndef PROM_H
28 #define PROM_H
29
30 #include "types.h"
31 #include "stdarg.h"
32
33 typedef void *prom_handle;
34 typedef void *ihandle;
35 typedef void *phandle;
36
37 #define PROM_INVALID_HANDLE     ((prom_handle)-1UL)
38 #define BOOTDEVSZ               (2048) /* iscsi args can be in excess of 1040 bytes */
39 #define TOK_ISCSI               "iscsi"
40 #define TOK_IPV6                "ipv6"
41 #define PROM_CLAIM_MAX_ADDR     0x10000000
42 #define BOOTLASTSZ              1024
43 #define FW_NBR_REBOOTSZ         4
44
45 struct prom_args;
46 typedef int (*prom_entry)(struct prom_args *);
47
48 extern void prom_init (prom_entry pe);
49
50 extern prom_entry prom;
51
52 /* I/O */
53
54 extern prom_handle prom_stdin;
55 extern prom_handle prom_stdout;
56
57 prom_handle prom_open (char *spec);
58 int prom_read (prom_handle file, void *buf, int len);
59 int prom_write (prom_handle file, void *buf, int len);
60 int prom_seek (prom_handle file, int pos);
61 int prom_lseek (prom_handle file, unsigned long long pos);
62 int prom_readblocks (prom_handle file, int blockNum, int blockCount, void *buffer);
63 void prom_close (prom_handle file);
64 int prom_getblksize (prom_handle file);
65 int prom_loadmethod (prom_handle device, void* addr);
66
67 #define K_UP    0x141
68 #define K_DOWN  0x142
69 #define K_LEFT  0x144
70 #define K_RIGHT 0x143
71
72 int prom_getchar ();
73 void prom_putchar (char);
74 int prom_nbgetchar();
75
76 #ifdef __GNUC__
77 void prom_vprintf (const char *fmt, va_list ap) __attribute__ ((format (printf, 1, 0)));
78 void prom_vfprintf (prom_handle file, const char *fmt, va_list ap)  __attribute__ ((format (printf, 2, 0)));
79 void prom_fprintf (prom_handle dev, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
80 void prom_printf (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
81 void prom_debug (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
82 #else
83 void prom_vprintf (const char *fmt, va_list ap);
84 void prom_fprintf (prom_handle dev, const char *fmt, ...);
85 void prom_printf (const char *fmt, ...);
86 void prom_debug (const char *fmt, ...);
87 #endif
88
89 void prom_perror (int error, char *filename);
90 void prom_readline (char *prompt, char *line, int len);
91 int prom_set_color(prom_handle device, int color, int r, int g, int b);
92
93 /* memory */
94
95 void *prom_claim_chunk(void *virt, unsigned int size, unsigned int align);
96 void *prom_claim_chunk_top(unsigned int size, unsigned int align);
97 void *prom_claim (void *virt, unsigned int size, unsigned int align);
98 void prom_release(void *virt, unsigned int size);
99 void prom_map (void *phys, void *virt, int size);
100 void prom_print_available(void);
101
102 /* packages and device nodes */
103
104 prom_handle prom_finddevice (char *name);
105 prom_handle prom_findpackage (char *path);
106 int prom_getprop (prom_handle dev, char *name, void *buf, int len);
107 int prom_setprop (prom_handle dev, char *name, void *buf, int len);
108 int prom_getproplen(prom_handle, const char *);
109 int prom_get_devtype (char *device);
110
111 /* misc */
112
113 char *prom_getargs ();
114 void prom_setargs (char *args);
115
116 void prom_exit ();
117 void prom_abort (char *fmt, ...);
118 void prom_sleep (int seconds);
119
120 int prom_interpret (char *forth);
121
122 int prom_get_chosen (char *name, void *mem, int len);
123 int prom_get_options (char *name, void *mem, int len);
124 int prom_set_options (char *name, void *mem, int len);
125
126 extern int prom_getms(void);
127 extern void prom_pause(void);
128
129 extern void *call_prom (const char *service, int nargs, int nret, ...);
130 extern void *call_prom_return (const char *service, int nargs, int nret, ...);
131
132 /* Netboot stuffs */
133
134 /*
135  * "bootp-response" is the property name which is specified in
136  * the recommended practice doc for obp-tftp. However, pmac
137  * provides a "dhcp-response" property and chrp provides a
138  * "bootpreply-packet" property.  The latter appears to begin the
139  * bootp packet at offset 0x2a in the property for some reason.
140  */
141
142 struct bootp_property_offset {
143      char *name; /* property name */
144      int offset; /* offset into property where bootp packet occurs */
145 };
146
147 static const struct bootp_property_offset bootp_response_properties[] = {
148      { .name = "bootp-response", .offset = 0 },
149      { .name = "dhcp-response", .offset = 0 },
150      { .name = "bootpreply-packet", .offset = 0x2a },
151 };
152
153 struct bootp_packet {
154      __u8 op, htype, hlen, hops;
155      __u32 xid;
156      __u16 secs, flags;
157      __u32 ciaddr, yiaddr, siaddr, giaddr;
158      unsigned char chaddr[16];
159      unsigned char sname[64];
160      unsigned char file[128];
161      unsigned char options[]; /* vendor options */
162 };
163
164 struct bootp_packet * prom_get_netinfo (void);
165 char * prom_get_mac (struct bootp_packet * packet);
166 char * prom_get_ip (struct bootp_packet * packet);
167
168 #endif