Deleted Added
sdiff udiff text old ( 182732 ) new ( 183598 )
full compact
1/*-
2 * Copyright (c) 2007-2008 Semihalf, Rafal Jaworowski <raj@semihalf.com>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/boot/uboot/lib/glue.c 183598 2008-10-04 13:10:38Z raj $");
29
30#include <stand.h>
31#include "api_public.h"
32#include "glue.h"
33
34#define DEBUG
35#undef DEBUG
36

--- 174 unchanged lines hidden (view full) ---

211
212void
213ub_reset(void)
214{
215
216 syscall(API_RESET, NULL);
217}
218
219static struct mem_region mr[UB_MAX_MR];
220static struct sys_info si;
221
222struct sys_info *
223ub_get_sys_info(void)
224{
225 int err = 0;
226
227 memset(&si, 0, sizeof(struct sys_info));
228 si.mr = mr;
229 si.mr_no = UB_MAX_MR;
230 memset(&mr, 0, sizeof(mr));
231
232 if (!syscall(API_GET_SYS_INFO, &err, (u_int32_t)&si))
233 return (NULL);
234
235 return ((err) ? NULL : &si);
236}
237

--- 22 unchanged lines hidden (view full) ---

260 return (cur);
261}
262
263
264/****************************************************************************
265 *
266 * devices
267 *
268 * Devices are identified by handles: numbers 0, 1, 2, ..., UB_MAX_DEV-1
269 *
270 ***************************************************************************/
271
272static struct device_info devices[UB_MAX_DEV];
273
274struct device_info *
275ub_dev_get(int i)
276{
277
278 return ((i < 0 || i >= UB_MAX_DEV) ? NULL : &devices[i]);
279}
280
281/*
282 * Enumerates the devices: fills out device_info elements in the devices[]
283 * array.
284 *
285 * returns: number of devices found
286 */
287int
288ub_dev_enum(void)
289{
290 struct device_info *di;
291 int n = 0;
292
293 memset(&devices, 0, sizeof(struct device_info) * UB_MAX_DEV);
294 di = &devices[0];
295
296 if (!syscall(API_DEV_ENUM, NULL, di))
297 return (0);
298
299 while (di->cookie != NULL) {
300
301 if (++n >= UB_MAX_DEV)
302 break;
303
304 /* take another device_info */
305 di++;
306
307 /* pass on the previous cookie */
308 di->cookie = devices[n - 1].cookie;
309

--- 11 unchanged lines hidden (view full) ---

321 * returns: 0 when OK, err otherwise
322 */
323int
324ub_dev_open(int handle)
325{
326 struct device_info *di;
327 int err = 0;
328
329 if (handle < 0 || handle >= UB_MAX_DEV)
330 return (API_EINVAL);
331
332 di = &devices[handle];
333 if (!syscall(API_DEV_OPEN, &err, di))
334 return (-1);
335
336 return (err);
337}
338
339int
340ub_dev_close(int handle)
341{
342 struct device_info *di;
343
344 if (handle < 0 || handle >= UB_MAX_DEV)
345 return (API_EINVAL);
346
347 di = &devices[handle];
348 if (!syscall(API_DEV_CLOSE, NULL, di))
349 return (-1);
350
351 return (0);
352}

--- 5 unchanged lines hidden (view full) ---

358 * - be opened
359 *
360 * returns: 0/1 accordingly
361 */
362static int
363dev_valid(int handle)
364{
365
366 if (handle < 0 || handle >= UB_MAX_DEV)
367 return (0);
368
369 if (devices[handle].state != DEV_STA_OPEN)
370 return (0);
371
372 return (1);
373}
374

--- 6 unchanged lines hidden (view full) ---

381
382 if (!(devices[handle].type & DEV_TYP_STOR))
383 return (0);
384
385 return (1);
386}
387
388int
389ub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start,
390 lbasize_t *rlen)
391{
392 struct device_info *di;
393 lbasize_t act_len;
394 int err = 0;
395
396 if (!dev_stor_valid(handle))
397 return (API_ENODEV);
398
399 di = &devices[handle];
400 if (!syscall(API_DEV_READ, &err, di, buf, &len, &start, &act_len))
401 return (API_ESYSC);
402
403 if (!err && rlen)
404 *rlen = act_len;
405
406 return (err);
407}
408
409static int
410dev_net_valid(int handle)
411{
412
413 if (!dev_valid(handle))
414 return (0);
415
416 if (devices[handle].type != DEV_TYP_NET)
417 return (0);
418
419 return (1);
420}
421
422int
423ub_dev_recv(int handle, void *buf, int len, int *rlen)
424{
425 struct device_info *di;
426 int err = 0, act_len;
427
428 if (!dev_net_valid(handle))
429 return (API_ENODEV);
430
431 di = &devices[handle];
432 if (!syscall(API_DEV_READ, &err, di, buf, &len, &act_len))
433 return (API_ESYSC);
434
435 if (!err)
436 *rlen = act_len;
437
438 return (err);
439}
440
441int
442ub_dev_send(int handle, void *buf, int len)
443{
444 struct device_info *di;
445 int err = 0;
446
447 if (!dev_net_valid(handle))
448 return (API_ENODEV);
449
450 di = &devices[handle];
451 if (!syscall(API_DEV_WRITE, &err, di, buf, &len))
452 return (API_ESYSC);
453
454 return (err);
455}
456
457static char *
458ub_stor_type(int type)
459{
460

--- 138 unchanged lines hidden ---