Deleted Added
full compact
glue.c (182732) glue.c (183598)
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>
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 $");
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
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];
219static struct mem_region mr[UB_MAX_MR];
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;
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;
231 si.mr_no = MR_MAX;
229 si.mr_no = UB_MAX_MR;
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 *
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 *
270 * Devices are identified by handles: numbers 0, 1, 2, ..., MAX_DEVS-1
268 * Devices are identified by handles: numbers 0, 1, 2, ..., UB_MAX_DEV-1
271 *
272 ***************************************************************************/
273
269 *
270 ***************************************************************************/
271
274#define MAX_DEVS 6
272static struct device_info devices[UB_MAX_DEV];
275
273
276static struct device_info devices[MAX_DEVS];
277
278struct device_info *
279ub_dev_get(int i)
280{
281
274struct device_info *
275ub_dev_get(int i)
276{
277
282 return ((i < 0 || i >= MAX_DEVS) ? NULL : &devices[i]);
278 return ((i < 0 || i >= UB_MAX_DEV) ? 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
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
297 memset(&devices, 0, sizeof(struct device_info) * MAX_DEVS);
293 memset(&devices, 0, sizeof(struct device_info) * UB_MAX_DEV);
298 di = &devices[0];
299
300 if (!syscall(API_DEV_ENUM, NULL, di))
301 return (0);
302
303 while (di->cookie != NULL) {
304
294 di = &devices[0];
295
296 if (!syscall(API_DEV_ENUM, NULL, di))
297 return (0);
298
299 while (di->cookie != NULL) {
300
305 if (++n >= MAX_DEVS)
301 if (++n >= UB_MAX_DEV)
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
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
333 if (handle < 0 || handle >= MAX_DEVS)
329 if (handle < 0 || handle >= UB_MAX_DEV)
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
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
348 if (handle < 0 || handle >= MAX_DEVS)
344 if (handle < 0 || handle >= UB_MAX_DEV)
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
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
370 if (handle < 0 || handle >= MAX_DEVS)
366 if (handle < 0 || handle >= UB_MAX_DEV)
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
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
393ub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start)
389ub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start,
390 lbasize_t *rlen)
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))
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))
404 return (-1);
401 return (API_ESYSC);
405
402
406 if (err)
407 return (err);
403 if (!err && rlen)
404 *rlen = act_len;
408
405
409 if (act_len != len)
410 return (API_EIO);
411
412 return (0);
406 return (err);
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
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
429ub_dev_recv(int handle, void *buf, int len)
423ub_dev_recv(int handle, void *buf, int len, int *rlen)
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))
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))
439 return (-1);
433 return (API_ESYSC);
440
434
441 if (err)
442 return (-1);
435 if (!err)
436 *rlen = act_len;
443
437
444 return (act_len);
438 return (err);
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))
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))
458 return (-1);
452 return (API_ESYSC);
459
460 return (err);
461}
462
463static char *
464ub_stor_type(int type)
465{
466

--- 138 unchanged lines hidden ---
453
454 return (err);
455}
456
457static char *
458ub_stor_type(int type)
459{
460

--- 138 unchanged lines hidden ---