X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=api%2Fapi.c;h=9f03f1a35bb2511fd8a69a615c91e05d991a90e6;hb=38cad04e2d07d5833114831d6f92c759a9253fe7;hp=10f83eb691c85afe8ee817f72035ef140d78142a;hpb=ecc198c9b9522aa766235b7780f8ef7e01d0d0e2;p=u-boot diff --git a/api/api.c b/api/api.c index 10f83eb691..9f03f1a35b 100644 --- a/api/api.c +++ b/api/api.c @@ -1,35 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2007 Semihalf * * Written by: Rafal Jaworowski - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - * */ #include - -#if defined(CONFIG_API) - #include #include #include +#include #include #include @@ -38,11 +18,6 @@ #define DEBUG #undef DEBUG -/* U-Boot routines needed */ -extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); -extern uchar (*env_get_char)(int); -extern uchar *env_get_addr(int); - /***************************************************************************** * * This is the API core. @@ -76,7 +51,7 @@ static int API_getc(va_list ap) { int *c; - if ((c = (int *)va_arg(ap, u_int32_t)) == NULL) + if ((c = (int *)va_arg(ap, uintptr_t)) == NULL) return API_EINVAL; *c = getc(); @@ -92,7 +67,7 @@ static int API_tstc(va_list ap) { int *t; - if ((t = (int *)va_arg(ap, u_int32_t)) == NULL) + if ((t = (int *)va_arg(ap, uintptr_t)) == NULL) return API_EINVAL; *t = tstc(); @@ -108,7 +83,7 @@ static int API_putc(va_list ap) { char *c; - if ((c = (char *)va_arg(ap, u_int32_t)) == NULL) + if ((c = (char *)va_arg(ap, uintptr_t)) == NULL) return API_EINVAL; putc(*c); @@ -124,7 +99,7 @@ static int API_puts(va_list ap) { char *s; - if ((s = (char *)va_arg(ap, u_int32_t)) == NULL) + if ((s = (char *)va_arg(ap, uintptr_t)) == NULL) return API_EINVAL; puts(s); @@ -156,7 +131,7 @@ static int API_get_sys_info(va_list ap) { struct sys_info *si; - si = (struct sys_info *)va_arg(ap, u_int32_t); + si = (struct sys_info *)va_arg(ap, uintptr_t); if (si == NULL) return API_ENOMEM; @@ -172,7 +147,7 @@ static int API_udelay(va_list ap) { unsigned long *d; - if ((d = (unsigned long *)va_arg(ap, u_int32_t)) == NULL) + if ((d = (unsigned long *)va_arg(ap, unsigned long)) == NULL) return API_EINVAL; udelay(*d); @@ -188,11 +163,11 @@ static int API_get_timer(va_list ap) { unsigned long *base, *cur; - cur = (unsigned long *)va_arg(ap, u_int32_t); + cur = (unsigned long *)va_arg(ap, unsigned long); if (cur == NULL) return API_EINVAL; - base = (unsigned long *)va_arg(ap, u_int32_t); + base = (unsigned long *)va_arg(ap, unsigned long); if (base == NULL) return API_EINVAL; @@ -213,7 +188,7 @@ static int API_get_timer(va_list ap) * * - net: ð_device struct address from list pointed to by eth_devices * - * - storage: block_dev_desc_t struct address from &ide_dev_desc[n], + * - storage: struct blk_desc struct address from &ide_dev_desc[n], * &scsi_dev_desc[n] and similar tables * ****************************************************************************/ @@ -223,7 +198,7 @@ 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 */ - di = (struct device_info *)va_arg(ap, u_int32_t); + di = (struct device_info *)va_arg(ap, uintptr_t); if (di == NULL) return API_EINVAL; @@ -231,7 +206,7 @@ static int API_dev_enum(va_list ap) /* start over - clean up enumeration */ dev_enum_reset(); /* XXX shouldn't the name contain 'stor'? */ debugf("RESTART ENUM\n"); - + /* net device enumeration first */ if (dev_enum_net(di)) return 0; @@ -257,7 +232,7 @@ static int API_dev_open(va_list ap) int err = 0; /* arg is ptr to the device_info struct */ - di = (struct device_info *)va_arg(ap, u_int32_t); + di = (struct device_info *)va_arg(ap, uintptr_t); if (di == NULL) return API_EINVAL; @@ -289,7 +264,7 @@ static int API_dev_close(va_list ap) int err = 0; /* arg is ptr to the device_info struct */ - di = (struct device_info *)va_arg(ap, u_int32_t); + di = (struct device_info *)va_arg(ap, uintptr_t); if (di == NULL) return API_EINVAL; @@ -343,7 +318,7 @@ static int API_dev_write(va_list ap) int err = 0; /* 1. arg is ptr to the device_info struct */ - di = (struct device_info *)va_arg(ap, u_int32_t); + di = (struct device_info *)va_arg(ap, uintptr_t); if (di == NULL) return API_EINVAL; @@ -353,19 +328,19 @@ static int API_dev_write(va_list ap) return API_ENODEV; /* 2. arg is ptr to buffer from where to get data to write */ - buf = (void *)va_arg(ap, u_int32_t); + buf = (void *)va_arg(ap, uintptr_t); if (buf == NULL) return API_EINVAL; /* 3. arg is length of buffer */ - len = (int *)va_arg(ap, u_int32_t); + len = (int *)va_arg(ap, uintptr_t); if (len == NULL) return API_EINVAL; if (*len <= 0) return API_EINVAL; if (di->type & DEV_TYP_STOR) - /* + /* * write to storage is currently not supported by U-Boot: * no storage device implements block_write() method */ @@ -411,7 +386,7 @@ static int API_dev_read(va_list ap) int *len_net, *act_len_net; /* 1. arg is ptr to the device_info struct */ - di = (struct device_info *)va_arg(ap, u_int32_t); + di = (struct device_info *)va_arg(ap, uintptr_t); if (di == NULL) return API_EINVAL; @@ -421,23 +396,23 @@ static int API_dev_read(va_list ap) return API_ENODEV; /* 2. arg is ptr to buffer from where to put the read data */ - buf = (void *)va_arg(ap, u_int32_t); + buf = (void *)va_arg(ap, uintptr_t); if (buf == NULL) return API_EINVAL; if (di->type & DEV_TYP_STOR) { /* 3. arg - ptr to var with # of blocks to read */ - len_stor = (lbasize_t *)va_arg(ap, u_int32_t); + len_stor = (lbasize_t *)va_arg(ap, uintptr_t); if (!len_stor) return API_EINVAL; if (*len_stor <= 0) return API_EINVAL; /* 4. arg - ptr to var with start block */ - start = (lbastart_t *)va_arg(ap, u_int32_t); + start = (lbastart_t *)va_arg(ap, uintptr_t); /* 5. arg - ptr to var where to put the len actually read */ - act_len_stor = (lbasize_t *)va_arg(ap, u_int32_t); + act_len_stor = (lbasize_t *)va_arg(ap, uintptr_t); if (!act_len_stor) return API_EINVAL; @@ -446,14 +421,14 @@ static int API_dev_read(va_list ap) } else if (di->type & DEV_TYP_NET) { /* 3. arg points to the var with length of packet to read */ - len_net = (int *)va_arg(ap, u_int32_t); + len_net = (int *)va_arg(ap, uintptr_t); if (!len_net) return API_EINVAL; if (*len_net <= 0) return API_EINVAL; /* 4. - ptr to var where to put the len actually read */ - act_len_net = (int *)va_arg(ap, u_int32_t); + act_len_net = (int *)va_arg(ap, uintptr_t); if (!act_len_net) return API_EINVAL; @@ -477,12 +452,12 @@ static int API_env_get(va_list ap) { char *name, **value; - if ((name = (char *)va_arg(ap, u_int32_t)) == NULL) + if ((name = (char *)va_arg(ap, uintptr_t)) == NULL) return API_EINVAL; - if ((value = (char **)va_arg(ap, u_int32_t)) == NULL) + if ((value = (char **)va_arg(ap, uintptr_t)) == NULL) return API_EINVAL; - *value = getenv(name); + *value = env_get(name); return 0; } @@ -500,12 +475,12 @@ static int API_env_set(va_list ap) { char *name, *value; - if ((name = (char *)va_arg(ap, u_int32_t)) == NULL) + if ((name = (char *)va_arg(ap, uintptr_t)) == NULL) return API_EINVAL; - if ((value = (char *)va_arg(ap, u_int32_t)) == NULL) + if ((value = (char *)va_arg(ap, uintptr_t)) == NULL) return API_EINVAL; - setenv(name, value); + env_set(name, value); return 0; } @@ -519,44 +494,90 @@ static int API_env_set(va_list ap) */ static int API_env_enum(va_list ap) { - int i, n; - char *last, **next; + int i, buflen; + char *last, **next, *s; + ENTRY *match, search; + static char *var; + + last = (char *)va_arg(ap, unsigned long); - last = (char *)va_arg(ap, u_int32_t); - - if ((next = (char **)va_arg(ap, u_int32_t)) == NULL) + if ((next = (char **)va_arg(ap, uintptr_t)) == NULL) return API_EINVAL; - if (last == NULL) - /* start over */ - *next = ((char *)env_get_addr(0)); - else { - *next = last; - - for (i = 0; env_get_char(i) != '\0'; i = n + 1) { - for (n = i; env_get_char(n) != '\0'; ++n) { - if (n >= CFG_ENV_SIZE) { - /* XXX shouldn't we set *next = NULL?? */ - return 0; - } - } - - if (envmatch((uchar *)last, i) < 0) - continue; - - /* try to get next name */ - i = n + 1; - if (env_get_char(i) == '\0') { - /* no more left */ - *next = NULL; - return 0; - } - - *next = ((char *)env_get_addr(i)); - return 0; + 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; } } + /* 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; + return 0; + +done: + free(var); + var = NULL; + *next = NULL; + return i; +} + +/* + * 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; } @@ -567,7 +588,7 @@ static cfp_t calls_table[API_MAXCALL] = { NULL, }; * serviced until finished. * * e.g. syscall(1, int *, u_int32_t, u_int32_t, u_int32_t, u_int32_t); - * + * * call: syscall number * * retval: points to the return value placeholder, this is the place the @@ -583,7 +604,7 @@ int syscall(int call, int *retval, ...) va_list ap; int rv; - if (call < 0 || call >= calls_no || calls_table[call] == NULL) { + if (call < 0 || call >= calls_no) { debugf("invalid call #%d\n", call); return 0; } @@ -603,7 +624,7 @@ int syscall(int call, int *retval, ...) void api_init(void) { - struct api_signature *sig = NULL; + struct api_signature *sig; /* TODO put this into linker set one day... */ calls_table[API_RSVD] = NULL; @@ -623,6 +644,9 @@ void api_init(void) calls_table[API_ENV_GET] = &API_env_get; calls_table[API_ENV_SET] = &API_env_set; calls_table[API_ENV_ENUM] = &API_env_enum; + 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; calls_no = API_MAXCALL; debugf("API initialized with %d calls\n", calls_no); @@ -638,14 +662,15 @@ void api_init(void) return; } - debugf("API sig @ 0x%08x\n", sig); + env_set_hex("api_address", (unsigned long)sig); + debugf("API sig @ 0x%lX\n", (unsigned long)sig); 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)); - debugf("syscall entry: 0x%08x\n", sig->syscall); + debugf("syscall entry: 0x%lX\n", (unsigned long)sig->syscall); } void platform_set_mr(struct sys_info *si, unsigned long start, unsigned long size, @@ -655,7 +680,7 @@ void platform_set_mr(struct sys_info *si, unsigned long start, unsigned long siz if (!si->mr || !size || (flags == 0)) return; - + /* find free slot */ for (i = 0; i < si->mr_no; i++) if (si->mr[i].flags == 0) { @@ -666,5 +691,3 @@ void platform_set_mr(struct sys_info *si, unsigned long start, unsigned long siz return; } } - -#endif /* CONFIG_API */