blob: d06dc5a6b8d398ec5e4f6947277af6f589d06376 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2000, 2001, 2002 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
Christoph Hellwig417345d2007-10-29 14:23:43 +000019/*
20 *
21 * Broadcom Common Firmware Environment (CFE)
22 *
23 * This module contains device function stubs (small routines to
24 * call the standard "iocb" interface entry point to CFE).
25 * There should be one routine here per iocb function call.
26 *
27 * Authors: Mitch Lichtenberg, Chris Demetriou
28 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Aurelien Jarnodf78b5c2007-09-05 08:58:26 +020030#include <asm/fw/cfe/cfe_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "cfe_api_int.h"
32
33/* Cast from a native pointer to a cfe_xptr_t and back. */
34#define XPTR_FROM_NATIVE(n) ((cfe_xptr_t) (intptr_t) (n))
35#define NATIVE_FROM_XPTR(x) ((void *) (intptr_t) (x))
36
Christoph Hellwig417345d2007-10-29 14:23:43 +000037int cfe_iocb_dispatch(struct cfe_xiocb *xiocb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039/*
40 * Declare the dispatch function with args of "intptr_t".
41 * This makes sure whatever model we're compiling in
42 * puts the pointers in a single register. For example,
43 * combining -mlong64 and -mips1 or -mips2 would lead to
44 * trouble, since the handle and IOCB pointer will be
45 * passed in two registers each, and CFE expects one.
46 */
47
Ralf Baechle982f6ff2009-09-17 02:25:07 +020048static int (*cfe_dispfunc) (intptr_t handle, intptr_t xiocb);
49static u64 cfe_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Christoph Hellwig417345d2007-10-29 14:23:43 +000051int cfe_init(u64 handle, u64 ept)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
53 cfe_dispfunc = NATIVE_FROM_XPTR(ept);
54 cfe_handle = handle;
55 return 0;
56}
57
Christoph Hellwig417345d2007-10-29 14:23:43 +000058int cfe_iocb_dispatch(struct cfe_xiocb * xiocb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
60 if (!cfe_dispfunc)
61 return -1;
62 return (*cfe_dispfunc) ((intptr_t) cfe_handle, (intptr_t) xiocb);
63}
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Linus Torvalds1da177e2005-04-16 15:20:36 -070065int cfe_close(int handle)
66{
Christoph Hellwig417345d2007-10-29 14:23:43 +000067 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69 xiocb.xiocb_fcode = CFE_CMD_DEV_CLOSE;
70 xiocb.xiocb_status = 0;
71 xiocb.xiocb_handle = handle;
72 xiocb.xiocb_flags = 0;
73 xiocb.xiocb_psize = 0;
74
75 cfe_iocb_dispatch(&xiocb);
76
77 return xiocb.xiocb_status;
78
79}
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081int cfe_cpu_start(int cpu, void (*fn) (void), long sp, long gp, long a1)
82{
Christoph Hellwig417345d2007-10-29 14:23:43 +000083 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85 xiocb.xiocb_fcode = CFE_CMD_FW_CPUCTL;
86 xiocb.xiocb_status = 0;
87 xiocb.xiocb_handle = 0;
88 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +000089 xiocb.xiocb_psize = sizeof(struct xiocb_cpuctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 xiocb.plist.xiocb_cpuctl.cpu_number = cpu;
91 xiocb.plist.xiocb_cpuctl.cpu_command = CFE_CPU_CMD_START;
92 xiocb.plist.xiocb_cpuctl.gp_val = gp;
93 xiocb.plist.xiocb_cpuctl.sp_val = sp;
94 xiocb.plist.xiocb_cpuctl.a1_val = a1;
95 xiocb.plist.xiocb_cpuctl.start_addr = (long) fn;
96
97 cfe_iocb_dispatch(&xiocb);
98
99 return xiocb.xiocb_status;
100}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102int cfe_cpu_stop(int cpu)
103{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000104 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 xiocb.xiocb_fcode = CFE_CMD_FW_CPUCTL;
107 xiocb.xiocb_status = 0;
108 xiocb.xiocb_handle = 0;
109 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000110 xiocb.xiocb_psize = sizeof(struct xiocb_cpuctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 xiocb.plist.xiocb_cpuctl.cpu_number = cpu;
112 xiocb.plist.xiocb_cpuctl.cpu_command = CFE_CPU_CMD_STOP;
113
114 cfe_iocb_dispatch(&xiocb);
115
116 return xiocb.xiocb_status;
117}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119int cfe_enumenv(int idx, char *name, int namelen, char *val, int vallen)
120{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000121 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123 xiocb.xiocb_fcode = CFE_CMD_ENV_SET;
124 xiocb.xiocb_status = 0;
125 xiocb.xiocb_handle = 0;
126 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000127 xiocb.xiocb_psize = sizeof(struct xiocb_envbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 xiocb.plist.xiocb_envbuf.enum_idx = idx;
129 xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
130 xiocb.plist.xiocb_envbuf.name_length = namelen;
131 xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(val);
132 xiocb.plist.xiocb_envbuf.val_length = vallen;
133
134 cfe_iocb_dispatch(&xiocb);
135
136 return xiocb.xiocb_status;
137}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139int
Christoph Hellwig417345d2007-10-29 14:23:43 +0000140cfe_enummem(int idx, int flags, u64 *start, u64 *length, u64 *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000142 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 xiocb.xiocb_fcode = CFE_CMD_FW_MEMENUM;
145 xiocb.xiocb_status = 0;
146 xiocb.xiocb_handle = 0;
147 xiocb.xiocb_flags = flags;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000148 xiocb.xiocb_psize = sizeof(struct xiocb_meminfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 xiocb.plist.xiocb_meminfo.mi_idx = idx;
150
151 cfe_iocb_dispatch(&xiocb);
152
153 if (xiocb.xiocb_status < 0)
154 return xiocb.xiocb_status;
155
156 *start = xiocb.plist.xiocb_meminfo.mi_addr;
157 *length = xiocb.plist.xiocb_meminfo.mi_size;
158 *type = xiocb.plist.xiocb_meminfo.mi_type;
159
160 return 0;
161}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163int cfe_exit(int warm, int status)
164{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000165 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 xiocb.xiocb_fcode = CFE_CMD_FW_RESTART;
168 xiocb.xiocb_status = 0;
169 xiocb.xiocb_handle = 0;
170 xiocb.xiocb_flags = warm ? CFE_FLG_WARMSTART : 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000171 xiocb.xiocb_psize = sizeof(struct xiocb_exitstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 xiocb.plist.xiocb_exitstat.status = status;
173
174 cfe_iocb_dispatch(&xiocb);
175
176 return xiocb.xiocb_status;
177}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179int cfe_flushcache(int flg)
180{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000181 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 xiocb.xiocb_fcode = CFE_CMD_FW_FLUSHCACHE;
184 xiocb.xiocb_status = 0;
185 xiocb.xiocb_handle = 0;
186 xiocb.xiocb_flags = flg;
187 xiocb.xiocb_psize = 0;
188
189 cfe_iocb_dispatch(&xiocb);
190
191 return xiocb.xiocb_status;
192}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194int cfe_getdevinfo(char *name)
195{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000196 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 xiocb.xiocb_fcode = CFE_CMD_DEV_GETINFO;
199 xiocb.xiocb_status = 0;
200 xiocb.xiocb_handle = 0;
201 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000202 xiocb.xiocb_psize = sizeof(struct xiocb_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 xiocb.plist.xiocb_buffer.buf_offset = 0;
204 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(name);
Christoph Hellwig417345d2007-10-29 14:23:43 +0000205 xiocb.plist.xiocb_buffer.buf_length = strlen(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207 cfe_iocb_dispatch(&xiocb);
208
209 if (xiocb.xiocb_status < 0)
210 return xiocb.xiocb_status;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000211 return xiocb.plist.xiocb_buffer.buf_ioctlcmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214int cfe_getenv(char *name, char *dest, int destlen)
215{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000216 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218 *dest = 0;
219
220 xiocb.xiocb_fcode = CFE_CMD_ENV_GET;
221 xiocb.xiocb_status = 0;
222 xiocb.xiocb_handle = 0;
223 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000224 xiocb.xiocb_psize = sizeof(struct xiocb_envbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 xiocb.plist.xiocb_envbuf.enum_idx = 0;
226 xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
Christoph Hellwig417345d2007-10-29 14:23:43 +0000227 xiocb.plist.xiocb_envbuf.name_length = strlen(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(dest);
229 xiocb.plist.xiocb_envbuf.val_length = destlen;
230
231 cfe_iocb_dispatch(&xiocb);
232
233 return xiocb.xiocb_status;
234}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236int cfe_getfwinfo(cfe_fwinfo_t * info)
237{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000238 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 xiocb.xiocb_fcode = CFE_CMD_FW_GETINFO;
241 xiocb.xiocb_status = 0;
242 xiocb.xiocb_handle = 0;
243 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000244 xiocb.xiocb_psize = sizeof(struct xiocb_fwinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246 cfe_iocb_dispatch(&xiocb);
247
248 if (xiocb.xiocb_status < 0)
249 return xiocb.xiocb_status;
250
251 info->fwi_version = xiocb.plist.xiocb_fwinfo.fwi_version;
252 info->fwi_totalmem = xiocb.plist.xiocb_fwinfo.fwi_totalmem;
253 info->fwi_flags = xiocb.plist.xiocb_fwinfo.fwi_flags;
254 info->fwi_boardid = xiocb.plist.xiocb_fwinfo.fwi_boardid;
255 info->fwi_bootarea_va = xiocb.plist.xiocb_fwinfo.fwi_bootarea_va;
256 info->fwi_bootarea_pa = xiocb.plist.xiocb_fwinfo.fwi_bootarea_pa;
257 info->fwi_bootarea_size =
258 xiocb.plist.xiocb_fwinfo.fwi_bootarea_size;
259#if 0
260 info->fwi_reserved1 = xiocb.plist.xiocb_fwinfo.fwi_reserved1;
261 info->fwi_reserved2 = xiocb.plist.xiocb_fwinfo.fwi_reserved2;
262 info->fwi_reserved3 = xiocb.plist.xiocb_fwinfo.fwi_reserved3;
263#endif
264
265 return 0;
266}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268int cfe_getstdhandle(int flg)
269{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000270 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272 xiocb.xiocb_fcode = CFE_CMD_DEV_GETHANDLE;
273 xiocb.xiocb_status = 0;
274 xiocb.xiocb_handle = 0;
275 xiocb.xiocb_flags = flg;
276 xiocb.xiocb_psize = 0;
277
278 cfe_iocb_dispatch(&xiocb);
279
280 if (xiocb.xiocb_status < 0)
281 return xiocb.xiocb_status;
282 return xiocb.xiocb_handle;
283}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285int64_t
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286cfe_getticks(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000288 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290 xiocb.xiocb_fcode = CFE_CMD_FW_GETTIME;
291 xiocb.xiocb_status = 0;
292 xiocb.xiocb_handle = 0;
293 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000294 xiocb.xiocb_psize = sizeof(struct xiocb_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 xiocb.plist.xiocb_time.ticks = 0;
296
297 cfe_iocb_dispatch(&xiocb);
298
299 return xiocb.plist.xiocb_time.ticks;
300
301}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303int cfe_inpstat(int handle)
304{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000305 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 xiocb.xiocb_fcode = CFE_CMD_DEV_INPSTAT;
308 xiocb.xiocb_status = 0;
309 xiocb.xiocb_handle = handle;
310 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000311 xiocb.xiocb_psize = sizeof(struct xiocb_inpstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 xiocb.plist.xiocb_inpstat.inp_status = 0;
313
314 cfe_iocb_dispatch(&xiocb);
315
316 if (xiocb.xiocb_status < 0)
317 return xiocb.xiocb_status;
318 return xiocb.plist.xiocb_inpstat.inp_status;
319}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321int
322cfe_ioctl(int handle, unsigned int ioctlnum, unsigned char *buffer,
Christoph Hellwig417345d2007-10-29 14:23:43 +0000323 int length, int *retlen, u64 offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000325 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 xiocb.xiocb_fcode = CFE_CMD_DEV_IOCTL;
328 xiocb.xiocb_status = 0;
329 xiocb.xiocb_handle = handle;
330 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000331 xiocb.xiocb_psize = sizeof(struct xiocb_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 xiocb.plist.xiocb_buffer.buf_offset = offset;
333 xiocb.plist.xiocb_buffer.buf_ioctlcmd = ioctlnum;
334 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
335 xiocb.plist.xiocb_buffer.buf_length = length;
336
337 cfe_iocb_dispatch(&xiocb);
338
339 if (retlen)
340 *retlen = xiocb.plist.xiocb_buffer.buf_retlen;
341 return xiocb.xiocb_status;
342}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344int cfe_open(char *name)
345{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000346 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 xiocb.xiocb_fcode = CFE_CMD_DEV_OPEN;
349 xiocb.xiocb_status = 0;
350 xiocb.xiocb_handle = 0;
351 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000352 xiocb.xiocb_psize = sizeof(struct xiocb_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 xiocb.plist.xiocb_buffer.buf_offset = 0;
354 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(name);
Christoph Hellwig417345d2007-10-29 14:23:43 +0000355 xiocb.plist.xiocb_buffer.buf_length = strlen(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 cfe_iocb_dispatch(&xiocb);
358
359 if (xiocb.xiocb_status < 0)
360 return xiocb.xiocb_status;
361 return xiocb.xiocb_handle;
362}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364int cfe_read(int handle, unsigned char *buffer, int length)
365{
366 return cfe_readblk(handle, 0, buffer, length);
367}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Christoph Hellwig417345d2007-10-29 14:23:43 +0000369int cfe_readblk(int handle, s64 offset, unsigned char *buffer, int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000371 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 xiocb.xiocb_fcode = CFE_CMD_DEV_READ;
374 xiocb.xiocb_status = 0;
375 xiocb.xiocb_handle = handle;
376 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000377 xiocb.xiocb_psize = sizeof(struct xiocb_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 xiocb.plist.xiocb_buffer.buf_offset = offset;
379 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
380 xiocb.plist.xiocb_buffer.buf_length = length;
381
382 cfe_iocb_dispatch(&xiocb);
383
384 if (xiocb.xiocb_status < 0)
385 return xiocb.xiocb_status;
386 return xiocb.plist.xiocb_buffer.buf_retlen;
387}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389int cfe_setenv(char *name, char *val)
390{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000391 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 xiocb.xiocb_fcode = CFE_CMD_ENV_SET;
394 xiocb.xiocb_status = 0;
395 xiocb.xiocb_handle = 0;
396 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000397 xiocb.xiocb_psize = sizeof(struct xiocb_envbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 xiocb.plist.xiocb_envbuf.enum_idx = 0;
399 xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
Christoph Hellwig417345d2007-10-29 14:23:43 +0000400 xiocb.plist.xiocb_envbuf.name_length = strlen(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(val);
Christoph Hellwig417345d2007-10-29 14:23:43 +0000402 xiocb.plist.xiocb_envbuf.val_length = strlen(val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 cfe_iocb_dispatch(&xiocb);
405
406 return xiocb.xiocb_status;
407}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409int cfe_write(int handle, unsigned char *buffer, int length)
410{
411 return cfe_writeblk(handle, 0, buffer, length);
412}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Christoph Hellwig417345d2007-10-29 14:23:43 +0000414int cfe_writeblk(int handle, s64 offset, unsigned char *buffer, int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
Christoph Hellwig417345d2007-10-29 14:23:43 +0000416 struct cfe_xiocb xiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 xiocb.xiocb_fcode = CFE_CMD_DEV_WRITE;
419 xiocb.xiocb_status = 0;
420 xiocb.xiocb_handle = handle;
421 xiocb.xiocb_flags = 0;
Christoph Hellwig417345d2007-10-29 14:23:43 +0000422 xiocb.xiocb_psize = sizeof(struct xiocb_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 xiocb.plist.xiocb_buffer.buf_offset = offset;
424 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
425 xiocb.plist.xiocb_buffer.buf_length = length;
426
427 cfe_iocb_dispatch(&xiocb);
428
429 if (xiocb.xiocb_status < 0)
430 return xiocb.xiocb_status;
431 return xiocb.plist.xiocb_buffer.buf_retlen;
432}