Changeset 08f747e in mainline for uspace/lib
- Timestamp:
- 2010-11-26T21:49:30Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8e423a2d, dac43be
- Parents:
- e4dbfda (diff), da55d5b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib
- Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
re4dbfda r08f747e 816 816 UPPER32(ba), cnt); 817 817 if (rc != EOK) { 818 printf("Error %d reading % dblocks starting at block %" PRIuOFF64819 " from device handle % d\n", rc, cnt, ba,818 printf("Error %d reading %zu blocks starting at block %" PRIuOFF64 819 " from device handle %" PRIun "\n", rc, cnt, ba, 820 820 devcon->devmap_handle); 821 821 #ifndef NDEBUG … … 843 843 UPPER32(ba), cnt); 844 844 if (rc != EOK) { 845 printf("Error %d writing % dblocks starting at block %" PRIuOFF64846 " to device handle % d\n", rc, cnt, ba, devcon->devmap_handle);845 printf("Error %d writing %zu blocks starting at block %" PRIuOFF64 846 " to device handle %" PRIun "\n", rc, cnt, ba, devcon->devmap_handle); 847 847 #ifndef NDEBUG 848 848 stacktrace_print(); -
uspace/lib/c/arch/abs32le/include/inttypes.h
re4dbfda r08f747e 34 34 #define LIBC_abs32le_INTTYPES_H_ 35 35 36 #define PRId8 "d" 37 #define PRId16 "d" 38 #define PRId32 "d" 39 #define PRId64 "lld" 40 #define PRIdPTR "d" 41 42 #define PRIo8 "o" 43 #define PRIo16 "o" 44 #define PRIo32 "o" 45 #define PRIo64 "llo" 46 #define PRIoPTR "o" 47 48 #define PRIu8 "u" 49 #define PRIu16 "u" 50 #define PRIu32 "u" 51 #define PRIu64 "llu" 52 #define PRIuPTR "u" 53 54 #define PRIx8 "x" 55 #define PRIx16 "x" 56 #define PRIx32 "x" 57 #define PRIx64 "llx" 58 #define PRIxPTR "x" 59 60 #define PRIX8 "X" 61 #define PRIX16 "X" 62 #define PRIX32 "X" 63 #define PRIX64 "llX" 64 #define PRIXPTR "X" 36 #define PRIdn PRId32 /**< Format for sysarg_t, ipcarg_t, etc. */ 37 #define PRIun PRIu32 /**< Format for sysarg_t, ipcarg_t, etc. */ 38 #define PRIxn PRIx32 /**< Format for hexadecimal sysarg_t, ipcarg_t, etc. */ 39 #define PRIua PRIu32 /**< Format for atomic_count_t. */ 65 40 66 41 #endif -
uspace/lib/c/arch/amd64/include/inttypes.h
re4dbfda r08f747e 30 30 * @{ 31 31 */ 32 /** @file Macros for format specifiers.33 *34 * Macros for formatting stdint types as specified in section35 * 7.8.1 Macros for format specifiers of the C99 draft specification36 * (ISO/IEC 9899:201x). Only some macros from the specification are37 * implemented.38 */39 32 40 33 #ifndef LIBC_amd64_INTTYPES_H_ 41 34 #define LIBC_amd64_INTTYPES_H_ 42 35 43 #define PRId8 "d" 44 #define PRId16 "d" 45 #define PRId32 "d" 46 #define PRId64 "lld" 47 #define PRIdPTR "lld" 48 49 #define PRIo8 "o" 50 #define PRIo16 "o" 51 #define PRIo32 "o" 52 #define PRIo64 "llo" 53 #define PRIoPTR "llo" 54 55 #define PRIu8 "u" 56 #define PRIu16 "u" 57 #define PRIu32 "u" 58 #define PRIu64 "llu" 59 #define PRIuPTR "llu" 60 61 #define PRIx8 "x" 62 #define PRIx16 "x" 63 #define PRIx32 "x" 64 #define PRIx64 "llx" 65 #define PRIxPTR "llx" 66 67 #define PRIX8 "X" 68 #define PRIX16 "X" 69 #define PRIX32 "X" 70 #define PRIX64 "llX" 71 #define PRIXPTR "llX" 36 #define PRIdn PRId64 /**< Format for sysarg_t, ipcarg_t, etc. */ 37 #define PRIun PRIu64 /**< Format for sysarg_t, ipcarg_t, etc. */ 38 #define PRIxn PRIx64 /**< Format for hexadecimal sysarg_t, ipcarg_t, etc. */ 39 #define PRIua PRIu64 /**< Format for atomic_count_t. */ 72 40 73 41 #endif -
uspace/lib/c/arch/arm32/include/inttypes.h
re4dbfda r08f747e 30 30 * @{ 31 31 */ 32 /** @file Macros for format specifiers.33 *34 * Macros for formatting stdint types as specified in section35 * 7.8.1 Macros for format specifiers of the C99 draft specification36 * (ISO/IEC 9899:201x). Only some macros from the specification are37 * implemented.38 */39 32 40 33 #ifndef LIBC_arm32_INTTYPES_H_ 41 34 #define LIBC_arm32_INTTYPES_H_ 42 35 43 #define PRId8 "d" 44 #define PRId16 "d" 45 #define PRId32 "d" 46 #define PRId64 "lld" 47 #define PRIdPTR "d" 48 49 #define PRIo8 "o" 50 #define PRIo16 "o" 51 #define PRIo32 "o" 52 #define PRIo64 "llo" 53 #define PRIoPTR "o" 54 55 #define PRIu8 "u" 56 #define PRIu16 "u" 57 #define PRIu32 "u" 58 #define PRIu64 "llu" 59 #define PRIuPTR "u" 60 61 #define PRIx8 "x" 62 #define PRIx16 "x" 63 #define PRIx32 "x" 64 #define PRIx64 "llx" 65 #define PRIxPTR "x" 66 67 #define PRIX8 "X" 68 #define PRIX16 "X" 69 #define PRIX32 "X" 70 #define PRIX64 "llX" 71 #define PRIXPTR "X" 36 #define PRIdn PRId32 /**< Format for sysarg_t, ipcarg_t, etc. */ 37 #define PRIun PRIu32 /**< Format for sysarg_t, ipcarg_t, etc. */ 38 #define PRIxn PRIx32 /**< Format for hexadecimal sysarg_t, ipcarg_t, etc. */ 39 #define PRIua PRIu32 /**< Format for atomic_count_t. */ 72 40 73 41 #endif -
uspace/lib/c/arch/ia32/include/inttypes.h
re4dbfda r08f747e 30 30 * @{ 31 31 */ 32 /** @file Macros for format specifiers.33 *34 * Macros for formatting stdint types as specified in section35 * 7.8.1 Macros for format specifiers of the C99 draft specification36 * (ISO/IEC 9899:201x). Only some macros from the specification are37 * implemented.38 */39 32 40 33 #ifndef LIBC_ia32_INTTYPES_H_ 41 34 #define LIBC_ia32_INTTYPES_H_ 42 35 43 #define PRId8 "d" 44 #define PRId16 "d" 45 #define PRId32 "d" 46 #define PRId64 "lld" 47 #define PRIdPTR "d" 48 49 #define PRIo8 "o" 50 #define PRIo16 "o" 51 #define PRIo32 "o" 52 #define PRIo64 "llo" 53 #define PRIoPTR "o" 54 55 #define PRIu8 "u" 56 #define PRIu16 "u" 57 #define PRIu32 "u" 58 #define PRIu64 "llu" 59 #define PRIuPTR "u" 60 61 #define PRIx8 "x" 62 #define PRIx16 "x" 63 #define PRIx32 "x" 64 #define PRIx64 "llx" 65 #define PRIxPTR "x" 66 67 #define PRIX8 "X" 68 #define PRIX16 "X" 69 #define PRIX32 "X" 70 #define PRIX64 "llX" 71 #define PRIXPTR "X" 36 #define PRIdn PRId32 /**< Format for sysarg_t, ipcarg_t, etc. */ 37 #define PRIun PRIu32 /**< Format for sysarg_t, ipcarg_t, etc. */ 38 #define PRIxn PRIx32 /**< Format for hexadecimal sysarg_t, ipcarg_t, etc. */ 39 #define PRIua PRIu32 /**< Format for atomic_count_t. */ 72 40 73 41 #endif -
uspace/lib/c/arch/ia64/include/inttypes.h
re4dbfda r08f747e 30 30 * @{ 31 31 */ 32 /** @file Macros for format specifiers.33 *34 * Macros for formatting stdint types as specified in section35 * 7.8.1 Macros for format specifiers of the C99 draft specification36 * (ISO/IEC 9899:201x). Only some macros from the specification are37 * implemented.38 */39 32 40 33 #ifndef LIBC_ia64_INTTYPES_H_ 41 34 #define LIBC_ia64_INTTYPES_H_ 42 35 43 #define PRId8 "d" 44 #define PRId16 "d" 45 #define PRId32 "d" 46 #define PRId64 "ld" 47 #define PRIdPTR "ld" 48 49 #define PRIo8 "o" 50 #define PRIo16 "o" 51 #define PRIo32 "o" 52 #define PRIo64 "lo" 53 #define PRIoPTR "lo" 54 55 #define PRIu8 "u" 56 #define PRIu16 "u" 57 #define PRIu32 "u" 58 #define PRIu64 "lu" 59 #define PRIuPTR "lu" 60 61 #define PRIx8 "x" 62 #define PRIx16 "x" 63 #define PRIx32 "x" 64 #define PRIx64 "lx" 65 #define PRIxPTR "lx" 66 67 #define PRIX8 "X" 68 #define PRIX16 "X" 69 #define PRIX32 "X" 70 #define PRIX64 "lX" 71 #define PRIXPTR "lX" 36 #define PRIdn PRId64 /**< Format for sysarg_t, ipcarg_t, etc. */ 37 #define PRIun PRIu64 /**< Format for sysarg_t, ipcarg_t, etc. */ 38 #define PRIxn PRIx64 /**< Format for hexadecimal sysarg_t, ipcarg_t, etc. */ 39 #define PRIua PRIu64 /**< Format for atomic_count_t. */ 72 40 73 41 #endif -
uspace/lib/c/arch/mips32/include/inttypes.h
re4dbfda r08f747e 30 30 * @{ 31 31 */ 32 /** @file Macros for format specifiers.33 *34 * Macros for formatting stdint types as specified in section35 * 7.8.1 Macros for format specifiers of the C99 draft specification36 * (ISO/IEC 9899:201x). Only some macros from the specification are37 * implemented.38 */39 32 40 33 #ifndef LIBC_mips32_INTTYPES_H_ 41 34 #define LIBC_mips32_INTTYPES_H_ 42 35 43 #define PRId8 "d" 44 #define PRId16 "d" 45 #define PRId32 "d" 46 #define PRId64 "lld" 47 #define PRIdPTR "d" 48 49 #define PRIo8 "o" 50 #define PRIo16 "o" 51 #define PRIo32 "o" 52 #define PRIo64 "llo" 53 #define PRIoPTR "o" 54 55 #define PRIu8 "u" 56 #define PRIu16 "u" 57 #define PRIu32 "u" 58 #define PRIu64 "llu" 59 #define PRIuPTR "u" 60 61 #define PRIx8 "x" 62 #define PRIx16 "x" 63 #define PRIx32 "x" 64 #define PRIx64 "llx" 65 #define PRIxPTR "x" 66 67 #define PRIX8 "X" 68 #define PRIX16 "X" 69 #define PRIX32 "X" 70 #define PRIX64 "llX" 71 #define PRIXPTR "x" 36 #define PRIdn PRId32 /**< Format for sysarg_t, ipcarg_t, etc. */ 37 #define PRIun PRIu32 /**< Format for sysarg_t, ipcarg_t, etc. */ 38 #define PRIxn PRIx32 /**< Format for hexadecimal sysarg_t, ipcarg_t, etc. */ 39 #define PRIua PRIu32 /**< Format for atomic_count_t. */ 72 40 73 41 #endif -
uspace/lib/c/arch/ppc32/include/inttypes.h
re4dbfda r08f747e 30 30 * @{ 31 31 */ 32 /** @file Macros for format specifiers.33 *34 * Macros for formatting stdint types as specified in section35 * 7.8.1 Macros for format specifiers of the C99 draft specification36 * (ISO/IEC 9899:201x). Only some macros from the specification are37 * implemented.38 */39 32 40 33 #ifndef LIBC_ppc32_INTTYPES_H_ 41 34 #define LIBC_ppc32_INTTYPES_H_ 42 35 43 #define PRId8 "d" 44 #define PRId16 "d" 45 #define PRId32 "d" 46 #define PRId64 "lld" 47 #define PRIdPTR "d" 48 49 #define PRIo8 "o" 50 #define PRIo16 "o" 51 #define PRIo32 "o" 52 #define PRIo64 "llo" 53 #define PRIoPTR "o" 54 55 #define PRIu8 "u" 56 #define PRIu16 "u" 57 #define PRIu32 "u" 58 #define PRIu64 "llu" 59 #define PRIuPTR "u" 60 61 #define PRIx8 "x" 62 #define PRIx16 "x" 63 #define PRIx32 "x" 64 #define PRIx64 "llx" 65 #define PRIxPTR "x" 66 67 #define PRIX8 "X" 68 #define PRIX16 "X" 69 #define PRIX32 "X" 70 #define PRIX64 "llX" 71 #define PRIXPTR "X" 36 #define PRIdn PRId32 /**< Format for sysarg_t, ipcarg_t, etc. */ 37 #define PRIun PRIu32 /**< Format for sysarg_t, ipcarg_t, etc. */ 38 #define PRIxn PRIx32 /**< Format for hexadecimal sysarg_t, ipcarg_t, etc. */ 39 #define PRIua PRIu32 /**< Format for atomic_count_t. */ 72 40 73 41 #endif -
uspace/lib/c/arch/sparc64/include/inttypes.h
re4dbfda r08f747e 30 30 * @{ 31 31 */ 32 /** @file Macros for format specifiers.33 *34 * Macros for formatting stdint types as specified in section35 * 7.8.1 Macros for format specifiers of the C99 draft specification36 * (ISO/IEC 9899:201x). Only some macros from the specification are37 * implemented.38 */39 32 40 33 #ifndef LIBC_sparc64_INTTYPES_H_ 41 34 #define LIBC_sparc64_INTTYPES_H_ 42 35 43 #define PRId8 "d" 44 #define PRId16 "d" 45 #define PRId32 "d" 46 #define PRId64 "lld" 47 #define PRIdPTR "lld" 48 49 #define PRIo8 "o" 50 #define PRIo16 "o" 51 #define PRIo32 "o" 52 #define PRIo64 "llo" 53 #define PRIoPTR "llo" 54 55 #define PRIu8 "u" 56 #define PRIu16 "u" 57 #define PRIu32 "u" 58 #define PRIu64 "llu" 59 #define PRIuPTR "llu" 60 61 #define PRIx8 "x" 62 #define PRIx16 "x" 63 #define PRIx32 "x" 64 #define PRIx64 "llx" 65 #define PRIxPTR "llx" 66 67 #define PRIX8 "X" 68 #define PRIX16 "X" 69 #define PRIX32 "X" 70 #define PRIX64 "llX" 71 #define PRIXPTR "llX" 36 #define PRIdn PRId64 /**< Format for sysarg_t, ipcarg_t, etc. */ 37 #define PRIun PRIu64 /**< Format for sysarg_t, ipcarg_t, etc. */ 38 #define PRIxn PRIx64 /**< Format for hexadecimal sysarg_t, ipcarg_t, etc. */ 39 #define PRIua PRIu64 /**< Format for atomic_count_t. */ 72 40 73 41 #endif -
uspace/lib/c/generic/device/char.c
re4dbfda r08f747e 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 29 /** @addtogroup libc 30 30 * @{ … … 40 40 #include <stdio.h> 41 41 42 /** Read to or write from the device using its character interface. 43 * 44 * Helper function. 45 * 46 * @param dev_phone phone to the device. 47 * @param buf the buffer for the data read from or written to the device. 48 * @param len the maximum length of the data to be read or written. 49 * @param read read from the device if true, write to it otherwise. 50 * 51 * @return non-negative number of bytes actually read from or written to the device on success, 52 * negative error number otherwise. 53 * 42 /** Read to or write from device. 43 * 44 * Helper function to read to or write from a device 45 * using its character interface. 46 * 47 * @param dev_phone Phone to the device. 48 * @param buf Buffer for the data read 49 * from or written to the device. 50 * @param len Maximum length of the data to be 51 * read or written. 52 * @param read Read from the device if true, 53 * write to it otherwise. 54 * 55 * @return Non-negative number of bytes actually read 56 * from or written to the device on success, 57 * negative error number otherwise. 58 * 54 59 */ 55 static int rw_dev(int dev_phone, void *buf, size_t len, bool read)60 static ssize_t rw_dev(int dev_phone, void *buf, size_t len, bool read) 56 61 { 57 ipc_call_t answer;58 59 62 async_serialize_start(); 60 63 64 ipc_call_t answer; 61 65 aid_t req; 62 66 int ret; 63 67 64 68 if (read) { 65 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_READ_DEV, &answer); 66 ret = async_data_read_start(dev_phone, buf, len); 69 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), 70 CHAR_READ_DEV, &answer); 71 ret = async_data_read_start(dev_phone, buf, len); 67 72 } else { 68 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), CHAR_WRITE_DEV, &answer); 73 req = async_send_1(dev_phone, DEV_IFACE_ID(CHAR_DEV_IFACE), 74 CHAR_WRITE_DEV, &answer); 69 75 ret = async_data_write_start(dev_phone, buf, len); 70 76 } 71 77 72 78 ipcarg_t rc; 73 if (ret != EOK) { 79 if (ret != EOK) { 74 80 async_wait_for(req, &rc); 75 81 async_serialize_end(); 76 if (rc == EOK) { 77 return ret; 78 } 79 else { 80 return (int) rc; 81 } 82 if (rc == EOK) 83 return (ssize_t) ret; 84 85 return (ssize_t) rc; 82 86 } 83 87 … … 85 89 async_serialize_end(); 86 90 87 ret = (int)rc; 88 if (EOK != ret) { 89 return ret; 90 } 91 ret = (int) rc; 92 if (ret != EOK) 93 return (ssize_t) ret; 91 94 92 return IPC_GET_ARG1(answer);95 return (ssize_t) IPC_GET_ARG1(answer); 93 96 } 94 97 95 /** Read from the device using its character interface. 96 * 97 * @param dev_phone phone to the device. 98 * @param buf the output buffer for the data read from the device. 99 * @param len the maximum length of the data to be read. 100 * 101 * @return non-negative number of bytes actually read from the device on success, negative error number otherwise. 98 /** Read from device using its character interface. 99 * 100 * @param dev_phone Phone to the device. 101 * @param buf Output buffer for the data 102 * read from the device. 103 * @param len Maximum length of the data to be read. 104 * 105 * @return Non-negative number of bytes actually read 106 * from the device on success, negative error 107 * number otherwise. 108 * 102 109 */ 103 int read_dev(int dev_phone, void *buf, size_t len)104 { 110 ssize_t read_dev(int dev_phone, void *buf, size_t len) 111 { 105 112 return rw_dev(dev_phone, buf, len, true); 106 113 } 107 114 108 /** Write to the device using its character interface. 109 * 110 * @param dev_phone phone to the device. 111 * @param buf the input buffer containg the data to be written to the device. 112 * @param len the maximum length of the data to be written. 113 * 114 * @return non-negative number of bytes actually written to the device on success, negative error number otherwise. 115 /** Write to device using its character interface. 116 * 117 * @param dev_phone Phone to the device. 118 * @param buf Input buffer containg the data 119 * to be written to the device. 120 * @param len Maximum length of the data to be written. 121 * 122 * @return Non-negative number of bytes actually written 123 * to the device on success, negative error number 124 * otherwise. 125 * 115 126 */ 116 int write_dev(int dev_phone, void *buf, size_t len)127 ssize_t write_dev(int dev_phone, void *buf, size_t len) 117 128 { 118 129 return rw_dev(dev_phone, buf, len, false); 119 130 } 120 131 121 122 /** @} 132 /** @} 123 133 */ -
uspace/lib/c/generic/io/printf_core.c
re4dbfda r08f747e 82 82 PrintfQualifierLong, 83 83 PrintfQualifierLongLong, 84 PrintfQualifierPointer 84 PrintfQualifierPointer, 85 PrintfQualifierSize 85 86 } qualifier_t; 86 87 … … 552 553 * - "" Signed or unsigned int (default value).@n 553 554 * - "l" Signed or unsigned long int.@n 554 * If conversion is "c", the character is w char_t (wide character).@n555 * If conversion is "c", the character is wint_t (wide character).@n 555 556 * If conversion is "s", the string is wchar_t * (wide string).@n 556 557 * - "ll" Signed or unsigned long long int.@n 558 * - "z" Signed or unsigned ssize_t or site_t.@n 557 559 * 558 560 * CONVERSION:@n … … 736 738 } 737 739 break; 740 case 'z': 741 qualifier = PrintfQualifierSize; 742 i = nxt; 743 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 744 break; 738 745 default: 739 746 /* Default type */ … … 763 770 case 'c': 764 771 if (qualifier == PrintfQualifierLong) 765 retval = print_wchar(va_arg(ap, w char_t), width, flags, ps);772 retval = print_wchar(va_arg(ap, wint_t), width, flags, ps); 766 773 else 767 774 retval = print_char(va_arg(ap, unsigned int), width, flags, ps); … … 849 856 precision = size << 1; 850 857 number = (uint64_t) (uintptr_t) va_arg(ap, void *); 858 break; 859 case PrintfQualifierSize: 860 size = sizeof(size_t); 861 number = (uint64_t) va_arg(ap, size_t); 851 862 break; 852 863 default: -
uspace/lib/c/generic/stacktrace.c
re4dbfda r08f747e 50 50 51 51 while (stacktrace_fp_valid(&st, fp)) { 52 printf("%p: %p()\n", fp,pc);52 printf("%p: %p()\n", (void *) fp, (void *) pc); 53 53 (void) stacktrace_ra_get(&st, fp, &pc); 54 54 (void) stacktrace_fp_prev(&st, fp, &nfp); -
uspace/lib/c/generic/str.c
re4dbfda r08f747e 1005 1005 *end = '\0'; 1006 1006 return start; 1007 } 1008 1009 /** Convert string to uint64_t (internal variant). 1010 * 1011 * @param nptr Pointer to string. 1012 * @param endptr Pointer to the first invalid character is stored here. 1013 * @param base Zero or number between 2 and 36 inclusive. 1014 * @param neg Indication of unary minus is stored here. 1015 * @apram result Result of the conversion. 1016 * 1017 * @return EOK if conversion was successful. 1018 * 1019 */ 1020 static int str_uint(const char *nptr, char **endptr, unsigned int base, 1021 bool *neg, uint64_t *result) 1022 { 1023 assert(endptr != NULL); 1024 assert(neg != NULL); 1025 assert(result != NULL); 1026 1027 *neg = false; 1028 const char *str = nptr; 1029 1030 /* Ignore leading whitespace */ 1031 while (isspace(*str)) 1032 str++; 1033 1034 if (*str == '-') { 1035 *neg = true; 1036 str++; 1037 } else if (*str == '+') 1038 str++; 1039 1040 if (base == 0) { 1041 /* Decode base if not specified */ 1042 base = 10; 1043 1044 if (*str == '0') { 1045 base = 8; 1046 str++; 1047 1048 switch (*str) { 1049 case 'b': 1050 case 'B': 1051 base = 2; 1052 str++; 1053 break; 1054 case 'o': 1055 case 'O': 1056 base = 8; 1057 str++; 1058 break; 1059 case 'd': 1060 case 'D': 1061 case 't': 1062 case 'T': 1063 base = 10; 1064 str++; 1065 break; 1066 case 'x': 1067 case 'X': 1068 base = 16; 1069 str++; 1070 break; 1071 default: 1072 str--; 1073 } 1074 } 1075 } else { 1076 /* Check base range */ 1077 if ((base < 2) || (base > 36)) { 1078 *endptr = (char *) str; 1079 return EINVAL; 1080 } 1081 } 1082 1083 *result = 0; 1084 const char *startstr = str; 1085 1086 while (*str != 0) { 1087 unsigned int digit; 1088 1089 if ((*str >= 'a') && (*str <= 'z')) 1090 digit = *str - 'a' + 10; 1091 else if ((*str >= 'A') && (*str <= 'Z')) 1092 digit = *str - 'A' + 10; 1093 else if ((*str >= '0') && (*str <= '9')) 1094 digit = *str - '0'; 1095 else 1096 break; 1097 1098 if (digit >= base) 1099 break; 1100 1101 uint64_t prev = *result; 1102 *result = (*result) * base + digit; 1103 1104 if (*result < prev) { 1105 /* Overflow */ 1106 *endptr = (char *) str; 1107 return EOVERFLOW; 1108 } 1109 1110 str++; 1111 } 1112 1113 if (str == startstr) { 1114 /* 1115 * No digits were decoded => first invalid character is 1116 * the first character of the string. 1117 */ 1118 str = nptr; 1119 } 1120 1121 *endptr = (char *) str; 1122 1123 if (str == nptr) 1124 return EINVAL; 1125 1126 return EOK; 1127 } 1128 1129 /** Convert string to uint64_t. 1130 * 1131 * @param nptr Pointer to string. 1132 * @param endptr If not NULL, pointer to the first invalid character 1133 * is stored here. 1134 * @param base Zero or number between 2 and 36 inclusive. 1135 * @param strict Do not allow any trailing characters. 1136 * @param result Result of the conversion. 1137 * 1138 * @return EOK if conversion was successful. 1139 * 1140 */ 1141 int str_uint64(const char *nptr, char **endptr, unsigned int base, 1142 bool strict, uint64_t *result) 1143 { 1144 assert(result != NULL); 1145 1146 bool neg; 1147 char *lendptr; 1148 int ret = str_uint(nptr, &lendptr, base, &neg, result); 1149 1150 if (endptr != NULL) 1151 *endptr = (char *) lendptr; 1152 1153 if (ret != EOK) 1154 return ret; 1155 1156 /* Do not allow negative values */ 1157 if (neg) 1158 return EINVAL; 1159 1160 /* Check whether we are at the end of 1161 the string in strict mode */ 1162 if ((strict) && (*lendptr != 0)) 1163 return EINVAL; 1164 1165 return EOK; 1166 } 1167 1168 /** Convert string to size_t. 1169 * 1170 * @param nptr Pointer to string. 1171 * @param endptr If not NULL, pointer to the first invalid character 1172 * is stored here. 1173 * @param base Zero or number between 2 and 36 inclusive. 1174 * @param strict Do not allow any trailing characters. 1175 * @param result Result of the conversion. 1176 * 1177 * @return EOK if conversion was successful. 1178 * 1179 */ 1180 int str_size_t(const char *nptr, char **endptr, unsigned int base, 1181 bool strict, size_t *result) 1182 { 1183 assert(result != NULL); 1184 1185 bool neg; 1186 char *lendptr; 1187 uint64_t res; 1188 int ret = str_uint(nptr, &lendptr, base, &neg, &res); 1189 1190 if (endptr != NULL) 1191 *endptr = (char *) lendptr; 1192 1193 if (ret != EOK) 1194 return ret; 1195 1196 /* Do not allow negative values */ 1197 if (neg) 1198 return EINVAL; 1199 1200 /* Check whether we are at the end of 1201 the string in strict mode */ 1202 if ((strict) && (*lendptr != 0)) 1203 return EINVAL; 1204 1205 /* Check for overflow */ 1206 size_t _res = (size_t) res; 1207 if (_res != res) 1208 return EOVERFLOW; 1209 1210 *result = _res; 1211 1212 return EOK; 1007 1213 } 1008 1214 -
uspace/lib/c/include/assert.h
re4dbfda r08f747e 51 51 52 52 #ifndef NDEBUG 53 # define assert(expr) \ 54 do { \ 55 if (!(expr)) { \ 56 printf("Assertion failed (%s) at file '%s', " \ 57 "line %d.\n", #expr, __FILE__, __LINE__); \ 58 abort(); \ 59 } \ 60 } while (0) 61 #else 62 # define assert(expr) 63 #endif 53 54 #define assert(expr) \ 55 do { \ 56 if (!(expr)) { \ 57 printf("Assertion failed (%s) at file '%s', " \ 58 "line %d.\n", #expr, __FILE__, __LINE__); \ 59 abort(); \ 60 } \ 61 } while (0) 62 63 #else /* NDEBUG */ 64 65 #define assert(expr) 66 67 #endif /* NDEBUG */ 64 68 65 69 #endif -
uspace/lib/c/include/device/char.h
re4dbfda r08f747e 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 29 /** @addtogroup libc 30 30 * @{ … … 32 32 /** @file 33 33 */ 34 34 35 35 #ifndef LIBC_DEVICE_HW_RES_H_ 36 36 #define LIBC_DEVICE_HW_RES_H_ … … 38 38 typedef enum { 39 39 CHAR_READ_DEV = 0, 40 CHAR_WRITE_DEV 40 CHAR_WRITE_DEV 41 41 } hw_res_funcs_t; 42 42 43 int read_dev(int dev_phone, void *buf, size_t len);44 int write_dev(int dev_phone, void *buf, size_t len);43 ssize_t read_dev(int dev_phone, void *buf, size_t len); 44 ssize_t write_dev(int dev_phone, void *buf, size_t len); 45 45 46 46 #endif -
uspace/lib/c/include/err.h
re4dbfda r08f747e 38 38 #include <stdio.h> 39 39 40 #define errx(status, fmt, ...) { \ 41 printf((fmt), ##__VA_ARGS__); \ 42 _exit(status); \ 43 } 40 #define errx(status, fmt, ...) \ 41 { \ 42 printf((fmt), ##__VA_ARGS__); \ 43 _exit(status); \ 44 } 44 45 45 46 #endif … … 47 48 /** @} 48 49 */ 49 -
uspace/lib/c/include/malloc.h
re4dbfda r08f747e 41 41 extern uintptr_t get_max_heap_addr(void); 42 42 43 extern void *malloc(const size_t size); 44 extern void *calloc(const size_t nmemb, const size_t size); 45 extern void *memalign(const size_t align, const size_t size); 43 extern void *malloc(const size_t size) 44 __attribute__((malloc)); 45 extern void *calloc(const size_t nmemb, const size_t size) 46 __attribute__((malloc)); 47 extern void *memalign(const size_t align, const size_t size) 48 __attribute__((malloc)); 46 49 extern void *realloc(const void *addr, const size_t size); 47 50 extern void free(const void *addr); -
uspace/lib/c/include/stdint.h
re4dbfda r08f747e 36 36 #define LIBC_STDINT_H_ 37 37 38 #define INT8_MIN (0x80)39 #define INT8_MAX (0x7F)38 #define INT8_MIN INT8_C(0x80) 39 #define INT8_MAX INT8_C(0x7F) 40 40 41 #define UINT8_MIN (0u)42 #define UINT8_MAX (0xFFu)41 #define UINT8_MIN UINT8_C(0) 42 #define UINT8_MAX UINT8_C(0xFF) 43 43 44 #define INT16_MIN (0x8000)45 #define INT16_MAX (0x7FFF)44 #define INT16_MIN INT16_C(0x8000) 45 #define INT16_MAX INT16_C(0x7FFF) 46 46 47 #define UINT16_MIN (0u)48 #define UINT16_MAX (0xFFFFu)47 #define UINT16_MIN UINT16_C(0) 48 #define UINT16_MAX UINT16_C(0xFFFF) 49 49 50 #define INT32_MIN (0x80000000l)51 #define INT32_MAX (0x7FFFFFFFl)50 #define INT32_MIN INT32_C(0x80000000) 51 #define INT32_MAX INT32_C(0x7FFFFFFF) 52 52 53 #define UINT32_MIN (0ul)54 #define UINT32_MAX (0xFFFFFFFFul)53 #define UINT32_MIN UINT32_C(0) 54 #define UINT32_MAX UINT32_C(0xFFFFFFFF) 55 55 56 #define INT64_MIN (0x8000000000000000ll)57 #define INT64_MAX (0x7FFFFFFFFFFFFFFFll)56 #define INT64_MIN INT64_C(0x8000000000000000) 57 #define INT64_MAX INT64_C(0x7FFFFFFFFFFFFFFF) 58 58 59 #define UINT64_MIN (0ull)60 #define UINT64_MAX (0xFFFFFFFFFFFFFFFFull)59 #define UINT64_MIN UINT64_C(0) 60 #define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF) 61 61 62 62 #include <libarch/types.h> -
uspace/lib/c/include/stdio.h
re4dbfda r08f747e 41 41 #include <adt/list.h> 42 42 43 #ifndef NVERIFY_PRINTF 44 45 #define PRINTF_ATTRIBUTE(start, end) \ 46 __attribute__((format(gnu_printf, start, end))) 47 48 #else /* NVERIFY_PRINTF */ 49 50 #define PRINTF_ATTRIBUTE(start, end) 51 52 #endif /* NVERIFY_PRINTF */ 53 43 54 #define EOF (-1) 44 55 … … 149 160 150 161 /* Formatted string output functions */ 151 extern int fprintf(FILE *, const char*, ...); 162 extern int fprintf(FILE *, const char*, ...) 163 PRINTF_ATTRIBUTE(2, 3); 152 164 extern int vfprintf(FILE *, const char *, va_list); 153 165 154 extern int printf(const char *, ...); 166 extern int printf(const char *, ...) 167 PRINTF_ATTRIBUTE(1, 2); 155 168 extern int vprintf(const char *, va_list); 156 169 157 extern int snprintf(char *, size_t , const char *, ...); 158 extern int asprintf(char **, const char *, ...); 170 extern int snprintf(char *, size_t , const char *, ...) 171 PRINTF_ATTRIBUTE(3, 4); 172 extern int asprintf(char **, const char *, ...) 173 PRINTF_ATTRIBUTE(2, 3); 159 174 extern int vsnprintf(char *, size_t, const char *, va_list); 160 175 -
uspace/lib/c/include/str.h
re4dbfda r08f747e 86 86 extern char *str_ndup(const char *, size_t max_size); 87 87 88 extern int str_uint64(const char *, char **, unsigned int, bool, uint64_t *); 89 extern int str_size_t(const char *, char **, unsigned int, bool, size_t *); 90 88 91 extern void order_suffix(const uint64_t val, uint64_t *rv, char *suffix); 89 92 -
uspace/lib/c/include/sys/typefmt.h
re4dbfda r08f747e 39 39 #include <inttypes.h> 40 40 41 /* off64_t */41 /* off64_t, aoff64_t */ 42 42 #define PRIdOFF64 PRId64 43 43 #define PRIuOFF64 PRIu64 … … 45 45 #define PRIXOFF64 PRIX64 46 46 47 /* (s)size_t */48 #define PRIdSIZE PRIdPTR49 #define PRIuSIZE PRIuPTR50 #define PRIxSIZE PRIxPTR51 #define PRIXSIZE PRIXPTR52 53 /* sysarg_t */54 #define PRIdSYSARG PRIdPTR55 #define PRIuSYSARG PRIuPTR56 #define PRIxSYSARG PRIxPTR57 #define PRIXSYSARG PRIxPTR58 59 /* ipcarg_t */60 #define PRIdIPCARG PRIdPTR61 #define PRIuIPCARG PRIuPTR62 #define PRIxIPCARG PRIxPTR63 #define PRIXIPCARG PRIXPTR64 65 /* taskid_t */66 #define PRIdTASKID PRId6467 #define PRIuTASKID PRIu6468 #define PRIxTASKID PRIx6469 #define PRIXTASKID PRIx6470 71 47 #endif 72 48 -
uspace/lib/c/include/sys/types.h
re4dbfda r08f747e 46 46 typedef uint64_t aoff64_t; 47 47 48 /** Unicode code point */49 typedef int32_t wchar_t;50 51 48 typedef volatile uint8_t ioport8_t; 52 49 typedef volatile uint16_t ioport16_t; -
uspace/lib/drv/generic/driver.c
re4dbfda r08f747e 48 48 #include <ctype.h> 49 49 #include <errno.h> 50 #include <inttypes.h> 50 51 51 52 #include <ipc/driver.h> … … 164 165 165 166 devman_handle_t dev_handle = IPC_GET_ARG1(*icall); 167 devman_handle_t parent_dev_handle = IPC_GET_ARG2(*icall); 168 166 169 device_t *dev = create_device(); 167 170 dev->handle = dev_handle; … … 171 174 172 175 add_to_devices_list(dev); 176 dev->parent = driver_get_device(&devices, parent_dev_handle); 177 173 178 res = driver->driver_ops->add_device(dev); 174 179 if (0 == res) { 175 printf("%s: new device with handle = %xwas added.\n",180 printf("%s: new device with handle=%" PRIun " was added.\n", 176 181 driver->name, dev_handle); 177 182 } else { 178 printf("%s: failed to add a new device with handle = % d.\n",183 printf("%s: failed to add a new device with handle = %" PRIun ".\n", 179 184 driver->name, dev_handle); 180 185 remove_from_devices_list(dev); … … 203 208 break; 204 209 default: 205 if (!(callid & IPC_CALLID_NOTIFICATION)) 206 ipc_answer_0(callid, ENOENT); 210 ipc_answer_0(callid, ENOENT); 207 211 } 208 212 } … … 226 230 if (dev == NULL) { 227 231 printf("%s: driver_connection_gen error - no device with handle" 228 " % xwas found.\n", driver->name, handle);232 " %" PRIun " was found.\n", driver->name, handle); 229 233 ipc_answer_0(iid, ENOENT); 230 234 return; … … 290 294 printf("%s: driver_connection_gen error - ", 291 295 driver->name); 292 printf("device with handle % dhas no interface "296 printf("device with handle %" PRIun " has no interface " 293 297 "with id %d.\n", handle, iface_idx); 294 298 ipc_answer_0(callid, ENOTSUP); -
uspace/lib/usb/include/usb/classes/hub.h
re4dbfda r08f747e 36 36 #define LIBUSB_HUB_H_ 37 37 38 /** Hub class request. */ 39 typedef enum { 40 USB_HUB_REQUEST_GET_STATUS = 0, 41 USB_HUB_REQUEST_CLEAR_FEATURE = 1, 42 USB_HUB_REQUEST_GET_STATE = 2, 43 USB_HUB_REQUEST_SET_FEATURE = 3, 44 USB_HUB_REQUEST_GET_DESCRIPTOR = 6, 45 USB_HUB_REQUEST_SET_DESCRIPTOR = 7, 46 /* USB_HUB_REQUEST_ = , */ 47 } usb_hub_class_request_t; 38 #include <sys/types.h> 39 #include <usb/hcdhubd.h> 40 48 41 49 42 /** Hub class feature selector. … … 69 62 } usb_hub_class_feature_t; 70 63 64 65 /** 66 * @brief usb hub descriptor 67 * 68 * For more information see Universal Serial Bus Specification Revision 1.1 chapter 11.16.2 69 */ 70 typedef struct hub_descriptor_type{ 71 /** Number of bytes in this descriptor, including this byte */ 72 //uint8_t bDescLength; 73 74 /** Descriptor Type, value: 29H for hub descriptor */ 75 //uint8_t bDescriptorType; 76 77 /** Number of downstream ports that this hub supports */ 78 uint8_t ports_count; 79 80 /** 81 D1...D0: Logical Power Switching Mode 82 00: Ganged power switching (all ports’ power at 83 once) 84 01: Individual port power switching 85 1X: Reserved. Used only on 1.0 compliant hubs 86 that implement no power switching. 87 D2: Identifies a Compound Device 88 0: Hub is not part of a compound device 89 1: Hub is part of a compound device 90 D4...D3: Over-current Protection Mode 91 00: Global Over-current Protection. The hub 92 reports over-current as a summation of all 93 ports’ current draw, without a breakdown of 94 individual port over-current status. 95 01: Individual Port Over-current Protection. The 96 hub reports over-current on a per-port basis. 97 Each port has an over-current indicator. 98 1X: No Over-current Protection. This option is 99 allowed only for bus-powered hubs that do not 100 implement over-current protection. 101 D15...D5: 102 Reserved 103 */ 104 uint16_t hub_characteristics; 105 106 /** 107 Time (in 2ms intervals) from the time the power-on 108 sequence begins on a port until power is good on that 109 port. The USB System Software uses this value to 110 determine how long to wait before accessing a 111 powered-on port. 112 */ 113 uint8_t pwr_on_2_good_time; 114 115 /** 116 Maximum current requirements of the Hub Controller 117 electronics in mA. 118 */ 119 uint8_t current_requirement; 120 121 /** 122 Indicates if a port has a removable device attached. 123 This field is reported on byte-granularity. Within a 124 byte, if no port exists for a given location, the field 125 representing the port characteristics returns 0. 126 Bit value definition: 127 0B - Device is removable 128 1B - Device is non-removable 129 This is a bitmap corresponding to the individual ports 130 on the hub: 131 Bit 0: Reserved for future use 132 Bit 1: Port 1 133 Bit 2: Port 2 134 .... 135 Bit n: Port n (implementation-dependent, up to a 136 maximum of 255 ports). 137 */ 138 uint8_t * devices_removable; 139 140 /** 141 This field exists for reasons of compatibility with 142 software written for 1.0 compliant devices. All bits in 143 this field should be set to 1B. This field has one bit for 144 each port on the hub with additional pad bits, if 145 necessary, to make the number of bits in the field an 146 integer multiple of 8. 147 */ 148 //uint8_t * port_pwr_ctrl_mask; 149 } usb_hub_descriptor_t; 150 151 152 153 /** @brief usb hub specific request types. 154 * 155 * For more information see Universal Serial Bus Specification Revision 1.1 chapter 11.16.2 156 */ 157 typedef enum { 158 /** This request resets a value reported in the hub status. */ 159 USB_HUB_REQ_TYPE_CLEAR_HUB_FEATURE = 0x20, 160 /** This request resets a value reported in the port status. */ 161 USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE = 0x23, 162 /** This is an optional per-port diagnostic request that returns the bus state value, as sampled at the last EOF2 point. */ 163 USB_HUB_REQ_TYPE_GET_STATE = 0xA3, 164 /** This request returns the hub descriptor. */ 165 USB_HUB_REQ_TYPE_GET_DESCRIPTOR = 0xA0, 166 /** This request returns the current hub status and the states that have changed since the previous acknowledgment. */ 167 USB_HUB_REQ_TYPE_GET_HUB_STATUS = 0xA0, 168 /** This request returns the current port status and the current value of the port status change bits. */ 169 USB_HUB_REQ_TYPE_GET_PORT_STATUS = 0xA3, 170 /** This request overwrites the hub descriptor. */ 171 USB_HUB_REQ_TYPE_SET_DESCRIPTOR = 0x20, 172 /** This request sets a value reported in the hub status. */ 173 USB_HUB_REQ_TYPE_SET_HUB_FEATURE = 0x20, 174 /** This request sets a value reported in the port status. */ 175 USB_HUB_REQ_TYPE_SET_PORT_FEATURE = 0x23 176 } usb_hub_bm_request_type_t; 177 178 /** @brief hub class request codes*/ 179 typedef enum { 180 /** */ 181 USB_HUB_REQUEST_GET_STATUS = 0, 182 /** */ 183 USB_HUB_REQUEST_CLEAR_FEATURE = 1, 184 /** */ 185 USB_HUB_REQUEST_GET_STATE = 2, 186 /** */ 187 USB_HUB_REQUEST_SET_FEATURE = 3, 188 /** */ 189 USB_HUB_REQUEST_GET_DESCRIPTOR = 6, 190 /** */ 191 USB_HUB_REQUEST_SET_DESCRIPTOR = 7 192 } usb_hub_request_t; 193 194 /** 195 * Maximum size of usb hub descriptor in bytes 196 */ 197 extern size_t USB_HUB_MAX_DESCRIPTOR_SIZE; 198 199 /** 200 * @brief create uint8_t array with serialized descriptor 201 * 202 * @param descriptor 203 */ 204 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor); 205 206 /** 207 * @brief create deserialized desriptor structure out of serialized descriptor 208 * 209 * The serialized descriptor must be proper usb hub descriptor, otherwise an eerror might occur. 210 * 211 * @param sdescriptor serialized descriptor 212 */ 213 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * sdescriptor); 214 215 /** 216 * @brief create hub structure instance 217 * 218 * @param device 219 * @return 220 */ 221 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device); 222 223 224 225 226 71 227 #endif 72 228 /** -
uspace/lib/usb/src/hcdhubd.c
re4dbfda r08f747e 36 36 #include <usb/devreq.h> 37 37 #include <usbhc_iface.h> 38 #include <usb/descriptor.h> 38 39 #include <driver.h> 39 40 #include <bool.h> 40 41 #include <errno.h> 42 #include <usb/classes/hub.h> 41 43 42 44 #define USB_HUB_DEVICE_NAME "usbhub" 45 46 #define USB_KBD_DEVICE_NAME "hid" 47 48 49 43 50 44 51 /** List of handled host controllers. */ … … 57 64 }; 58 65 66 size_t USB_HUB_MAX_DESCRIPTOR_SIZE = 71; 67 68 uint8_t USB_HUB_DESCRIPTOR_TYPE = 0x29; 69 70 //********************************************* 71 // 72 // various utils 73 // 74 //********************************************* 75 76 void * usb_serialize_hub_descriptor(usb_hub_descriptor_t * descriptor) { 77 //base size 78 size_t size = 7; 79 //variable size according to port count 80 size_t var_size = descriptor->ports_count / 8 + ((descriptor->ports_count % 8 > 0) ? 1 : 0); 81 size += 2 * var_size; 82 uint8_t * result = (uint8_t*) malloc(size); 83 //size 84 result[0] = size; 85 //descriptor type 86 result[1] = USB_DESCTYPE_HUB; 87 result[2] = descriptor->ports_count; 88 /// @fixme handling of endianness?? 89 result[3] = descriptor->hub_characteristics / 256; 90 result[4] = descriptor->hub_characteristics % 256; 91 result[5] = descriptor->pwr_on_2_good_time; 92 result[6] = descriptor->current_requirement; 93 94 size_t i; 95 for (i = 0; i < var_size; ++i) { 96 result[7 + i] = descriptor->devices_removable[i]; 97 } 98 for (i = 0; i < var_size; ++i) { 99 result[7 + var_size + i] = 255; 100 } 101 return result; 102 } 103 104 usb_hub_descriptor_t * usb_deserialize_hub_desriptor(void * serialized_descriptor) { 105 uint8_t * sdescriptor = (uint8_t*) serialized_descriptor; 106 if (sdescriptor[1] != USB_DESCTYPE_HUB) return NULL; 107 usb_hub_descriptor_t * result = (usb_hub_descriptor_t*) malloc(sizeof (usb_hub_descriptor_t)); 108 //uint8_t size = sdescriptor[0]; 109 result->ports_count = sdescriptor[2]; 110 /// @fixme handling of endianness?? 111 result->hub_characteristics = sdescriptor[4] + 256 * sdescriptor[3]; 112 result->pwr_on_2_good_time = sdescriptor[5]; 113 result->current_requirement = sdescriptor[6]; 114 size_t var_size = result->ports_count / 8 + ((result->ports_count % 8 > 0) ? 1 : 0); 115 result->devices_removable = (uint8_t*) malloc(var_size); 116 117 size_t i; 118 for (i = 0; i < var_size; ++i) { 119 result->devices_removable[i] = sdescriptor[7 + i]; 120 } 121 return result; 122 } 123 124 125 //********************************************* 126 // 127 // hub driver code 128 // 129 //********************************************* 130 59 131 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address); 60 132 133 usb_hcd_hub_info_t * usb_create_hub_info(device_t * device) { 134 usb_hcd_hub_info_t* result = (usb_hcd_hub_info_t*) malloc(sizeof (usb_hcd_hub_info_t)); 135 //get parent device 136 /// @TODO this code is not correct 137 device_t * my_hcd = device; 138 while (my_hcd->parent) 139 my_hcd = my_hcd->parent; 140 //dev-> 141 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name); 142 //we add the hub into the first hc 143 //link_t *link_hc = hc_list.next; 144 //usb_hc_device_t *hc = list_get_instance(link_hc, 145 // usb_hc_device_t, link); 146 //must get generic device info 147 148 149 return result; 150 } 151 61 152 /** Callback when new device is detected and must be handled by this driver. 62 153 * 63 154 * @param dev New device. 64 * @return Error code. 65 */ 66 static int add_device(device_t *dev) 67 { 155 * @return Error code.hub added, hurrah!\n" 156 */ 157 static int add_device(device_t *dev) { 68 158 /* 69 159 * FIXME: use some magic to determine whether hub or another HC … … 77 167 * We are the HC itself. 78 168 */ 79 usb_hc_device_t *hc_dev = malloc(sizeof (usb_hc_device_t));169 usb_hc_device_t *hc_dev = malloc(sizeof (usb_hc_device_t)); 80 170 list_initialize(&hc_dev->link); 81 171 hc_dev->transfer_ops = NULL; … … 99 189 list_append(&hc_dev->link, &hc_list); 100 190 191 //add keyboard 192 /// @TODO this is not correct code 193 194 /* 195 * Announce presence of child device. 196 */ 197 device_t *kbd = NULL; 198 match_id_t *match_id = NULL; 199 200 kbd = create_device(); 201 if (kbd == NULL) { 202 printf("ERROR: enomem\n"); 203 } 204 kbd->name = USB_KBD_DEVICE_NAME; 205 206 match_id = create_match_id(); 207 if (match_id == NULL) { 208 printf("ERROR: enomem\n"); 209 } 210 211 char *id; 212 rc = asprintf(&id, USB_KBD_DEVICE_NAME); 213 if (rc <= 0) { 214 printf("ERROR: enomem\n"); 215 return rc; 216 } 217 218 match_id->id = id; 219 match_id->score = 30; 220 221 add_match_id(&kbd->match_ids, match_id); 222 223 rc = child_device_register(kbd, dev); 224 if (rc != EOK) { 225 printf("ERROR: cannot register kbd\n"); 226 return rc; 227 } 228 229 printf("%s: registered root hub\n", dev->name); 101 230 return EOK; 231 232 233 102 234 } else { 103 235 usb_hc_device_t *hc = list_get_instance(hc_list.next, usb_hc_device_t, link); … … 109 241 * connected devices. 110 242 */ 111 112 return ENOTSUP; 243 //insert hub into list 244 //find owner hcd 245 device_t * my_hcd = dev; 246 while (my_hcd->parent) 247 my_hcd = my_hcd->parent; 248 //dev-> 249 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name); 250 my_hcd = dev; 251 while (my_hcd->parent) 252 my_hcd = my_hcd->parent; 253 //dev-> 254 255 printf("%s: owner hcd found: %s\n", hc_driver->name, my_hcd->name); 256 257 //create the hub structure 258 usb_hcd_hub_info_t * hub_info = usb_create_hub_info(dev); 259 260 261 //append into the list 262 //we add the hub into the first hc 263 list_append(&hub_info->link, &hc->hubs); 264 265 266 267 return EOK; 268 //return ENOTSUP; 113 269 } 114 270 } … … 123 279 * @param address New hub address. 124 280 */ 125 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) 126 { 281 static void set_hub_address(usb_hc_device_t *hc, usb_address_t address) { 127 282 printf("%s: setting hub address to %d\n", hc->generic->name, address); 128 283 usb_target_t target = {0, 0}; … … 139 294 140 295 rc = usb_hc_async_control_write_setup(hc, target, 141 &setup_packet, sizeof(setup_packet), &handle);296 &setup_packet, sizeof (setup_packet), &handle); 142 297 if (rc != EOK) { 143 298 return; … … 164 319 /** Check changes on all known hubs. 165 320 */ 166 static void check_hub_changes(void) 167 { 321 static void check_hub_changes(void) { 168 322 /* 169 323 * Iterate through all HCs. … … 171 325 link_t *link_hc; 172 326 for (link_hc = hc_list.next; 173 174 327 link_hc != &hc_list; 328 link_hc = link_hc->next) { 175 329 usb_hc_device_t *hc = list_get_instance(link_hc, 176 330 usb_hc_device_t, link); 177 331 /* 178 332 * Iterate through all their hubs. … … 180 334 link_t *link_hub; 181 335 for (link_hub = hc->hubs.next; 182 183 336 link_hub != &hc->hubs; 337 link_hub = link_hub->next) { 184 338 usb_hcd_hub_info_t *hub = list_get_instance(link_hub, 185 339 usb_hcd_hub_info_t, link); 186 340 187 341 /* … … 205 359 */ 206 360 usb_hc_async_interrupt_in(hc, target, 207 208 361 change_bitmap, byte_length, &actual_size, 362 &handle); 209 363 210 364 usb_hc_async_wait_for(handle); … … 234 388 * @return Error code. 235 389 */ 236 int usb_hcd_main(usb_hc_driver_t *hc) 237 { 390 int usb_hcd_main(usb_hc_driver_t *hc) { 238 391 hc_driver = hc; 239 392 hc_driver_generic.name = hc->name; -
uspace/lib/usbvirt/debug.c
re4dbfda r08f747e 60 60 61 61 if (print_prefix) { 62 printf("[vusb]: " , level);62 printf("[vusb]: "); 63 63 while (--level > 0) { 64 64 printf(" ");
Note:
See TracChangeset
for help on using the changeset viewer.