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 182732 2008-09-03 17:48:41Z 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
219
220#define MR_MAX 5
221static struct mem_region mr[MR_MAX];
222static struct sys_info si;
223
224struct sys_info *
225ub_get_sys_info(void)
226{
227 int err = 0;
228
229 memset(&si, 0, sizeof(struct sys_info));
230 si.mr = mr;
231 si.mr_no = MR_MAX;
232 memset(&mr, 0, sizeof(mr));
233
234 if (!syscall(API_GET_SYS_INFO, &err, (u_int32_t)&si))
235 return (NULL);
236
237 return ((err) ? NULL : &si);
238}
239

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

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

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

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

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

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

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

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

--- 138 unchanged lines hidden ---