Blame view

api/api.c 14.1 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
500856eb1   Rafal Jaworowski   API for external ...
2
3
4
5
  /*
   * (C) Copyright 2007 Semihalf
   *
   * Written by: Rafal Jaworowski <raj@semihalf.com>
500856eb1   Rafal Jaworowski   API for external ...
6
7
8
   */
  
  #include <config.h>
500856eb1   Rafal Jaworowski   API for external ...
9
10
11
  #include <command.h>
  #include <common.h>
  #include <malloc.h>
a8409f4f1   Wolfgang Denk   environment: clea...
12
  #include <environment.h>
500856eb1   Rafal Jaworowski   API for external ...
13
14
15
16
17
18
19
  #include <linux/types.h>
  #include <api_public.h>
  
  #include "api_private.h"
  
  #define DEBUG
  #undef DEBUG
500856eb1   Rafal Jaworowski   API for external ...
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  /*****************************************************************************
   *
   * This is the API core.
   *
   * API_ functions are part of U-Boot code and constitute the lowest level
   * calls:
   *
   *  - they know what values they need as arguments
   *  - their direct return value pertains to the API_ "shell" itself (0 on
   *    success, some error code otherwise)
   *  - if the call returns a value it is buried within arguments
   *
   ****************************************************************************/
  
  #ifdef DEBUG
  #define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt, ##args); } while (0)
  #else
  #define debugf(fmt, args...)
  #endif
  
  typedef	int (*cfp_t)(va_list argp);
  
  static int calls_no;
  
  /*
   * pseudo signature:
   *
   * int API_getc(int *c)
   */
  static int API_getc(va_list ap)
  {
  	int *c;
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
52
  	if ((c = (int *)va_arg(ap, uintptr_t)) == NULL)
500856eb1   Rafal Jaworowski   API for external ...
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  		return API_EINVAL;
  
  	*c = getc();
  	return 0;
  }
  
  /*
   * pseudo signature:
   *
   * int API_tstc(int *c)
   */
  static int API_tstc(va_list ap)
  {
  	int *t;
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
67
  	if ((t = (int *)va_arg(ap, uintptr_t)) == NULL)
500856eb1   Rafal Jaworowski   API for external ...
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  		return API_EINVAL;
  
  	*t = tstc();
  	return 0;
  }
  
  /*
   * pseudo signature:
   *
   * int API_putc(char *ch)
   */
  static int API_putc(va_list ap)
  {
  	char *c;
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
82
  	if ((c = (char *)va_arg(ap, uintptr_t)) == NULL)
500856eb1   Rafal Jaworowski   API for external ...
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  		return API_EINVAL;
  
  	putc(*c);
  	return 0;
  }
  
  /*
   * pseudo signature:
   *
   * int API_puts(char **s)
   */
  static int API_puts(va_list ap)
  {
  	char *s;
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
97
  	if ((s = (char *)va_arg(ap, uintptr_t)) == NULL)
500856eb1   Rafal Jaworowski   API for external ...
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  		return API_EINVAL;
  
  	puts(s);
  	return 0;
  }
  
  /*
   * pseudo signature:
   *
   * int API_reset(void)
   */
  static int API_reset(va_list ap)
  {
  	do_reset(NULL, 0, 0, NULL);
  
  	/* NOT REACHED */
  	return 0;
  }
  
  /*
   * pseudo signature:
   *
   * int API_get_sys_info(struct sys_info *si)
   *
   * fill out the sys_info struct containing selected parameters about the
   * machine
   */
  static int API_get_sys_info(va_list ap)
  {
  	struct sys_info *si;
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
128
  	si = (struct sys_info *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
  	if (si == NULL)
  		return API_ENOMEM;
  
  	return (platform_sys_info(si)) ? 0 : API_ENODEV;
  }
  
  /*
   * pseudo signature:
   *
   * int API_udelay(unsigned long *udelay)
   */
  static int API_udelay(va_list ap)
  {
  	unsigned long *d;
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
143
  	if ((d = (unsigned long *)va_arg(ap, unsigned long)) == NULL)
500856eb1   Rafal Jaworowski   API for external ...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
  		return API_EINVAL;
  
  	udelay(*d);
  	return 0;
  }
  
  /*
   * pseudo signature:
   *
   * int API_get_timer(unsigned long *current, unsigned long *base)
   */
  static int API_get_timer(va_list ap)
  {
  	unsigned long *base, *cur;
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
158
  	cur = (unsigned long *)va_arg(ap, unsigned long);
500856eb1   Rafal Jaworowski   API for external ...
159
160
  	if (cur == NULL)
  		return API_EINVAL;
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
161
  	base = (unsigned long *)va_arg(ap, unsigned long);
500856eb1   Rafal Jaworowski   API for external ...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
  	if (base == NULL)
  		return API_EINVAL;
  
  	*cur = get_timer(*base);
  	return 0;
  }
  
  
  /*****************************************************************************
   *
   * pseudo signature:
   *
   * int API_dev_enum(struct device_info *)
   *
   *
   * cookies uniqely identify the previously enumerated device instance and
   * provide a hint for what to inspect in current enum iteration:
   *
   *   - net: &eth_device struct address from list pointed to by eth_devices
   *
4101f6879   Simon Glass   dm: Drop the bloc...
182
   *   - storage: struct blk_desc struct address from &ide_dev_desc[n],
500856eb1   Rafal Jaworowski   API for external ...
183
184
185
186
187
188
189
190
191
   *     &scsi_dev_desc[n] and similar tables
   *
   ****************************************************************************/
  
  static int API_dev_enum(va_list ap)
  {
  	struct device_info *di;
  
  	/* arg is ptr to the device_info struct we are going to fill out */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
192
  	di = (struct device_info *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
193
194
195
196
197
198
199
200
  	if (di == NULL)
  		return API_EINVAL;
  
  	if (di->cookie == NULL) {
  		/* start over - clean up enumeration */
  		dev_enum_reset();	/* XXX shouldn't the name contain 'stor'? */
  		debugf("RESTART ENUM
  ");
d3a6532cb   Wolfgang Denk   Coding Style clea...
201

500856eb1   Rafal Jaworowski   API for external ...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  		/* net device enumeration first */
  		if (dev_enum_net(di))
  			return 0;
  	}
  
  	/*
  	 * The hidden assumption is there can only be one active network
  	 * device and it is identified upon enumeration (re)start, so there's
  	 * no point in trying to find network devices in other cases than the
  	 * (re)start and hence the 'next' device can only be storage
  	 */
  	if (!dev_enum_storage(di))
  		/* make sure we mark there are no more devices */
  		di->cookie = NULL;
  
  	return 0;
  }
  
  
  static int API_dev_open(va_list ap)
  {
  	struct device_info *di;
  	int err = 0;
  
  	/* arg is ptr to the device_info struct */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
227
  	di = (struct device_info *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
  	if (di == NULL)
  		return API_EINVAL;
  
  	/* Allow only one consumer of the device at a time */
  	if (di->state == DEV_STA_OPEN)
  		return API_EBUSY;
  
  	if (di->cookie == NULL)
  		return API_ENODEV;
  
  	if (di->type & DEV_TYP_STOR)
  		err = dev_open_stor(di->cookie);
  
  	else if (di->type & DEV_TYP_NET)
  		err = dev_open_net(di->cookie);
  	else
  		err = API_ENODEV;
  
  	if (!err)
  		di->state = DEV_STA_OPEN;
  
  	return err;
  }
  
  
  static int API_dev_close(va_list ap)
  {
  	struct device_info *di;
  	int err = 0;
  
  	/* arg is ptr to the device_info struct */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
259
  	di = (struct device_info *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
  	if (di == NULL)
  		return API_EINVAL;
  
  	if (di->state == DEV_STA_CLOSED)
  		return 0;
  
  	if (di->cookie == NULL)
  		return API_ENODEV;
  
  	if (di->type & DEV_TYP_STOR)
  		err = dev_close_stor(di->cookie);
  
  	else if (di->type & DEV_TYP_NET)
  		err = dev_close_net(di->cookie);
  	else
  		/*
  		 * In case of unknown device we cannot change its state, so
  		 * only return error code
  		 */
  		err = API_ENODEV;
  
  	if (!err)
  		di->state = DEV_STA_CLOSED;
  
  	return err;
  }
  
  
  /*
   * Notice: this is for sending network packets only, as U-Boot does not
   * support writing to storage at the moment (12.2007)
   *
   * pseudo signature:
   *
   * int API_dev_write(
   *	struct device_info *di,
   *	void *buf,
   *	int *len
   * )
   *
   * buf:	ptr to buffer from where to get the data to send
   *
   * len: length of packet to be sent (in bytes)
   *
   */
  static int API_dev_write(va_list ap)
  {
  	struct device_info *di;
  	void *buf;
  	int *len;
  	int err = 0;
  
  	/* 1. arg is ptr to the device_info struct */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
313
  	di = (struct device_info *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
314
315
316
317
318
319
320
321
322
  	if (di == NULL)
  		return API_EINVAL;
  
  	/* XXX should we check if device is open? i.e. the ->state ? */
  
  	if (di->cookie == NULL)
  		return API_ENODEV;
  
  	/* 2. arg is ptr to buffer from where to get data to write */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
323
  	buf = (void *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
324
325
326
327
  	if (buf == NULL)
  		return API_EINVAL;
  
  	/* 3. arg is length of buffer */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
328
  	len = (int *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
329
330
331
332
333
334
  	if (len == NULL)
  		return API_EINVAL;
  	if (*len <= 0)
  		return API_EINVAL;
  
  	if (di->type & DEV_TYP_STOR)
d3a6532cb   Wolfgang Denk   Coding Style clea...
335
  		/*
500856eb1   Rafal Jaworowski   API for external ...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
  		 * write to storage is currently not supported by U-Boot:
  		 * no storage device implements block_write() method
  		 */
  		return API_ENODEV;
  
  	else if (di->type & DEV_TYP_NET)
  		err = dev_write_net(di->cookie, buf, *len);
  	else
  		err = API_ENODEV;
  
  	return err;
  }
  
  
  /*
   * pseudo signature:
   *
   * int API_dev_read(
   *	struct device_info *di,
   *	void *buf,
   *	size_t *len,
   *	unsigned long *start
   *	size_t *act_len
   * )
   *
   * buf:	ptr to buffer where to put the read data
   *
   * len: ptr to length to be read
   *      - network: len of packet to read (in bytes)
   *      - storage: # of blocks to read (can vary in size depending on define)
   *
   * start: ptr to start block (only used for storage devices, ignored for
   *        network)
   *
   * act_len: ptr to where to put the len actually read
   */
  static int API_dev_read(va_list ap)
  {
  	struct device_info *di;
  	void *buf;
  	lbasize_t *len_stor, *act_len_stor;
  	lbastart_t *start;
  	int *len_net, *act_len_net;
  
  	/* 1. arg is ptr to the device_info struct */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
381
  	di = (struct device_info *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
382
383
384
385
386
387
388
389
390
  	if (di == NULL)
  		return API_EINVAL;
  
  	/* XXX should we check if device is open? i.e. the ->state ? */
  
  	if (di->cookie == NULL)
  		return API_ENODEV;
  
  	/* 2. arg is ptr to buffer from where to put the read data */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
391
  	buf = (void *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
392
393
394
395
396
  	if (buf == NULL)
  		return API_EINVAL;
  
  	if (di->type & DEV_TYP_STOR) {
  		/* 3. arg - ptr to var with # of blocks to read */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
397
  		len_stor = (lbasize_t *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
398
399
400
401
402
403
  		if (!len_stor)
  			return API_EINVAL;
  		if (*len_stor <= 0)
  			return API_EINVAL;
  
  		/* 4. arg - ptr to var with start block */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
404
  		start = (lbastart_t *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
405
406
  
  		/* 5. arg - ptr to var where to put the len actually read */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
407
  		act_len_stor = (lbasize_t *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
408
409
410
411
412
413
414
415
  		if (!act_len_stor)
  			return API_EINVAL;
  
  		*act_len_stor = dev_read_stor(di->cookie, buf, *len_stor, *start);
  
  	} else if (di->type & DEV_TYP_NET) {
  
  		/* 3. arg points to the var with length of packet to read */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
416
  		len_net = (int *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
417
418
419
420
421
422
  		if (!len_net)
  			return API_EINVAL;
  		if (*len_net <= 0)
  			return API_EINVAL;
  
  		/* 4. - ptr to var where to put the len actually read */
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
423
  		act_len_net = (int *)va_arg(ap, uintptr_t);
500856eb1   Rafal Jaworowski   API for external ...
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
  		if (!act_len_net)
  			return API_EINVAL;
  
  		*act_len_net = dev_read_net(di->cookie, buf, *len_net);
  
  	} else
  		return API_ENODEV;
  
  	return 0;
  }
  
  
  /*
   * pseudo signature:
   *
   * int API_env_get(const char *name, char **value)
   *
   * name: ptr to name of env var
   */
  static int API_env_get(va_list ap)
  {
  	char *name, **value;
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
446
  	if ((name = (char *)va_arg(ap, uintptr_t)) == NULL)
500856eb1   Rafal Jaworowski   API for external ...
447
  		return API_EINVAL;
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
448
  	if ((value = (char **)va_arg(ap, uintptr_t)) == NULL)
500856eb1   Rafal Jaworowski   API for external ...
449
  		return API_EINVAL;
00caae6d4   Simon Glass   env: Rename geten...
450
  	*value = env_get(name);
500856eb1   Rafal Jaworowski   API for external ...
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
  
  	return 0;
  }
  
  /*
   * pseudo signature:
   *
   * int API_env_set(const char *name, const char *value)
   *
   * name: ptr to name of env var
   *
   * value: ptr to value to be set
   */
  static int API_env_set(va_list ap)
  {
  	char *name, *value;
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
467
  	if ((name = (char *)va_arg(ap, uintptr_t)) == NULL)
500856eb1   Rafal Jaworowski   API for external ...
468
  		return API_EINVAL;
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
469
  	if ((value = (char *)va_arg(ap, uintptr_t)) == NULL)
500856eb1   Rafal Jaworowski   API for external ...
470
  		return API_EINVAL;
382bee57f   Simon Glass   env: Rename seten...
471
  	env_set(name, value);
500856eb1   Rafal Jaworowski   API for external ...
472
473
474
475
476
477
478
479
480
481
482
483
484
  
  	return 0;
  }
  
  /*
   * pseudo signature:
   *
   * int API_env_enum(const char *last, char **next)
   *
   * last: ptr to name of env var found in last iteration
   */
  static int API_env_enum(va_list ap)
  {
6215bd4c1   Emmanuel Vadot   api: Use hashtabl...
485
486
487
488
  	int i, buflen;
  	char *last, **next, *s;
  	ENTRY *match, search;
  	static char *var;
500856eb1   Rafal Jaworowski   API for external ...
489

78757d52c   Stanislav Galabov   Fix FreeBSD loade...
490
  	last = (char *)va_arg(ap, unsigned long);
d3a6532cb   Wolfgang Denk   Coding Style clea...
491

78757d52c   Stanislav Galabov   Fix FreeBSD loade...
492
  	if ((next = (char **)va_arg(ap, uintptr_t)) == NULL)
500856eb1   Rafal Jaworowski   API for external ...
493
  		return API_EINVAL;
6215bd4c1   Emmanuel Vadot   api: Use hashtabl...
494
495
496
497
498
499
500
501
502
503
504
505
506
  	if (last == NULL) {
  		var = NULL;
  		i = 0;
  	} else {
  		var = strdup(last);
  		s = strchr(var, '=');
  		if (s != NULL)
  			*s = 0;
  		search.key = var;
  		i = hsearch_r(search, FIND, &match, &env_htab, 0);
  		if (i == 0) {
  			i = API_EINVAL;
  			goto done;
500856eb1   Rafal Jaworowski   API for external ...
507
508
  		}
  	}
6215bd4c1   Emmanuel Vadot   api: Use hashtabl...
509
510
511
512
513
514
515
516
  	/* match the next entry after i */
  	i = hmatch_r("", i, &match, &env_htab);
  	if (i == 0)
  		goto done;
  	buflen = strlen(match->key) + strlen(match->data) + 2;
  	var = realloc(var, buflen);
  	snprintf(var, buflen, "%s=%s", match->key, match->data);
  	*next = var;
500856eb1   Rafal Jaworowski   API for external ...
517
  	return 0;
6215bd4c1   Emmanuel Vadot   api: Use hashtabl...
518
519
520
521
522
523
  
  done:
  	free(var);
  	var = NULL;
  	*next = NULL;
  	return i;
500856eb1   Rafal Jaworowski   API for external ...
524
  }
a2a5729fc   Che-Liang Chiou   api: export LCD d...
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
  /*
   * pseudo signature:
   *
   * int API_display_get_info(int type, struct display_info *di)
   */
  static int API_display_get_info(va_list ap)
  {
  	int type;
  	struct display_info *di;
  
  	type = va_arg(ap, int);
  	di = va_arg(ap, struct display_info *);
  
  	return display_get_info(type, di);
  }
  
  /*
   * pseudo signature:
   *
   * int API_display_draw_bitmap(ulong bitmap, int x, int y)
   */
  static int API_display_draw_bitmap(va_list ap)
  {
  	ulong bitmap;
  	int x, y;
  
  	bitmap = va_arg(ap, ulong);
  	x = va_arg(ap, int);
  	y = va_arg(ap, int);
  
  	return display_draw_bitmap(bitmap, x, y);
  }
  
  /*
   * pseudo signature:
   *
   * void API_display_clear(void)
   */
  static int API_display_clear(va_list ap)
  {
  	display_clear();
  	return 0;
  }
500856eb1   Rafal Jaworowski   API for external ...
568
569
570
571
572
573
574
  static cfp_t calls_table[API_MAXCALL] = { NULL, };
  
  /*
   * The main syscall entry point - this is not reentrant, only one call is
   * serviced until finished.
   *
   * e.g. syscall(1, int *, u_int32_t, u_int32_t, u_int32_t, u_int32_t);
d3a6532cb   Wolfgang Denk   Coding Style clea...
575
   *
500856eb1   Rafal Jaworowski   API for external ...
576
577
578
579
580
581
582
583
584
585
586
587
588
589
   * call:	syscall number
   *
   * retval:	points to the return value placeholder, this is the place the
   *		syscall puts its return value, if NULL the caller does not
   *		expect a return value
   *
   * ...		syscall arguments (variable number)
   *
   * returns:	0 if the call not found, 1 if serviced
   */
  int syscall(int call, int *retval, ...)
  {
  	va_list	ap;
  	int rv;
20e5ed137   Jean-Christophe PLAGNIOL-VILLARD   API: remove dupli...
590
  	if (call < 0 || call >= calls_no) {
500856eb1   Rafal Jaworowski   API for external ...
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
  		debugf("invalid call #%d
  ", call);
  		return 0;
  	}
  
  	if (calls_table[call] == NULL) {
  		debugf("syscall #%d does not have a handler
  ", call);
  		return 0;
  	}
  
  	va_start(ap, retval);
  	rv = calls_table[call](ap);
  	if (retval != NULL)
  		*retval = rv;
  
  	return 1;
  }
  
  void api_init(void)
  {
5cc9e6b7f   xypron.glpk@gmx.de   api: remove super...
612
  	struct api_signature *sig;
500856eb1   Rafal Jaworowski   API for external ...
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
  
  	/* TODO put this into linker set one day... */
  	calls_table[API_RSVD] = NULL;
  	calls_table[API_GETC] = &API_getc;
  	calls_table[API_PUTC] = &API_putc;
  	calls_table[API_TSTC] = &API_tstc;
  	calls_table[API_PUTS] = &API_puts;
  	calls_table[API_RESET] = &API_reset;
  	calls_table[API_GET_SYS_INFO] = &API_get_sys_info;
  	calls_table[API_UDELAY] = &API_udelay;
  	calls_table[API_GET_TIMER] = &API_get_timer;
  	calls_table[API_DEV_ENUM] = &API_dev_enum;
  	calls_table[API_DEV_OPEN] = &API_dev_open;
  	calls_table[API_DEV_CLOSE] = &API_dev_close;
  	calls_table[API_DEV_READ] = &API_dev_read;
  	calls_table[API_DEV_WRITE] = &API_dev_write;
  	calls_table[API_ENV_GET] = &API_env_get;
  	calls_table[API_ENV_SET] = &API_env_set;
  	calls_table[API_ENV_ENUM] = &API_env_enum;
a2a5729fc   Che-Liang Chiou   api: export LCD d...
632
633
634
  	calls_table[API_DISPLAY_GET_INFO] = &API_display_get_info;
  	calls_table[API_DISPLAY_DRAW_BITMAP] = &API_display_draw_bitmap;
  	calls_table[API_DISPLAY_CLEAR] = &API_display_clear;
500856eb1   Rafal Jaworowski   API for external ...
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
  	calls_no = API_MAXCALL;
  
  	debugf("API initialized with %d calls
  ", calls_no);
  
  	dev_stor_init();
  
  	/*
  	 * Produce the signature so the API consumers can find it
  	 */
  	sig = malloc(sizeof(struct api_signature));
  	if (sig == NULL) {
  		printf("API: could not allocate memory for the signature!
  ");
  		return;
  	}
018f53032   Simon Glass   env: Rename commo...
651
  	env_set_hex("api_address", (unsigned long)sig);
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
652
653
  	debugf("API sig @ 0x%lX
  ", (unsigned long)sig);
500856eb1   Rafal Jaworowski   API for external ...
654
655
656
657
658
659
  	memcpy(sig->magic, API_SIG_MAGIC, 8);
  	sig->version = API_SIG_VERSION;
  	sig->syscall = &syscall;
  	sig->checksum = 0;
  	sig->checksum = crc32(0, (unsigned char *)sig,
  			      sizeof(struct api_signature));
78757d52c   Stanislav Galabov   Fix FreeBSD loade...
660
661
  	debugf("syscall entry: 0x%lX
  ", (unsigned long)sig->syscall);
500856eb1   Rafal Jaworowski   API for external ...
662
663
664
665
666
667
668
669
670
  }
  
  void platform_set_mr(struct sys_info *si, unsigned long start, unsigned long size,
  			int flags)
  {
  	int i;
  
  	if (!si->mr || !size || (flags == 0))
  		return;
d3a6532cb   Wolfgang Denk   Coding Style clea...
671

500856eb1   Rafal Jaworowski   API for external ...
672
673
674
675
676
677
678
679
680
681
  	/* find free slot */
  	for (i = 0; i < si->mr_no; i++)
  		if (si->mr[i].flags == 0) {
  			/* insert new mem region */
  			si->mr[i].start = start;
  			si->mr[i].size = size;
  			si->mr[i].flags = flags;
  			return;
  		}
  }