Changeset 14f8fd4 in mainline
- Timestamp:
- 2012-03-15T22:52:33Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bfb3d60
- Parents:
- 43cd499 (diff), dbbba51c (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. - Files:
-
- 7 added
- 62 edited
- 12 moved
Legend:
- Unmodified
- Added
- Removed
-
abi/include/syscall.h
r43cd499 r14f8fd4 92 92 SYS_IRQ_UNREGISTER, 93 93 94 SYS_SYSINFO_GET_KEYS_SIZE, 95 SYS_SYSINFO_GET_KEYS, 94 96 SYS_SYSINFO_GET_VAL_TYPE, 95 97 SYS_SYSINFO_GET_VALUE, -
boot/Makefile.common
r43cd499 r14f8fd4 165 165 $(USPACE_PATH)/app/locinfo/locinfo \ 166 166 $(USPACE_PATH)/app/mkfat/mkfat \ 167 $(USPACE_PATH)/app/mkexfat/mkexfat \ 167 168 $(USPACE_PATH)/app/mkmfs/mkmfs \ 168 169 $(USPACE_PATH)/app/lsusb/lsusb \ -
kernel/arch/amd64/include/context.h
r43cd499 r14f8fd4 38 38 #include <typedefs.h> 39 39 40 /* According to ABI the stack MUST be aligned on 40 /* 41 * According to ABI the stack MUST be aligned on 41 42 * 16-byte boundary. If it is not, the va_arg calling will 42 43 * panic sooner or later -
kernel/arch/arm32/include/context.h
r43cd499 r14f8fd4 27 27 */ 28 28 29 /** @addtogroup arm32 29 /** @addtogroup arm32 30 30 * @{ 31 31 */ -
kernel/arch/ia64/include/context.h
r43cd499 r14f8fd4 27 27 */ 28 28 29 /** @addtogroup ia64 29 /** @addtogroup ia64 30 30 * @{ 31 31 */ … … 47 47 * One item is put onto the stack to support get_stack_base(). 48 48 */ 49 #define SP_DELTA 49 #define SP_DELTA (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 50 50 51 51 /* RSE stack starts at the bottom of memory stack, hence the division by 2. */ 52 #define context_set(c, _pc, stack, size) 53 do { 54 (c)->pc = (uintptr_t) _pc; 55 (c)->bsp = ((uintptr_t) stack) + ALIGN_UP((size / 2), REGISTER_STACK_ALIGNMENT); 56 (c)->ar_pfs &= PFM_MASK; 57 (c)->sp = ((uintptr_t) stack) + ALIGN_UP((size / 2), STACK_ALIGNMENT) - SP_DELTA; 58 } while (0) ;52 #define context_set(c, _pc, stack, size) \ 53 do { \ 54 (c)->pc = (uintptr_t) _pc; \ 55 (c)->bsp = ((uintptr_t) stack) + ALIGN_UP((size / 2), REGISTER_STACK_ALIGNMENT); \ 56 (c)->ar_pfs &= PFM_MASK; \ 57 (c)->sp = ((uintptr_t) stack) + ALIGN_UP((size / 2), STACK_ALIGNMENT) - SP_DELTA; \ 58 } while (0) 59 59 60 60 /* -
kernel/arch/mips32/include/context.h
r43cd499 r14f8fd4 42 42 * Put one item onto the stack to support get_stack_base() and align it up. 43 43 */ 44 #define SP_DELTA ( 0+ ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))44 #define SP_DELTA (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 45 45 46 46 #ifndef __ASM__ -
kernel/arch/mips32/include/stack.h
r43cd499 r14f8fd4 27 27 */ 28 28 29 /** @addtogroup mips32 29 /** @addtogroup mips32 30 30 * @{ 31 31 */ … … 36 36 #define KERN_mips32_STACK_H_ 37 37 38 #define STACK_ITEM_SIZE 4 39 #define STACK_ALIGNMENT 8 38 #define STACK_ITEM_SIZE 4 39 #define STACK_ALIGNMENT 8 40 #define ABI_STACK_FRAME 32 40 41 41 42 #endif -
kernel/arch/mips32/src/start.S
r43cd499 r14f8fd4 241 241 /* $a1 contains physical address of bootinfo_t */ 242 242 jal arch_pre_main 243 nop243 addiu $sp, -ABI_STACK_FRAME 244 244 245 245 j main_bsp … … 281 281 282 282 move $a1, $sp 283 move $a0, $k0 283 284 jal exc_dispatch /* exc_dispatch(excno, register_space) */ 284 move $a0, $k0 285 addiu $sp, -ABI_STACK_FRAME 286 addiu $sp, ABI_STACK_FRAME 285 287 286 288 REGISTERS_LOAD $sp … … 323 325 sw $t0, ISTATE_OFFSET_T0($sp) /* save the 5th argument on the stack */ 324 326 sw $t1, ISTATE_OFFSET_T1($sp) /* save the 6th argument on the stack */ 327 325 328 jal syscall_handler 326 329 sw $v0, ISTATE_OFFSET_V0($sp) /* save the syscall number on the stack */ … … 357 360 move $sp, $k0 358 361 362 move $a0, $sp 359 363 jal tlb_refill 360 move $a0, $sp 364 addiu $sp, -ABI_STACK_FRAME 365 addiu $sp, ABI_STACK_FRAME 361 366 362 367 REGISTERS_LOAD $sp … … 366 371 cache_error_handler: 367 372 KERNEL_STACK_TO_K0 368 sub $k0, ISTATE_SOFT_SIZE 373 sub $k0, ISTATE_SOFT_SIZE 369 374 REGISTERS_STORE_AND_EXC_RESET $k0 370 375 sw $sp, ISTATE_OFFSET_SP($k0) 371 376 move $sp, $k0 372 377 378 move $a0, $sp 373 379 jal cache_error 374 move $a0, $sp 380 addiu $sp, -ABI_STACK_FRAME 381 addiu $sp, ABI_STACK_FRAME 375 382 376 383 REGISTERS_LOAD $sp -
kernel/arch/mips64/include/context.h
r43cd499 r14f8fd4 42 42 * Put one item onto the stack to support get_stack_base() and align it up. 43 43 */ 44 #define SP_DELTA ( 0+ ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))44 #define SP_DELTA (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 45 45 46 46 #ifndef __ASM__ -
kernel/arch/mips64/include/stack.h
r43cd499 r14f8fd4 38 38 #define STACK_ITEM_SIZE 8 39 39 #define STACK_ALIGNMENT 8 40 #define ABI_STACK_FRAME 64 40 41 41 42 #endif -
kernel/arch/mips64/src/start.S
r43cd499 r14f8fd4 241 241 /* $a1 contains physical address of bootinfo_t */ 242 242 jal arch_pre_main 243 nop243 addiu $sp, -ABI_STACK_FRAME 244 244 245 245 j main_bsp … … 281 281 282 282 move $a1, $sp 283 move $a0, $k0 283 284 jal exc_dispatch /* exc_dispatch(excno, register_space) */ 284 move $a0, $k0 285 addiu $sp, -ABI_STACK_FRAME 286 addiu $sp, ABI_STACK_FRAME 285 287 286 288 REGISTERS_LOAD $sp … … 323 325 sw $t0, ISTATE_OFFSET_T0($sp) /* save the 5th argument on the stack */ 324 326 sw $t1, ISTATE_OFFSET_T1($sp) /* save the 6th argument on the stack */ 327 325 328 jal syscall_handler 326 329 sw $v0, ISTATE_OFFSET_V0($sp) /* save the syscall number on the stack */ … … 357 360 move $sp, $k0 358 361 362 move $a0, $sp 359 363 jal tlb_refill 360 move $a0, $sp 364 addiu $sp, -ABI_STACK_FRAME 365 addiu $sp, ABI_STACK_FRAME 361 366 362 367 REGISTERS_LOAD $sp … … 366 371 cache_error_handler: 367 372 KERNEL_STACK_TO_K0 368 sub $k0, ISTATE_SOFT_SIZE 373 sub $k0, ISTATE_SOFT_SIZE 369 374 REGISTERS_STORE_AND_EXC_RESET $k0 370 375 sw $sp, ISTATE_OFFSET_SP($k0) 371 376 move $sp, $k0 372 377 378 move $a0, $sp 373 379 jal cache_error 374 move $a0, $sp 380 addiu $sp, -ABI_STACK_FRAME 381 addiu $sp, ABI_STACK_FRAME 375 382 376 383 REGISTERS_LOAD $sp -
kernel/arch/ppc32/src/ppc32.c
r43cd499 r14f8fd4 173 173 ofw_tree_walk_by_device_type("display", display_register, NULL); 174 174 #endif 175 /* Map OFW information into sysinfo */ 176 ofw_sysinfo_map(); 175 177 176 178 /* Initialize IRQ routing */ -
kernel/arch/sparc64/include/context.h
r43cd499 r14f8fd4 27 27 */ 28 28 29 /** @addtogroup sparc64 29 /** @addtogroup sparc64 30 30 * @{ 31 31 */ … … 40 40 #include <align.h> 41 41 42 #define SP_DELTA 42 #define SP_DELTA (STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE) 43 43 44 #define context_set(c, _pc, stack, size) \ 45 (c)->pc = ((uintptr_t) _pc) - 8; \ 46 (c)->sp = ((uintptr_t) stack) + ALIGN_UP((size), \ 47 STACK_ALIGNMENT) - (STACK_BIAS + SP_DELTA); \ 48 (c)->fp = -STACK_BIAS 49 44 #define context_set(c, _pc, stack, size) \ 45 do { \ 46 (c)->pc = ((uintptr_t) _pc) - 8; \ 47 (c)->sp = ((uintptr_t) stack) + ALIGN_UP((size), \ 48 STACK_ALIGNMENT) - (STACK_BIAS + SP_DELTA); \ 49 (c)->fp = -STACK_BIAS; \ 50 } while (0) 50 51 51 52 /* -
kernel/arch/sparc64/src/sun4u/sparc64.c
r43cd499 r14f8fd4 94 94 { 95 95 if (config.cpu_active == 1) { 96 /* Map OFW information into sysinfo */ 97 ofw_sysinfo_map(); 98 96 99 /* 97 100 * We have 2^11 different interrupt vectors. -
kernel/arch/sparc64/src/sun4v/sparc64.c
r43cd499 r14f8fd4 92 92 { 93 93 if (config.cpu_active == 1) { 94 /* Map OFW information into sysinfo */ 95 ofw_sysinfo_map(); 96 94 97 /* 95 98 * We have 2^11 different interrupt vectors. -
kernel/genarch/include/ofw/ofw_tree.h
r43cd499 r14f8fd4 67 67 68 68 extern void ofw_tree_init(ofw_tree_node_t *); 69 extern void ofw_ tree_print(void);69 extern void ofw_sysinfo_map(void); 70 70 71 71 extern const char *ofw_tree_node_name(const ofw_tree_node_t *); -
kernel/genarch/src/ofw/ofw_tree.c
r43cd499 r14f8fd4 38 38 #include <genarch/ofw/ofw_tree.h> 39 39 #include <mm/slab.h> 40 #include <sysinfo/sysinfo.h> 40 41 #include <memstr.h> 41 42 #include <str.h> … … 65 66 const char *name) 66 67 { 67 size_t i; 68 69 for (i = 0; i < node->properties; i++) { 68 for (size_t i = 0; i < node->properties; i++) { 70 69 if (str_cmp(node->property[i].name, name) == 0) 71 70 return &node->property[i]; … … 104 103 const char *name) 105 104 { 106 ofw_tree_node_t *cur;107 108 105 /* 109 106 * Try to find the disambigued name. 110 107 */ 111 for ( cur = node->child; cur; cur = cur->peer) {108 for (ofw_tree_node_t *cur = node->child; cur; cur = cur->peer) { 112 109 if (str_cmp(cur->da_name, name) == 0) 113 110 return cur; … … 121 118 * are not always fully-qualified. 122 119 */ 123 for ( cur = node->child; cur; cur = cur->peer) {120 for (ofw_tree_node_t *cur = node->child; cur; cur = cur->peer) { 124 121 if (str_cmp(ofw_tree_node_name(cur), name) == 0) 125 122 return cur; … … 141 138 const char *dtype) 142 139 { 143 ofw_tree_node_t *cur; 144 145 for (cur = node->child; cur; cur = cur->peer) { 140 for (ofw_tree_node_t *cur = node->child; cur; cur = cur->peer) { 146 141 ofw_tree_property_t *prop = 147 142 ofw_tree_getprop(cur, "device_type"); … … 172 167 phandle handle) 173 168 { 174 ofw_tree_node_t *cur; 175 176 for (cur = root; cur; cur = cur->peer) { 169 for (ofw_tree_node_t *cur = root; cur; cur = cur->peer) { 177 170 if (cur->node_handle == handle) 178 171 return cur; 179 172 180 173 if (cur->child) { 181 ofw_tree_node_t *node 182 =ofw_tree_find_node_by_handle(cur->child, handle);174 ofw_tree_node_t *node = 175 ofw_tree_find_node_by_handle(cur->child, handle); 183 176 if (node) 184 177 return node; … … 201 194 const char *dtype) 202 195 { 203 ofw_tree_node_t *cur; 204 205 for (cur = node->peer; cur; cur = cur->peer) { 196 for (ofw_tree_node_t *cur = node->peer; cur; cur = cur->peer) { 206 197 ofw_tree_property_t *prop = 207 198 ofw_tree_getprop(cur, "device_type"); … … 229 220 const char *name) 230 221 { 231 ofw_tree_node_t *cur; 232 233 for (cur = node->peer; cur; cur = cur->peer) { 234 ofw_tree_property_t *prop 235 = ofw_tree_getprop(cur, "name"); 222 for (ofw_tree_node_t *cur = node->peer; cur; cur = cur->peer) { 223 ofw_tree_property_t *prop = 224 ofw_tree_getprop(cur, "name"); 236 225 237 226 if ((!prop) || (!prop->value)) … … 259 248 260 249 ofw_tree_node_t *node = ofw_root; 261 size_t i;262 250 size_t j; 263 251 264 for ( i = 1; (i < str_size(path)) && (node); i = j + 1) {252 for (size_t i = 1; (i < str_size(path)) && (node); i = j + 1) { 265 253 for (j = i; (j < str_size(path)) && (path[j] != '/'); j++); 266 254 … … 294 282 const char *dtype, ofw_tree_walker_t walker, void *arg) 295 283 { 296 ofw_tree_node_t *cur; 297 298 for (cur = node; cur; cur = cur->peer) { 284 for (ofw_tree_node_t *cur = node; cur; cur = cur->peer) { 299 285 ofw_tree_property_t *prop = 300 286 ofw_tree_getprop(cur, "device_type"); … … 334 320 } 335 321 336 /** Print OpenFirmware device subtree rooted in a node. 322 /** Get OpenFirmware node properties. 323 * 324 * @param item Sysinfo item (unused). 325 * @param size Size of the returned data. 326 * @param dry_run Do not get the data, just calculate the size. 327 * @param data OpenFirmware node. 328 * 329 * @return Data containing a serialized dump of all node 330 * properties. If the return value is not NULL, it 331 * should be freed in the context of the sysinfo request. 332 * 333 */ 334 static void *ofw_sysinfo_properties(struct sysinfo_item *item, size_t *size, 335 bool dry_run, void *data) 336 { 337 ofw_tree_node_t *node = (ofw_tree_node_t *) data; 338 339 /* Compute serialized data size */ 340 *size = 0; 341 for (size_t i = 0; i < node->properties; i++) 342 *size += str_size(node->property[i].name) + 1 + 343 sizeof(node->property[i].size) + node->property[i].size; 344 345 if (dry_run) 346 return NULL; 347 348 void *dump = malloc(*size, FRAME_ATOMIC); 349 if (dump == NULL) { 350 *size = 0; 351 return NULL; 352 } 353 354 /* Serialize the data */ 355 size_t pos = 0; 356 for (size_t i = 0; i < node->properties; i++) { 357 /* Property name */ 358 str_cpy(dump + pos, *size - pos, node->property[i].name); 359 pos += str_size(node->property[i].name) + 1; 360 361 /* Value size */ 362 memcpy(dump + pos, &node->property[i].size, 363 sizeof(node->property[i].size)); 364 pos += sizeof(node->property[i].size); 365 366 /* Value */ 367 memcpy(dump + pos, node->property[i].value, 368 node->property[i].size); 369 pos += node->property[i].size; 370 } 371 372 return ((void *) dump); 373 } 374 375 /** Map OpenFirmware device subtree rooted in a node into sysinfo. 337 376 * 338 377 * Child nodes are processed recursively and peer nodes are processed … … 343 382 * 344 383 */ 345 static void ofw_tree_node_ print(ofw_tree_node_t *node, const char *path)384 static void ofw_tree_node_sysinfo(ofw_tree_node_t *node, const char *path) 346 385 { 347 386 char *cur_path = (char *) malloc(PATH_MAX_LEN, 0); 348 ofw_tree_node_t *cur; 349 350 for (cur = node; cur; cur = cur->peer) { 351 if ((cur->parent) && (path)) { 352 snprintf(cur_path, PATH_MAX_LEN, "%s/%s", path, cur->da_name); 353 printf("%s\n", cur_path); 354 } else { 355 snprintf(cur_path, PATH_MAX_LEN, "%s", cur->da_name); 356 printf("/\n"); 357 } 387 388 for (ofw_tree_node_t *cur = node; cur; cur = cur->peer) { 389 if ((cur->parent) && (path)) 390 snprintf(cur_path, PATH_MAX_LEN, "%s.%s", path, cur->da_name); 391 else 392 snprintf(cur_path, PATH_MAX_LEN, "firmware.%s", cur->da_name); 393 394 sysinfo_set_item_gen_data(cur_path, NULL, ofw_sysinfo_properties, 395 (void *) cur); 358 396 359 397 if (cur->child) 360 ofw_tree_node_ print(cur->child, cur_path);398 ofw_tree_node_sysinfo(cur->child, cur_path); 361 399 } 362 400 … … 364 402 } 365 403 366 /** Print the structure of the OpenFirmware device tree. */367 void ofw_ tree_print(void)368 { 369 ofw_tree_node_ print(ofw_root, NULL);404 /** Map the OpenFirmware device tree into sysinfo. */ 405 void ofw_sysinfo_map(void) 406 { 407 ofw_tree_node_sysinfo(ofw_root, NULL); 370 408 } 371 409 -
kernel/generic/include/context.h
r43cd499 r14f8fd4 41 41 42 42 #define context_set_generic(ctx, _pc, stack, size) \ 43 (ctx)->pc = (uintptr_t) (_pc); \ 44 (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; 43 do { \ 44 (ctx)->pc = (uintptr_t) (_pc); \ 45 (ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \ 46 } while (0) 45 47 46 48 extern int context_save_arch(context_t *ctx) __attribute__((returns_twice)); -
kernel/generic/include/sysinfo/sysinfo.h
r43cd499 r14f8fd4 1 1 /* 2 2 * Copyright (c) 2006 Jakub Vana 3 * Copyright (c) 2012 Martin Decky 3 4 * All rights reserved. 4 5 * … … 54 55 struct sysinfo_item; 55 56 56 /** Gerated numeric value function */ 57 typedef sysarg_t (*sysinfo_fn_val_t)(struct sysinfo_item *); 57 /** Generated numeric value function */ 58 typedef sysarg_t (*sysinfo_fn_val_t)(struct sysinfo_item *, void *); 59 60 /** Sysinfo generated numberic value data 61 * 62 */ 63 typedef struct { 64 sysinfo_fn_val_t fn; /**< Generated value function */ 65 void *data; /**< Private data */ 66 } sysinfo_gen_val_data_t; 58 67 59 68 /** Generated binary data function */ 60 typedef void *(*sysinfo_fn_data_t)(struct sysinfo_item *, size_t *, bool); 69 typedef void *(*sysinfo_fn_data_t)(struct sysinfo_item *, size_t *, bool, 70 void *); 71 72 /** Sysinfo generated binary data data 73 * 74 */ 75 typedef struct { 76 sysinfo_fn_data_t fn; /**< Generated binary data function */ 77 void *data; /**< Private data */ 78 } sysinfo_gen_data_data_t; 61 79 62 80 /** Sysinfo item binary data … … 72 90 */ 73 91 typedef union { 74 sysarg_t val; /**< Constant numberic value */75 sysinfo_ fn_val_t fn_val; /**< Generated numeric value function*/76 sysinfo_ fn_data_t fn_data; /**< Generated binary datafunction */77 sysinfo_ data_t data; /**< Constant binary data*/92 sysarg_t val; /**< Constant numberic value */ 93 sysinfo_data_t data; /**< Constant binary data */ 94 sysinfo_gen_val_data_t gen_val; /**< Generated numeric value function */ 95 sysinfo_gen_data_data_t gen_data; /**< Generated binary data function */ 78 96 } sysinfo_item_val_t; 79 97 … … 95 113 96 114 /** Generated subtree function */ 97 typedef sysinfo_return_t (*sysinfo_fn_subtree_t)(const char *, bool); 115 typedef sysinfo_return_t (*sysinfo_fn_subtree_t)(const char *, bool, void *); 116 117 /** Sysinfo generated subtree data 118 * 119 */ 120 typedef struct { 121 sysinfo_fn_subtree_t fn; /**< Generated subtree function */ 122 void *data; /**< Private data */ 123 } sysinfo_gen_subtree_data_t; 98 124 99 125 /** Sysinfo subtree (union) … … 101 127 */ 102 128 typedef union { 103 struct sysinfo_item *table; /**< Fixed subtree (list of subitems) */104 sysinfo_ fn_subtree_t get_data; /**< Generated subtree function*/129 struct sysinfo_item *table; /**< Fixed subtree (list of subitems) */ 130 sysinfo_gen_subtree_data_t generator; /**< Generated subtree */ 105 131 } sysinfo_subtree_t; 106 132 … … 123 149 extern void sysinfo_set_item_data(const char *, sysinfo_item_t **, void *, 124 150 size_t); 125 extern void sysinfo_set_item_ fn_val(const char *, sysinfo_item_t **,126 sysinfo_fn_val_t );127 extern void sysinfo_set_item_ fn_data(const char *, sysinfo_item_t **,128 sysinfo_fn_data_t );151 extern void sysinfo_set_item_gen_val(const char *, sysinfo_item_t **, 152 sysinfo_fn_val_t, void *); 153 extern void sysinfo_set_item_gen_data(const char *, sysinfo_item_t **, 154 sysinfo_fn_data_t, void *); 129 155 extern void sysinfo_set_item_undefined(const char *, sysinfo_item_t **); 130 156 131 157 extern void sysinfo_set_subtree_fn(const char *, sysinfo_item_t **, 132 sysinfo_fn_subtree_t );158 sysinfo_fn_subtree_t, void *); 133 159 134 160 extern void sysinfo_init(void); 135 161 extern void sysinfo_dump(sysinfo_item_t *); 136 162 163 extern sysarg_t sys_sysinfo_get_keys_size(void *, size_t, void *); 164 extern sysarg_t sys_sysinfo_get_keys(void *, size_t, void *, size_t, size_t *); 137 165 extern sysarg_t sys_sysinfo_get_val_type(void *, size_t); 138 166 extern sysarg_t sys_sysinfo_get_value(void *, size_t, void *); -
kernel/generic/src/main/main.c
r43cd499 r14f8fd4 221 221 frame_init(); 222 222 slab_cache_init(); 223 ra_init(); 223 ra_init(); 224 224 sysinfo_init(); 225 225 btree_init(); -
kernel/generic/src/mm/frame.c
r43cd499 r14f8fd4 1270 1270 /** Adjust bounds of physical memory region according to low/high memory split. 1271 1271 * 1272 * @param low[in] If true, the ad ujstment is performed to make the region1272 * @param low[in] If true, the adjustment is performed to make the region 1273 1273 * fit in the low memory. Otherwise the adjustment is 1274 1274 * performed to make the region fit in the high memory. … … 1282 1282 bool frame_adjust_zone_bounds(bool low, uintptr_t *basep, size_t *sizep) 1283 1283 { 1284 // FIXME: This might lead to overflow if the identity_size is too big 1285 // but it is necessary if the PA identity_base > identity_size 1286 const uintptr_t limit = 1287 KA2PA(config.identity_base) + config.identity_size; 1284 uintptr_t limit = KA2PA(config.identity_base) + config.identity_size; 1288 1285 1289 1286 if (low) { -
kernel/generic/src/syscall/syscall.c
r43cd499 r14f8fd4 184 184 185 185 /* Sysinfo syscalls. */ 186 (syshandler_t) sys_sysinfo_get_keys_size, 187 (syshandler_t) sys_sysinfo_get_keys, 186 188 (syshandler_t) sys_sysinfo_get_val_type, 187 189 (syshandler_t) sys_sysinfo_get_value, -
kernel/generic/src/sysinfo/stats.c
r43cd499 r14f8fd4 83 83 * 84 84 * @param item Sysinfo item (unused). 85 * @param data Unused. 85 86 * 86 87 * @return System uptime (in secords). 87 88 * 88 89 */ 89 static sysarg_t get_stats_uptime(struct sysinfo_item *item )90 static sysarg_t get_stats_uptime(struct sysinfo_item *item, void *data) 90 91 { 91 92 /* This doesn't have to be very accurate */ … … 98 99 * @param size Size of the returned data. 99 100 * @param dry_run Do not get the data, just calculate the size. 101 * @param data Unused. 100 102 * 101 103 * @return Data containing several stats_cpu_t structures. … … 104 106 */ 105 107 static void *get_stats_cpus(struct sysinfo_item *item, size_t *size, 106 bool dry_run )108 bool dry_run, void *data) 107 109 { 108 110 *size = sizeof(stats_cpu_t) * config.cpu_count; … … 249 251 ASSERT(interrupts_disabled()); 250 252 ASSERT(irq_spinlock_locked(&task->lock)); 251 253 252 254 stats_task->task_id = task->taskid; 253 255 str_cpy(stats_task->name, TASK_NAME_BUFLEN, task->name); … … 293 295 * @param size Size of the returned data. 294 296 * @param dry_run Do not get the data, just calculate the size. 297 * @param data Unused. 295 298 * 296 299 * @return Data containing several stats_task_t structures. … … 299 302 */ 300 303 static void *get_stats_tasks(struct sysinfo_item *item, size_t *size, 301 bool dry_run )304 bool dry_run, void *data) 302 305 { 303 306 /* Messing with task structures, avoid deadlock */ … … 350 353 ASSERT(interrupts_disabled()); 351 354 ASSERT(irq_spinlock_locked(&thread->lock)); 352 355 353 356 stats_thread->thread_id = thread->tid; 354 357 stats_thread->task_id = thread->task->taskid; … … 398 401 * @param size Size of the returned data. 399 402 * @param dry_run Do not get the data, just calculate the size. 403 * @param data Unused. 400 404 * 401 405 * @return Data containing several stats_task_t structures. … … 404 408 */ 405 409 static void *get_stats_threads(struct sysinfo_item *item, size_t *size, 406 bool dry_run )410 bool dry_run, void *data) 407 411 { 408 412 /* Messing with threads structures, avoid deadlock */ … … 451 455 * @param name Task ID (string-encoded number). 452 456 * @param dry_run Do not get the data, just calculate the size. 457 * @param data Unused. 453 458 * 454 459 * @return Sysinfo return holder. The type of the returned … … 460 465 * 461 466 */ 462 static sysinfo_return_t get_stats_task(const char *name, bool dry_run) 467 static sysinfo_return_t get_stats_task(const char *name, bool dry_run, 468 void *data) 463 469 { 464 470 /* Initially no return value */ … … 520 526 * @param name Thread ID (string-encoded number). 521 527 * @param dry_run Do not get the data, just calculate the size. 528 * @param data Unused. 522 529 * 523 530 * @return Sysinfo return holder. The type of the returned … … 529 536 * 530 537 */ 531 static sysinfo_return_t get_stats_thread(const char *name, bool dry_run) 538 static sysinfo_return_t get_stats_thread(const char *name, bool dry_run, 539 void *data) 532 540 { 533 541 /* Initially no return value */ … … 586 594 * @param size Size of the returned data. 587 595 * @param dry_run Do not get the data, just calculate the size. 596 * @param data Unused. 588 597 * 589 598 * @return Data containing several stats_exc_t structures. … … 592 601 */ 593 602 static void *get_stats_exceptions(struct sysinfo_item *item, size_t *size, 594 bool dry_run )603 bool dry_run, void *data) 595 604 { 596 605 *size = sizeof(stats_exc_t) * IVT_ITEMS; … … 634 643 * @param name Exception number (string-encoded number). 635 644 * @param dry_run Do not get the data, just calculate the size. 645 * @param data Unused. 636 646 * 637 647 * @return Sysinfo return holder. The type of the returned … … 643 653 * 644 654 */ 645 static sysinfo_return_t get_stats_exception(const char *name, bool dry_run) 655 static sysinfo_return_t get_stats_exception(const char *name, bool dry_run, 656 void *data) 646 657 { 647 658 /* Initially no return value */ … … 705 716 * @param size Size of the returned data. 706 717 * @param dry_run Do not get the data, just calculate the size. 718 * @param data Unused. 707 719 * 708 720 * @return Data containing stats_physmem_t. … … 711 723 */ 712 724 static void *get_stats_physmem(struct sysinfo_item *item, size_t *size, 713 bool dry_run )725 bool dry_run, void *data) 714 726 { 715 727 *size = sizeof(stats_physmem_t); … … 735 747 * @param size Size of the returned data. 736 748 * @param dry_run Do not get the data, just calculate the size. 749 * @param data Unused. 737 750 * 738 751 * @return Data several load_t values. … … 741 754 */ 742 755 static void *get_stats_load(struct sysinfo_item *item, size_t *size, 743 bool dry_run )756 bool dry_run, void *data) 744 757 { 745 758 *size = sizeof(load_t) * LOAD_STEPS; … … 810 823 mutex_initialize(&load_lock, MUTEX_PASSIVE); 811 824 812 sysinfo_set_item_ fn_val("system.uptime", NULL, get_stats_uptime);813 sysinfo_set_item_ fn_data("system.cpus", NULL, get_stats_cpus);814 sysinfo_set_item_ fn_data("system.physmem", NULL, get_stats_physmem);815 sysinfo_set_item_ fn_data("system.load", NULL, get_stats_load);816 sysinfo_set_item_ fn_data("system.tasks", NULL, get_stats_tasks);817 sysinfo_set_item_ fn_data("system.threads", NULL, get_stats_threads);818 sysinfo_set_item_ fn_data("system.exceptions", NULL, get_stats_exceptions);819 sysinfo_set_subtree_fn("system.tasks", NULL, get_stats_task );820 sysinfo_set_subtree_fn("system.threads", NULL, get_stats_thread );821 sysinfo_set_subtree_fn("system.exceptions", NULL, get_stats_exception );825 sysinfo_set_item_gen_val("system.uptime", NULL, get_stats_uptime, NULL); 826 sysinfo_set_item_gen_data("system.cpus", NULL, get_stats_cpus, NULL); 827 sysinfo_set_item_gen_data("system.physmem", NULL, get_stats_physmem, NULL); 828 sysinfo_set_item_gen_data("system.load", NULL, get_stats_load, NULL); 829 sysinfo_set_item_gen_data("system.tasks", NULL, get_stats_tasks, NULL); 830 sysinfo_set_item_gen_data("system.threads", NULL, get_stats_threads, NULL); 831 sysinfo_set_item_gen_data("system.exceptions", NULL, get_stats_exceptions, NULL); 832 sysinfo_set_subtree_fn("system.tasks", NULL, get_stats_task, NULL); 833 sysinfo_set_subtree_fn("system.threads", NULL, get_stats_thread, NULL); 834 sysinfo_set_subtree_fn("system.exceptions", NULL, get_stats_exception, NULL); 822 835 } 823 836 -
kernel/generic/src/sysinfo/sysinfo.c
r43cd499 r14f8fd4 1 1 /* 2 2 * Copyright (c) 2006 Jakub Vana 3 * Copyright (c) 2012 Martin Decky 3 4 * All rights reserved. 4 5 * … … 99 100 sizeof(sysinfo_item_t), 0, sysinfo_item_constructor, 100 101 sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED); 101 102 102 103 mutex_initialize(&sysinfo_lock, MUTEX_ACTIVE); 103 104 } … … 110 111 * @param subtree Current sysinfo (sub)tree root item. 111 112 * @param ret If the return value is NULL, this argument 112 * can be either also NULL (i.e. no item was113 * can be set either to NULL (i.e. no item was 113 114 * found and no data was generated) or the 114 115 * original pointer is used to store the value … … 125 126 { 126 127 ASSERT(subtree != NULL); 127 ASSERT(ret != NULL);128 128 129 129 sysinfo_item_t *cur = subtree; … … 151 151 case SYSINFO_SUBTREE_FUNCTION: 152 152 /* Get generated data */ 153 **ret = cur->subtree.get_data(name + i + 1, dry_run); 153 if (ret != NULL) 154 **ret = cur->subtree.generator.fn(name + i + 1, 155 dry_run, cur->subtree.generator.data); 156 154 157 return NULL; 155 158 default: 156 159 /* Not found, no data generated */ 157 *ret = NULL; 160 if (ret != NULL) 161 *ret = NULL; 162 158 163 return NULL; 159 164 } … … 164 169 165 170 /* Not found, no data generated */ 166 *ret = NULL; 171 if (ret != NULL) 172 *ret = NULL; 173 167 174 return NULL; 168 175 } … … 352 359 * a new root item (NULL for global sysinfo root). 353 360 * @param fn Numeric value generator function. 354 * 355 */ 356 void sysinfo_set_item_fn_val(const char *name, sysinfo_item_t **root, 357 sysinfo_fn_val_t fn) 361 * @param data Private data. 362 * 363 */ 364 void sysinfo_set_item_gen_val(const char *name, sysinfo_item_t **root, 365 sysinfo_fn_val_t fn, void *data) 358 366 { 359 367 /* Protect sysinfo tree consistency */ … … 366 374 if (item != NULL) { 367 375 item->val_type = SYSINFO_VAL_FUNCTION_VAL; 368 item->val.fn_val = fn; 376 item->val.gen_val.fn = fn; 377 item->val.gen_val.data = data; 369 378 } 370 379 … … 383 392 * a new root item (NULL for global sysinfo root). 384 393 * @param fn Binary data generator function. 385 * 386 */ 387 void sysinfo_set_item_fn_data(const char *name, sysinfo_item_t **root, 388 sysinfo_fn_data_t fn) 394 * @param data Private data. 395 * 396 */ 397 void sysinfo_set_item_gen_data(const char *name, sysinfo_item_t **root, 398 sysinfo_fn_data_t fn, void *data) 389 399 { 390 400 /* Protect sysinfo tree consistency */ … … 397 407 if (item != NULL) { 398 408 item->val_type = SYSINFO_VAL_FUNCTION_DATA; 399 item->val.fn_data = fn; 409 item->val.gen_data.fn = fn; 410 item->val.gen_data.data = data; 400 411 } 401 412 … … 431 442 * a new root item (NULL for global sysinfo root). 432 443 * @param fn Subtree generator function. 444 * @param data Private data to be passed to the generator. 433 445 * 434 446 */ 435 447 void sysinfo_set_subtree_fn(const char *name, sysinfo_item_t **root, 436 sysinfo_fn_subtree_t fn )448 sysinfo_fn_subtree_t fn, void *data) 437 449 { 438 450 /* Protect sysinfo tree consistency */ … … 448 460 if ((item != NULL) && (item->subtree_type != SYSINFO_SUBTREE_TABLE)) { 449 461 item->subtree_type = SYSINFO_SUBTREE_FUNCTION; 450 item->subtree.get_data = fn; 462 item->subtree.generator.fn = fn; 463 item->subtree.generator.data = data; 451 464 } 452 465 … … 456 469 /** Sysinfo dump indentation helper routine 457 470 * 458 * @param depth Number of indentation characters to print. 459 * 460 */ 461 NO_TRACE static void sysinfo_indent(unsigned int depth) 462 { 463 unsigned int i; 464 for (i = 0; i < depth; i++) 465 printf(" "); 471 * @param depth Number of spaces to print. 472 * 473 */ 474 NO_TRACE static void sysinfo_indent(size_t spaces) 475 { 476 for (size_t i = 0; i < spaces; i++) 477 printf(" "); 466 478 } 467 479 … … 470 482 * Should be called with sysinfo_lock held. 471 483 * 472 * @param root Root item of the current (sub)tree. 473 * @param depth Current depth in the sysinfo tree. 474 * 475 */ 476 NO_TRACE static void sysinfo_dump_internal(sysinfo_item_t *root, unsigned int depth) 477 { 478 sysinfo_item_t *cur = root; 479 484 * @param root Root item of the current (sub)tree. 485 * @param spaces Current indentation level. 486 * 487 */ 488 NO_TRACE static void sysinfo_dump_internal(sysinfo_item_t *root, size_t spaces) 489 { 480 490 /* Walk all siblings */ 481 while (cur != NULL) { 482 sysinfo_indent(depth); 491 for (sysinfo_item_t *cur = root; cur; cur = cur->next) { 492 size_t length; 493 494 if (spaces == 0) { 495 printf("%s", cur->name); 496 length = str_length(cur->name); 497 } else { 498 sysinfo_indent(spaces); 499 printf(".%s", cur->name); 500 length = str_length(cur->name) + 1; 501 } 483 502 484 503 sysarg_t val; … … 488 507 switch (cur->val_type) { 489 508 case SYSINFO_VAL_UNDEFINED: 490 printf(" + %s\n", cur->name);509 printf(" [undefined]\n"); 491 510 break; 492 511 case SYSINFO_VAL_VAL: 493 printf(" + %s -> %" PRIun" (%#" PRIxn ")\n", cur->name,494 cur->val.val , cur->val.val);512 printf(" -> %" PRIun" (%#" PRIxn ")\n", cur->val.val, 513 cur->val.val); 495 514 break; 496 515 case SYSINFO_VAL_DATA: 497 printf("+ %s (%zu bytes)\n", cur->name, 498 cur->val.data.size); 516 printf(" (%zu bytes)\n", cur->val.data.size); 499 517 break; 500 518 case SYSINFO_VAL_FUNCTION_VAL: 501 val = cur->val. fn_val(cur);502 printf(" + %s -> %" PRIun" (%#" PRIxn ") [generated]\n",503 cur->name, val,val);519 val = cur->val.gen_val.fn(cur, cur->val.gen_val.data); 520 printf(" -> %" PRIun" (%#" PRIxn ") [generated]\n", val, 521 val); 504 522 break; 505 523 case SYSINFO_VAL_FUNCTION_DATA: 506 524 /* N.B.: No data was actually returned (only a dry run) */ 507 (void) cur->val. fn_data(cur, &size, true);508 printf("+ %s (%zu bytes) [generated]\n", cur->name,509 525 (void) cur->val.gen_data.fn(cur, &size, true, 526 cur->val.gen_data.data); 527 printf(" (%zu bytes) [generated]\n", size); 510 528 break; 511 529 default: … … 518 536 break; 519 537 case SYSINFO_SUBTREE_TABLE: 520 sysinfo_dump_internal(cur->subtree.table, depth + 1);538 sysinfo_dump_internal(cur->subtree.table, spaces + length); 521 539 break; 522 540 case SYSINFO_SUBTREE_FUNCTION: 523 sysinfo_indent( depth + 1);524 printf(" + [generated subtree]\n");541 sysinfo_indent(spaces + length); 542 printf("<generated subtree>\n"); 525 543 break; 526 544 default: 527 sysinfo_indent( depth + 1);528 printf(" + [unknown subtree]\n");545 sysinfo_indent(spaces + length); 546 printf("<unknown subtree>\n"); 529 547 } 530 531 cur = cur->next;532 548 } 533 549 } … … 594 610 break; 595 611 case SYSINFO_VAL_FUNCTION_VAL: 596 ret.val = item->val. fn_val(item);612 ret.val = item->val.gen_val.fn(item, item->val.gen_val.data); 597 613 break; 598 614 case SYSINFO_VAL_FUNCTION_DATA: 599 ret.data.data = item->val. fn_data(item, &ret.data.size,600 dry_run );615 ret.data.data = item->val.gen_data.fn(item, &ret.data.size, 616 dry_run, item->val.gen_data.data); 601 617 break; 602 618 } … … 635 651 ASSERT(path); 636 652 637 if ((copy_from_uspace(path, ptr, size + 1) == 0) 638 &&(path[size] == 0)) {653 if ((copy_from_uspace(path, ptr, size + 1) == 0) && 654 (path[size] == 0)) { 639 655 /* 640 656 * Prevent other functions from messing with sysinfo while we … … 645 661 mutex_unlock(&sysinfo_lock); 646 662 } 663 647 664 free(path); 648 665 return ret; 666 } 667 668 /** Return sysinfo keys determined by name 669 * 670 * Should be called with sysinfo_lock held. 671 * 672 * @param name Sysinfo path. 673 * @param root Root item of the sysinfo (sub)tree. 674 * If it is NULL then consider the global 675 * sysinfo tree. 676 * @param dry_run Do not actually get any generated 677 * binary data, just calculate the size. 678 * 679 * @return Item value (constant or generated). 680 * 681 */ 682 NO_TRACE static sysinfo_return_t sysinfo_get_keys(const char *name, 683 sysinfo_item_t **root, bool dry_run) 684 { 685 if (root == NULL) 686 root = &global_root; 687 688 sysinfo_item_t *subtree = NULL; 689 690 if (name[0] != 0) { 691 /* Try to find the item */ 692 sysinfo_item_t *item = 693 sysinfo_find_item(name, *root, NULL, dry_run); 694 if ((item != NULL) && 695 (item->subtree_type == SYSINFO_SUBTREE_TABLE)) 696 subtree = item->subtree.table; 697 } else 698 subtree = *root; 699 700 sysinfo_return_t ret; 701 702 if (subtree != NULL) { 703 /* 704 * Calculate the size of subkeys. 705 */ 706 size_t size = 0; 707 for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) 708 size += str_size(cur->name) + 1; 709 710 if (dry_run) { 711 ret.tag = SYSINFO_VAL_DATA; 712 ret.data.data = NULL; 713 ret.data.size = size; 714 } else { 715 /* Allocate buffer for subkeys */ 716 char *names = (char *) malloc(size, FRAME_ATOMIC); 717 if (names == NULL) 718 return ret; 719 720 size_t pos = 0; 721 for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) { 722 str_cpy(names + pos, size - pos, cur->name); 723 pos += str_size(cur->name) + 1; 724 } 725 726 /* Correct return value */ 727 ret.tag = SYSINFO_VAL_DATA; 728 ret.data.data = (void *) names; 729 ret.data.size = size; 730 } 731 } else { 732 /* No item in the fixed sysinfo tree */ 733 ret.tag = SYSINFO_VAL_UNDEFINED; 734 } 735 736 return ret; 737 } 738 739 /** Return sysinfo keys determined by name from user space 740 * 741 * The path string passed from the user space has to be properly 742 * null-terminated (the last passed character must be null). 743 * 744 * @param ptr Sysinfo path in the user address space. 745 * @param size Size of the path string. 746 * @param dry_run Do not actually get any generated 747 * binary data, just calculate the size. 748 * 749 */ 750 NO_TRACE static sysinfo_return_t sysinfo_get_keys_uspace(void *ptr, size_t size, 751 bool dry_run) 752 { 753 sysinfo_return_t ret; 754 ret.tag = SYSINFO_VAL_UNDEFINED; 755 756 if (size > SYSINFO_MAX_PATH) 757 return ret; 758 759 char *path = (char *) malloc(size + 1, 0); 760 ASSERT(path); 761 762 if ((copy_from_uspace(path, ptr, size + 1) == 0) && 763 (path[size] == 0)) { 764 /* 765 * Prevent other functions from messing with sysinfo while we 766 * are reading it. 767 */ 768 mutex_lock(&sysinfo_lock); 769 ret = sysinfo_get_keys(path, NULL, dry_run); 770 mutex_unlock(&sysinfo_lock); 771 } 772 773 free(path); 774 return ret; 775 } 776 777 /** Get the sysinfo keys size (syscall) 778 * 779 * The path string passed from the user space has 780 * to be properly null-terminated (the last passed 781 * character must be null). 782 * 783 * @param path_ptr Sysinfo path in the user address space. 784 * @param path_size Size of the path string. 785 * @param size_ptr User space pointer where to store the 786 * keys size. 787 * 788 * @return Error code (EOK in case of no error). 789 * 790 */ 791 sysarg_t sys_sysinfo_get_keys_size(void *path_ptr, size_t path_size, 792 void *size_ptr) 793 { 794 int rc; 795 796 /* 797 * Get the keys. 798 * 799 * N.B.: There is no need to free any potential keys 800 * since we request a dry run. 801 */ 802 sysinfo_return_t ret = 803 sysinfo_get_keys_uspace(path_ptr, path_size, true); 804 805 /* Check return data tag */ 806 if (ret.tag == SYSINFO_VAL_DATA) 807 rc = copy_to_uspace(size_ptr, &ret.data.size, 808 sizeof(ret.data.size)); 809 else 810 rc = EINVAL; 811 812 return (sysarg_t) rc; 813 } 814 815 /** Get the sysinfo keys (syscall) 816 * 817 * The path string passed from the user space has 818 * to be properly null-terminated (the last passed 819 * character must be null). 820 * 821 * If the user space buffer size does not equal 822 * the actual size of the returned data, the data 823 * is truncated. 824 * 825 * The actual size of data returned is stored to 826 * size_ptr. 827 * 828 * @param path_ptr Sysinfo path in the user address space. 829 * @param path_size Size of the path string. 830 * @param buffer_ptr User space pointer to the buffer where 831 * to store the binary data. 832 * @param buffer_size User space buffer size. 833 * @param size_ptr User space pointer where to store the 834 * binary data size. 835 * 836 * @return Error code (EOK in case of no error). 837 * 838 */ 839 sysarg_t sys_sysinfo_get_keys(void *path_ptr, size_t path_size, 840 void *buffer_ptr, size_t buffer_size, size_t *size_ptr) 841 { 842 int rc; 843 844 /* Get the keys */ 845 sysinfo_return_t ret = sysinfo_get_keys_uspace(path_ptr, path_size, 846 false); 847 848 /* Check return data tag */ 849 if (ret.tag == SYSINFO_VAL_DATA) { 850 size_t size = min(ret.data.size, buffer_size); 851 rc = copy_to_uspace(buffer_ptr, ret.data.data, size); 852 if (rc == EOK) 853 rc = copy_to_uspace(size_ptr, &size, sizeof(size)); 854 855 free(ret.data.data); 856 } else 857 rc = EINVAL; 858 859 return (sysarg_t) rc; 649 860 } 650 861 … … 672 883 673 884 /* 674 * Map generated value types to constant types (user space does not care675 * whether the value is constant or generated).885 * Map generated value types to constant types (user space does 886 * not care whether the value is constant or generated). 676 887 */ 677 888 if (ret.tag == SYSINFO_VAL_FUNCTION_VAL) … … 701 912 { 702 913 int rc; 703 914 704 915 /* 705 916 * Get the item. 706 917 * 707 * N.B.: There is no need to free any potential generated binary data708 * since we request a dry run.918 * N.B.: There is no need to free any potential generated binary 919 * data since we request a dry run. 709 920 */ 710 921 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); … … 741 952 * Get the item. 742 953 * 743 * N.B.: There is no need to free any potential generated binary data744 * since we request a dry run.954 * N.B.: There is no need to free any potential generated binary 955 * data since we request a dry run. 745 956 */ 746 957 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); -
tools/toolchain.sh
r43cd499 r14f8fd4 53 53 EOF 54 54 55 BINUTILS_VERSION="2.2 1.1"56 BINUTILS_RELEASE=" a"57 GCC_VERSION="4.6. 2"58 GDB_VERSION="7. 3.1"55 BINUTILS_VERSION="2.22" 56 BINUTILS_RELEASE="" 57 GCC_VERSION="4.6.3" 58 GDB_VERSION="7.4" 59 59 60 60 BASEDIR="`pwd`" … … 274 274 GDB_SOURCE="ftp://ftp.gnu.org/gnu/gdb/" 275 275 276 download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" " bde820eac53fa3a8d8696667418557ad"277 download_fetch "${GCC_SOURCE}" "${GCC_CORE}" "7 80f614ab18c7a9066dec6387d7490b2"278 download_fetch "${GCC_SOURCE}" "${GCC_OBJC}" " 94043cc0d08394eddebed73f30ecad89"279 download_fetch "${GCC_SOURCE}" "${GCC_CPP}" " 87ecd60431e41096419dd8a10f76e46b"280 download_fetch "${GDB_SOURCE}" "${GDB}" " b89a5fac359c618dda97b88645ceab47"276 download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "ee0f10756c84979622b992a4a61ea3f5" 277 download_fetch "${GCC_SOURCE}" "${GCC_CORE}" "766091220c6a14fcaa2c06dd573e3758" 278 download_fetch "${GCC_SOURCE}" "${GCC_OBJC}" "48ba23770c34b1cb468f72618b4452c5" 279 download_fetch "${GCC_SOURCE}" "${GCC_CPP}" "37515158a0fb3d0800ec41a08c05e69e" 280 download_fetch "${GDB_SOURCE}" "${GDB}" "95a9a8305fed4d30a30a6dc28ff9d060" 281 281 } 282 282 -
uspace/Makefile
r43cd499 r14f8fd4 48 48 app/lsusb \ 49 49 app/mkfat \ 50 app/mkexfat \ 50 51 app/mkmfs \ 51 52 app/redir \ -
uspace/app/sysinfo/sysinfo.c
r43cd499 r14f8fd4 37 37 #include <stdio.h> 38 38 #include <sysinfo.h> 39 #include <malloc.h> 39 40 #include <sys/types.h> 40 41 41 static int print_item_val(char *ipath); 42 static int print_item_data(char *ipath); 43 44 static void dump_bytes_hex(char *data, size_t size); 45 static void dump_bytes_text(char *data, size_t size); 46 47 static void print_syntax(void); 48 49 int main(int argc, char *argv[]) 50 { 51 int rc; 52 char *ipath; 53 sysinfo_item_val_type_t tag; 54 55 if (argc != 2) { 56 print_syntax(); 57 return 1; 58 } 59 60 ipath = argv[1]; 61 62 tag = sysinfo_get_val_type(ipath); 63 64 /* Silence warning */ 65 rc = EOK; 66 67 switch (tag) { 68 case SYSINFO_VAL_UNDEFINED: 69 printf("Error: Sysinfo item '%s' not defined.\n", ipath); 70 rc = 2; 71 break; 72 case SYSINFO_VAL_VAL: 73 rc = print_item_val(ipath); 74 break; 75 case SYSINFO_VAL_DATA: 76 rc = print_item_data(ipath); 77 break; 78 default: 79 printf("Error: Sysinfo item '%s' with unknown value type.\n", 80 ipath); 81 rc = 2; 82 break; 83 } 84 85 return rc; 42 static void dump_bytes_hex(char *data, size_t size) 43 { 44 for (size_t i = 0; i < size; i++) { 45 if (i > 0) 46 putchar(' '); 47 printf("0x%02x", (uint8_t) data[i]); 48 } 49 } 50 51 static void dump_bytes_text(char *data, size_t size) 52 { 53 size_t offset = 0; 54 55 while (offset < size) { 56 wchar_t c = str_decode(data, &offset, size); 57 printf("%lc", (wint_t) c); 58 } 86 59 } 87 60 … … 89 62 { 90 63 sysarg_t value; 91 int rc; 92 93 rc = sysinfo_get_value(ipath, &value); 64 int rc = sysinfo_get_value(ipath, &value); 94 65 if (rc != EOK) { 95 66 printf("Error reading item '%s'.\n", ipath); 96 67 return rc; 97 68 } 98 69 99 70 printf("%s -> %" PRIu64 " (0x%" PRIx64 ")\n", ipath, 100 71 (uint64_t) value, (uint64_t) value); 101 72 102 73 return EOK; 103 74 } … … 105 76 static int print_item_data(char *ipath) 106 77 { 107 void *data;108 78 size_t size; 109 110 data = sysinfo_get_data(ipath, &size); 79 void *data = sysinfo_get_data(ipath, &size); 111 80 if (data == NULL) { 112 81 printf("Error reading item '%s'.\n", ipath); 113 82 return -1; 114 83 } 115 84 116 85 printf("%s -> ", ipath); 117 86 dump_bytes_hex(data, size); … … 119 88 dump_bytes_text(data, size); 120 89 fputs("')\n", stdout); 121 90 122 91 return EOK; 123 92 } 124 93 125 static void dump_bytes_hex(char *data, size_t size) 126 { 127 size_t i; 128 129 for (i = 0; i < size; ++i) { 130 if (i > 0) putchar(' '); 131 printf("0x%02x", (uint8_t) data[i]); 132 } 133 } 134 135 static void dump_bytes_text(char *data, size_t size) 136 { 137 wchar_t c; 138 size_t offset; 139 140 offset = 0; 141 142 while (offset < size) { 143 c = str_decode(data, &offset, size); 144 printf("%lc", (wint_t) c); 145 } 146 } 147 148 149 static void print_syntax(void) 150 { 151 printf("Syntax: sysinfo <item_path>\n"); 94 static int print_item_property(char *ipath, char *iprop) 95 { 96 size_t size; 97 void *data = sysinfo_get_property(ipath, iprop, &size); 98 if (data == NULL) { 99 printf("Error reading property '%s' of item '%s'.\n", iprop, 100 ipath); 101 return -1; 102 } 103 104 printf("%s property %s -> ", ipath, iprop); 105 dump_bytes_hex(data, size); 106 fputs(" ('", stdout); 107 dump_bytes_text(data, size); 108 fputs("')\n", stdout); 109 110 return EOK; 111 } 112 113 static void print_spaces(size_t spaces) 114 { 115 for (size_t i = 0; i < spaces; i++) 116 printf(" "); 117 } 118 119 static void print_keys(const char *path, size_t spaces) 120 { 121 size_t size; 122 char *keys = sysinfo_get_keys(path, &size); 123 if ((keys == NULL) || (size == 0)) 124 return; 125 126 size_t pos = 0; 127 while (pos < size) { 128 /* Process each key with sanity checks */ 129 size_t cur_size = str_nsize(keys + pos, size - pos); 130 if (keys[pos + cur_size] != 0) 131 break; 132 133 size_t path_size = str_size(path) + cur_size + 2; 134 char *cur_path = (char *) malloc(path_size); 135 if (cur_path == NULL) 136 break; 137 138 size_t length; 139 140 if (path[0] != 0) { 141 print_spaces(spaces); 142 printf(".%s\n", keys + pos); 143 length = str_length(keys + pos) + 1; 144 145 snprintf(cur_path, path_size, "%s.%s", path, keys + pos); 146 } else { 147 printf("%s\n", keys + pos); 148 length = str_length(keys + pos); 149 150 snprintf(cur_path, path_size, "%s", keys + pos); 151 } 152 153 print_keys(cur_path, spaces + length); 154 155 free(cur_path); 156 pos += cur_size + 1; 157 } 158 159 free(keys); 160 } 161 162 int main(int argc, char *argv[]) 163 { 164 int rc = 0; 165 166 if (argc < 2) { 167 /* Print keys */ 168 print_keys("", 0); 169 return rc; 170 } 171 172 char *ipath = argv[1]; 173 174 if (argc < 3) { 175 sysinfo_item_val_type_t tag = sysinfo_get_val_type(ipath); 176 177 switch (tag) { 178 case SYSINFO_VAL_UNDEFINED: 179 printf("Error: Sysinfo item '%s' not defined.\n", ipath); 180 rc = 2; 181 break; 182 case SYSINFO_VAL_VAL: 183 rc = print_item_val(ipath); 184 break; 185 case SYSINFO_VAL_DATA: 186 rc = print_item_data(ipath); 187 break; 188 default: 189 printf("Error: Sysinfo item '%s' with unknown value type.\n", 190 ipath); 191 rc = 2; 192 break; 193 } 194 195 return rc; 196 } 197 198 char *iprop = argv[2]; 199 rc = print_item_property(ipath, iprop); 200 return rc; 152 201 } 153 202 -
uspace/drv/bus/usb/ehci/Makefile
r43cd499 r14f8fd4 43 43 SOURCES = \ 44 44 main.c \ 45 pci.c45 res.c 46 46 47 47 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/bus/usb/ehci/main.c
r43cd499 r14f8fd4 44 44 #include <usb/host/hcd.h> 45 45 46 #include " pci.h"46 #include "res.h" 47 47 48 48 #define NAME "ehci" … … 81 81 int irq = 0; 82 82 83 int ret = pci_get_my_registers(device, ®_base, ®_size, &irq);83 int ret = get_my_registers(device, ®_base, ®_size, &irq); 84 84 CHECK_RET_RETURN(ret, 85 85 "Failed to get memory addresses for %" PRIun ": %s.\n", … … 88 88 reg_base, reg_size, irq); 89 89 90 ret = pci_disable_legacy(device, reg_base, reg_size, irq);90 ret = disable_legacy(device, reg_base, reg_size); 91 91 CHECK_RET_RETURN(ret, 92 92 "Failed to disable legacy USB: %s.\n", str_error(ret)); -
uspace/drv/bus/usb/ehci/res.c
r43cd499 r14f8fd4 39 39 #include <str_error.h> 40 40 #include <assert.h> 41 #include <as.h>42 41 #include <devman.h> 43 42 #include <ddi.h> 44 #include <libarch/ddi.h>45 #include <device/hw_res.h>46 47 43 #include <usb/debug.h> 48 #include <pci_dev_iface.h> 49 50 #include "pci.h" 51 52 #define PAGE_SIZE_MASK 0xfffff000 44 #include <device/hw_res_parsed.h> 45 #include <device/pci.h> 46 47 #include "res.h" 53 48 54 49 #define HCC_PARAMS_OFFSET 0x8 … … 72 67 #define WAIT_STEP 10 73 68 74 #define PCI_READ(size) \75 do { \76 async_sess_t *parent_sess = \77 devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle, \78 IPC_FLAG_BLOCKING); \79 if (!parent_sess) \80 return ENOMEM; \81 \82 sysarg_t add = (sysarg_t) address; \83 sysarg_t val; \84 \85 async_exch_t *exch = async_exchange_begin(parent_sess); \86 \87 const int ret = \88 async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE), \89 IPC_M_CONFIG_SPACE_READ_##size, add, &val); \90 \91 async_exchange_end(exch); \92 async_hangup(parent_sess); \93 \94 assert(value); \95 \96 *value = val; \97 return ret; \98 } while (0)99 100 static int pci_read32(const ddf_dev_t *dev, int address, uint32_t *value)101 {102 PCI_READ(32);103 }104 105 static int pci_read16(const ddf_dev_t *dev, int address, uint16_t *value)106 {107 PCI_READ(16);108 }109 110 static int pci_read8(const ddf_dev_t *dev, int address, uint8_t *value)111 {112 PCI_READ(8);113 }114 115 #define PCI_WRITE(size) \116 do { \117 async_sess_t *parent_sess = \118 devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle, \119 IPC_FLAG_BLOCKING); \120 if (!parent_sess) \121 return ENOMEM; \122 \123 sysarg_t add = (sysarg_t) address; \124 sysarg_t val = value; \125 \126 async_exch_t *exch = async_exchange_begin(parent_sess); \127 \128 const int ret = \129 async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE), \130 IPC_M_CONFIG_SPACE_WRITE_##size, add, val); \131 \132 async_exchange_end(exch); \133 async_hangup(parent_sess); \134 \135 return ret; \136 } while(0)137 138 static int pci_write32(const ddf_dev_t *dev, int address, uint32_t value)139 {140 PCI_WRITE(32);141 }142 143 static int pci_write16(const ddf_dev_t *dev, int address, uint16_t value)144 {145 PCI_WRITE(16);146 }147 148 static int pci_write8(const ddf_dev_t *dev, int address, uint8_t value)149 {150 PCI_WRITE(8);151 }152 69 153 70 /** Get address of registers and IRQ for given device. … … 159 76 * @return Error code. 160 77 */ 161 int pci_get_my_registers(const ddf_dev_t *dev,78 int get_my_registers(const ddf_dev_t *dev, 162 79 uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no) 163 80 { 164 assert(dev != NULL);81 assert(dev); 165 82 166 async_sess_t *parent_sess = 167 devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle, 168 IPC_FLAG_BLOCKING); 83 async_sess_t *parent_sess = devman_parent_device_connect( 84 EXCHANGE_SERIALIZE, dev->handle, IPC_FLAG_BLOCKING); 169 85 if (!parent_sess) 170 86 return ENOMEM; 171 87 172 hw_resource_list_t hw_resources; 173 int rc = hw_res_get_resource_list(parent_sess, &hw_resources); 174 if (rc != EOK) { 175 async_hangup(parent_sess); 176 return rc; 177 } 178 179 uintptr_t mem_address = 0; 180 size_t mem_size = 0; 181 bool mem_found = false; 182 183 int irq = 0; 184 bool irq_found = false; 185 186 size_t i; 187 for (i = 0; i < hw_resources.count; i++) { 188 hw_resource_t *res = &hw_resources.resources[i]; 189 switch (res->type) { 190 case INTERRUPT: 191 irq = res->res.interrupt.irq; 192 irq_found = true; 193 usb_log_debug2("Found interrupt: %d.\n", irq); 194 break; 195 case MEM_RANGE: 196 if (res->res.mem_range.address != 0 197 && res->res.mem_range.size != 0 ) { 198 mem_address = res->res.mem_range.address; 199 mem_size = res->res.mem_range.size; 200 usb_log_debug2("Found mem: %" PRIxn" %zu.\n", 201 mem_address, mem_size); 202 mem_found = true; 203 } 204 default: 205 break; 206 } 207 } 208 209 if (mem_found && irq_found) { 210 *mem_reg_address = mem_address; 211 *mem_reg_size = mem_size; 212 *irq_no = irq; 213 rc = EOK; 214 } else { 215 rc = ENOENT; 216 } 217 88 hw_res_list_parsed_t hw_res; 89 hw_res_list_parsed_init(&hw_res); 90 const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0); 218 91 async_hangup(parent_sess); 219 return rc; 92 if (ret != EOK) { 93 return ret; 94 } 95 96 if (hw_res.irqs.count != 1 || hw_res.mem_ranges.count != 1) { 97 hw_res_list_parsed_clean(&hw_res); 98 return ENOENT; 99 } 100 101 if (mem_reg_address) 102 *mem_reg_address = hw_res.mem_ranges.ranges[0].address; 103 if (mem_reg_size) 104 *mem_reg_size = hw_res.mem_ranges.ranges[0].size; 105 if (irq_no) 106 *irq_no = hw_res.irqs.irqs[0]; 107 108 hw_res_list_parsed_clean(&hw_res); 109 return EOK; 220 110 } 221 111 /*----------------------------------------------------------------------------*/ … … 225 115 * @return Error code. 226 116 */ 227 int pci_enable_interrupts(const ddf_dev_t *device)117 int enable_interrupts(const ddf_dev_t *device) 228 118 { 229 async_sess_t *parent_sess = 230 devman_parent_device_connect(EXCHANGE_SERIALIZE, device->handle, 231 IPC_FLAG_BLOCKING); 119 async_sess_t *parent_sess = devman_parent_device_connect( 120 EXCHANGE_SERIALIZE, device->handle, IPC_FLAG_BLOCKING); 232 121 if (!parent_sess) 233 122 return ENOMEM; … … 239 128 } 240 129 /*----------------------------------------------------------------------------*/ 241 /** Implements BIOS handoff routine as decribed in EHCI spec 242 * 243 * @param[in] device Device asking for interrupts 130 /** Implements BIOS hands-off routine as described in EHCI spec 131 * 132 * @param device EHCI device 133 * @param eecp Value of EHCI Extended Capabilities pointer. 244 134 * @return Error code. 245 135 */ 246 int pci_disable_legacy( 247 const ddf_dev_t *device, uintptr_t reg_base, size_t reg_size, int irq) 136 static int disable_extended_caps(const ddf_dev_t *device, unsigned eecp) 137 { 138 /* nothing to do */ 139 if (eecp == 0) 140 return EOK; 141 142 async_sess_t *parent_sess = devman_parent_device_connect( 143 EXCHANGE_SERIALIZE, device->handle, IPC_FLAG_BLOCKING); 144 if (!parent_sess) 145 return ENOMEM; 146 147 #define CHECK_RET_HANGUP_RETURN(ret, message...) \ 148 if (ret != EOK) { \ 149 usb_log_error(message); \ 150 async_hangup(parent_sess); \ 151 return ret; \ 152 } else (void)0 153 154 /* Read the first EEC. i.e. Legacy Support register */ 155 uint32_t usblegsup; 156 int ret = pci_config_space_read_32(parent_sess, 157 eecp + USBLEGSUP_OFFSET, &usblegsup); 158 CHECK_RET_HANGUP_RETURN(ret, 159 "Failed to read USBLEGSUP: %s.\n", str_error(ret)); 160 usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup); 161 162 /* Request control from firmware/BIOS by writing 1 to highest 163 * byte. (OS Control semaphore)*/ 164 usb_log_debug("Requesting OS control.\n"); 165 ret = pci_config_space_write_8(parent_sess, 166 eecp + USBLEGSUP_OFFSET + 3, 1); 167 CHECK_RET_HANGUP_RETURN(ret, "Failed to request OS EHCI control: %s.\n", 168 str_error(ret)); 169 170 size_t wait = 0; 171 /* Wait for BIOS to release control. */ 172 ret = pci_config_space_read_32( 173 parent_sess, eecp + USBLEGSUP_OFFSET, &usblegsup); 174 while ((wait < DEFAULT_WAIT) && (usblegsup & USBLEGSUP_BIOS_CONTROL)) { 175 async_usleep(WAIT_STEP); 176 ret = pci_config_space_read_32(parent_sess, 177 eecp + USBLEGSUP_OFFSET, &usblegsup); 178 wait += WAIT_STEP; 179 } 180 181 if ((usblegsup & USBLEGSUP_BIOS_CONTROL) == 0) { 182 usb_log_info("BIOS released control after %zu usec.\n", wait); 183 async_hangup(parent_sess); 184 return EOK; 185 } 186 187 /* BIOS failed to hand over control, this should not happen. */ 188 usb_log_warning( "BIOS failed to release control after " 189 "%zu usecs, force it.\n", wait); 190 ret = pci_config_space_write_32(parent_sess, 191 eecp + USBLEGSUP_OFFSET, USBLEGSUP_OS_CONTROL); 192 CHECK_RET_HANGUP_RETURN(ret, "Failed to force OS control: " 193 "%s.\n", str_error(ret)); 194 /* 195 * Check capability type here, value of 01h identifies the capability 196 * as Legacy Support. This extended capability requires one additional 197 * 32-bit register for control/status information and this register is 198 * located at offset EECP+04h 199 */ 200 if ((usblegsup & 0xff) == 1) { 201 /* Read the second EEC Legacy Support and Control register */ 202 uint32_t usblegctlsts; 203 ret = pci_config_space_read_32(parent_sess, 204 eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts); 205 CHECK_RET_HANGUP_RETURN(ret, "Failed to get USBLEGCTLSTS: %s.\n", 206 str_error(ret)); 207 usb_log_debug("USBLEGCTLSTS: %" PRIx32 ".\n", usblegctlsts); 208 /* 209 * Zero SMI enables in legacy control register. 210 * It should prevent pre-OS code from 211 * interfering. NOTE: Three upper bits are WC 212 */ 213 ret = pci_config_space_write_32(parent_sess, 214 eecp + USBLEGCTLSTS_OFFSET, 0xe0000000); 215 CHECK_RET_HANGUP_RETURN(ret, "Failed(%d) zero USBLEGCTLSTS.\n", ret); 216 udelay(10); 217 ret = pci_config_space_read_32(parent_sess, 218 eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts); 219 CHECK_RET_HANGUP_RETURN(ret, "Failed to get USBLEGCTLSTS 2: %s.\n", 220 str_error(ret)); 221 usb_log_debug("Zeroed USBLEGCTLSTS: %" PRIx32 ".\n", 222 usblegctlsts); 223 } 224 225 /* Read again Legacy Support register */ 226 ret = pci_config_space_read_32(parent_sess, 227 eecp + USBLEGSUP_OFFSET, &usblegsup); 228 CHECK_RET_HANGUP_RETURN(ret, "Failed to read USBLEGSUP: %s.\n", 229 str_error(ret)); 230 usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup); 231 async_hangup(parent_sess); 232 return EOK; 233 #undef CHECK_RET_HANGUP_RETURN 234 } 235 236 int disable_legacy(const ddf_dev_t *device, uintptr_t reg_base, size_t reg_size) 248 237 { 249 238 assert(device); 250 (void) pci_read16;251 (void) pci_read8;252 (void) pci_write16;253 239 254 240 #define CHECK_RET_RETURN(ret, message...) \ … … 274 260 usb_log_debug("Value of EECP: %x.\n", eecp); 275 261 276 /* Read the first EEC. i.e. Legacy Support register */ 277 uint32_t usblegsup; 278 ret = pci_read32(device, eecp + USBLEGSUP_OFFSET, &usblegsup); 279 CHECK_RET_RETURN(ret, "Failed to read USBLEGSUP: %s.\n", str_error(ret)); 280 usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup); 281 282 /* Request control from firmware/BIOS, by writing 1 to highest byte. 283 * (OS Control semaphore)*/ 284 usb_log_debug("Requesting OS control.\n"); 285 ret = pci_write8(device, eecp + USBLEGSUP_OFFSET + 3, 1); 286 CHECK_RET_RETURN(ret, "Failed to request OS EHCI control: %s.\n", 262 ret = disable_extended_caps(device, eecp); 263 CHECK_RET_RETURN(ret, "Failed to disable extended capabilities: %s.\n", 287 264 str_error(ret)); 288 265 289 size_t wait = 0; 290 /* Wait for BIOS to release control. */ 291 ret = pci_read32(device, eecp + USBLEGSUP_OFFSET, &usblegsup); 292 while ((wait < DEFAULT_WAIT) && (usblegsup & USBLEGSUP_BIOS_CONTROL)) { 293 async_usleep(WAIT_STEP); 294 ret = pci_read32(device, eecp + USBLEGSUP_OFFSET, &usblegsup); 295 wait += WAIT_STEP; 296 } 297 298 299 if ((usblegsup & USBLEGSUP_BIOS_CONTROL) == 0) { 300 usb_log_info("BIOS released control after %zu usec.\n", wait); 301 } else { 302 /* BIOS failed to hand over control, this should not happen. */ 303 usb_log_warning( "BIOS failed to release control after " 304 "%zu usecs, force it.\n", wait); 305 ret = pci_write32(device, eecp + USBLEGSUP_OFFSET, 306 USBLEGSUP_OS_CONTROL); 307 CHECK_RET_RETURN(ret, "Failed to force OS control: %s.\n", 308 str_error(ret)); 309 /* Check capability type here, A value of 01h 310 * identifies the capability as Legacy Support. 311 * This extended capability requires one 312 * additional 32-bit register for control/status information, 313 * and this register is located at offset EECP+04h 314 * */ 315 if ((usblegsup & 0xff) == 1) { 316 /* Read the second EEC 317 * Legacy Support and Control register */ 318 uint32_t usblegctlsts; 319 ret = pci_read32( 320 device, eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts); 321 CHECK_RET_RETURN(ret, 322 "Failed to get USBLEGCTLSTS: %s.\n", str_error(ret)); 323 usb_log_debug("USBLEGCTLSTS: %" PRIx32 ".\n", 324 usblegctlsts); 325 /* Zero SMI enables in legacy control register. 326 * It should prevent pre-OS code from interfering. */ 327 ret = pci_write32(device, eecp + USBLEGCTLSTS_OFFSET, 328 0xe0000000); /* three upper bits are WC */ 329 CHECK_RET_RETURN(ret, 330 "Failed(%d) zero USBLEGCTLSTS.\n", ret); 331 udelay(10); 332 ret = pci_read32( 333 device, eecp + USBLEGCTLSTS_OFFSET, &usblegctlsts); 334 CHECK_RET_RETURN(ret, 335 "Failed to get USBLEGCTLSTS 2: %s.\n", 336 str_error(ret)); 337 usb_log_debug("Zeroed USBLEGCTLSTS: %" PRIx32 ".\n", 338 usblegctlsts); 339 } 340 } 341 342 343 /* Read again Legacy Support register */ 344 ret = pci_read32(device, eecp + USBLEGSUP_OFFSET, &usblegsup); 345 CHECK_RET_RETURN(ret, "Failed to read USBLEGSUP: %s.\n", str_error(ret)); 346 usb_log_debug("USBLEGSUP: %" PRIx32 ".\n", usblegsup); 266 #undef CHECK_RET_RETURN 347 267 348 268 /* 349 * TURN OFF EHCI FOR NOW, DRIVER WILL REINITIALIZE IT 269 * TURN OFF EHCI FOR NOW, DRIVER WILL REINITIALIZE IT IF NEEDED 350 270 */ 351 271 … … 384 304 385 305 return ret; 386 #undef CHECK_RET_RETURN387 306 } 388 307 -
uspace/drv/bus/usb/ehci/res.h
r43cd499 r14f8fd4 38 38 #include <ddf/driver.h> 39 39 40 int pci_get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *);41 int pci_enable_interrupts(const ddf_dev_t *);42 int pci_disable_legacy(const ddf_dev_t *, uintptr_t, size_t, int);40 int get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *); 41 int enable_interrupts(const ddf_dev_t *); 42 int disable_legacy(const ddf_dev_t *, uintptr_t, size_t); 43 43 44 44 #endif -
uspace/drv/bus/usb/ohci/Makefile
r43cd499 r14f8fd4 50 50 ohci_batch.c \ 51 51 ohci_endpoint.c \ 52 pci.c \52 res.c \ 53 53 root_hub.c \ 54 54 hw_struct/endpoint_descriptor.c \ -
uspace/drv/bus/usb/ohci/hw_struct/hcca.h
r43cd499 r14f8fd4 46 46 uint16_t pad1; 47 47 uint32_t done_head; 48 uint32_t reserved[ 29];49 } __attribute__((packed, aligned))hcca_t;48 uint32_t reserved[30]; 49 } hcca_t; 50 50 51 51 static inline void * hcca_get(void) -
uspace/drv/bus/usb/ohci/ohci.c
r43cd499 r14f8fd4 42 42 43 43 #include "ohci.h" 44 #include " pci.h"44 #include "res.h" 45 45 #include "hc.h" 46 46 … … 180 180 int irq = 0; 181 181 182 ret = pci_get_my_registers(device, ®_base, ®_size, &irq);182 ret = get_my_registers(device, ®_base, ®_size, &irq); 183 183 CHECK_RET_DEST_FREE_RETURN(ret, 184 184 "Failed to get register memory addresses for %" PRIun ": %s.\n", … … 211 211 /* Try to enable interrupts */ 212 212 bool interrupts = false; 213 ret = pci_enable_interrupts(device);213 ret = enable_interrupts(device); 214 214 if (ret != EOK) { 215 215 usb_log_warning("Failed to enable interrupts: %s." -
uspace/drv/bus/usb/ohci/res.c
r43cd499 r14f8fd4 38 38 #include <errno.h> 39 39 #include <assert.h> 40 #include <as.h>41 40 #include <devman.h> 42 #include <ddi.h>43 #include <libarch/ddi.h>44 41 #include <device/hw_res_parsed.h> 45 42 46 43 #include <usb/debug.h> 47 #include <pci_dev_iface.h>48 44 49 #include " pci.h"45 #include "res.h" 50 46 51 47 /** Get address of registers and IRQ for given device. … … 57 53 * @return Error code. 58 54 */ 59 int pci_get_my_registers(ddf_dev_t *dev,55 int get_my_registers(const ddf_dev_t *dev, 60 56 uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no) 61 57 { … … 98 94 * @return Error code. 99 95 */ 100 int pci_enable_interrupts(ddf_dev_t *device)96 int enable_interrupts(const ddf_dev_t *device) 101 97 { 102 98 async_sess_t *parent_sess = … … 106 102 return ENOMEM; 107 103 108 bool enabled = hw_res_enable_interrupt(parent_sess);104 const bool enabled = hw_res_enable_interrupt(parent_sess); 109 105 async_hangup(parent_sess); 110 106 -
uspace/drv/bus/usb/ohci/res.h
r43cd499 r14f8fd4 32 32 * PCI related functions needed by OHCI driver. 33 33 */ 34 #ifndef DRV_OHCI_ PCI_H35 #define DRV_OHCI_ PCI_H34 #ifndef DRV_OHCI_RES_H 35 #define DRV_OHCI_RES_H 36 36 37 37 #include <ddf/driver.h> 38 38 39 int pci_get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *); 40 int pci_enable_interrupts(ddf_dev_t *); 41 int pci_disable_legacy(ddf_dev_t *); 39 int get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *); 40 int enable_interrupts(const ddf_dev_t *); 42 41 43 42 #endif -
uspace/drv/bus/usb/uhci/Makefile
r43cd499 r14f8fd4 44 44 hc.c \ 45 45 main.c \ 46 pci.c \46 res.c \ 47 47 root_hub.c \ 48 48 transfer_list.c \ -
uspace/drv/bus/usb/uhci/res.c
r43cd499 r14f8fd4 39 39 #include <devman.h> 40 40 #include <device/hw_res_parsed.h> 41 #include <device/pci.h> 41 42 42 #include <usb/debug.h> 43 #include <pci_dev_iface.h> 44 45 #include "pci.h" 43 #include "res.h" 46 44 47 45 /** Get I/O address of registers and IRQ for given device. … … 53 51 * @return Error code. 54 52 */ 55 int pci_get_my_registers(const ddf_dev_t *dev,53 int get_my_registers(const ddf_dev_t *dev, 56 54 uintptr_t *io_reg_address, size_t *io_reg_size, int *irq_no) 57 55 { 58 56 assert(dev); 59 assert(io_reg_address);60 assert(io_reg_size);61 assert(irq_no);62 57 63 58 async_sess_t *parent_sess = … … 97 92 * @return Error code. 98 93 */ 99 int pci_enable_interrupts(const ddf_dev_t *device)94 int enable_interrupts(const ddf_dev_t *device) 100 95 { 101 96 async_sess_t *parent_sess = … … 116 111 * @return Error code. 117 112 */ 118 int pci_disable_legacy(const ddf_dev_t *device)113 int disable_legacy(const ddf_dev_t *device) 119 114 { 120 115 assert(device); 121 116 122 async_sess_t *parent_sess = 123 devman_parent_device_connect(EXCHANGE_SERIALIZE, device->handle, 124 IPC_FLAG_BLOCKING); 117 async_sess_t *parent_sess = devman_parent_device_connect( 118 EXCHANGE_SERIALIZE, device->handle, IPC_FLAG_BLOCKING); 125 119 if (!parent_sess) 126 120 return ENOMEM; 127 121 128 /* See UHCI design guide for these values p.45, 129 * write all WC bits in USB legacy register */ 130 const sysarg_t address = 0xc0; 131 const sysarg_t value = 0xaf00; 122 /* See UHCI design guide page 45 for these values. 123 * Write all WC bits in USB legacy register */ 124 const int rc = pci_config_space_write_16(parent_sess, 0xc0, 0xaf00); 132 125 133 async_exch_t *exch = async_exchange_begin(parent_sess);134 135 const int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),136 IPC_M_CONFIG_SPACE_WRITE_16, address, value);137 138 async_exchange_end(exch);139 126 async_hangup(parent_sess); 140 141 127 return rc; 142 128 } -
uspace/drv/bus/usb/uhci/res.h
r43cd499 r14f8fd4 38 38 #include <ddf/driver.h> 39 39 40 int pci_get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *);41 int pci_enable_interrupts(const ddf_dev_t *);42 int pci_disable_legacy(const ddf_dev_t *);40 int get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *); 41 int enable_interrupts(const ddf_dev_t *); 42 int disable_legacy(const ddf_dev_t *); 43 43 44 44 #endif -
uspace/drv/bus/usb/uhci/uhci.c
r43cd499 r14f8fd4 41 41 42 42 #include "uhci.h" 43 #include "pci.h" 44 43 44 #include "res.h" 45 45 #include "hc.h" 46 46 #include "root_hub.h" … … 49 49 * and USB root hub */ 50 50 typedef struct uhci { 51 /** Pointer to DDF represen ation of UHCI host controller */51 /** Pointer to DDF representation of UHCI host controller */ 52 52 ddf_fun_t *hc_fun; 53 /** Pointer to DDF represen ation of UHCI root hub */53 /** Pointer to DDF representation of UHCI root hub */ 54 54 ddf_fun_t *rh_fun; 55 55 56 /** Internal driver's represen ation of UHCI host controller */56 /** Internal driver's representation of UHCI host controller */ 57 57 hc_t hc; 58 /** Internal driver's represen ation of UHCI root hub */58 /** Internal driver's representation of UHCI root hub */ 59 59 rh_t rh; 60 60 } uhci_t; … … 187 187 int irq = 0; 188 188 189 ret = pci_get_my_registers(device, ®_base, ®_size, &irq);189 ret = get_my_registers(device, ®_base, ®_size, &irq); 190 190 CHECK_RET_DEST_FREE_RETURN(ret, 191 191 "Failed to get I/O addresses for %" PRIun ": %s.\n", … … 194 194 (void *) reg_base, reg_size, irq); 195 195 196 ret = pci_disable_legacy(device);196 ret = disable_legacy(device); 197 197 CHECK_RET_DEST_FREE_RETURN(ret, 198 198 "Failed to disable legacy USB: %s.\n", str_error(ret)); … … 220 220 221 221 bool interrupts = false; 222 ret = pci_enable_interrupts(device);222 ret = enable_interrupts(device); 223 223 if (ret != EOK) { 224 224 usb_log_warning("Failed to enable interrupts: %s." -
uspace/lib/c/arch/amd64/include/fibril.h
r43cd499 r14f8fd4 38 38 #include <sys/types.h> 39 39 40 /* According to ABI the stack MUST be aligned on 40 /* 41 * According to ABI the stack MUST be aligned on 41 42 * 16-byte boundary. If it is not, the va_arg calling will 42 43 * panic sooner or later 43 44 */ 44 #define SP_DELTA 45 #define SP_DELTA 16 45 46 46 47 #define context_set(c, _pc, stack, size, ptls) \ -
uspace/lib/c/arch/arm32/include/fibril.h
r43cd499 r14f8fd4 27 27 */ 28 28 29 /** @addtogroup libcarm32 29 /** @addtogroup libcarm32 30 30 * @{ 31 31 */ … … 42 42 43 43 /** Size of a stack item */ 44 #define STACK_ITEM_SIZE 44 #define STACK_ITEM_SIZE 4 45 45 46 46 /** Stack alignment - see <a href="http://www.arm.com/support/faqdev/14269.html">ABI</a> for details */ 47 #define STACK_ALIGNMENT 47 #define STACK_ALIGNMENT 8 48 48 49 #define SP_DELTA 49 #define SP_DELTA (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 50 50 51 51 52 /** Sets data to the context. 53 * 52 /** Sets data to the context. 53 * 54 54 * @param c Context (#context_t). 55 55 * @param _pc Program counter. … … 62 62 (c)->pc = (sysarg_t) (_pc); \ 63 63 (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \ 64 64 (c)->tls = ((sysarg_t)(ptls)) + sizeof(tcb_t) + ARM_TP_OFFSET; \ 65 65 (c)->fp = 0; \ 66 66 } while (0) 67 67 68 /** Fibril context. 68 /** Fibril context. 69 69 * 70 70 * Only registers preserved accross function calls are included. r9 is used … … 91 91 } 92 92 93 94 93 #endif 95 94 -
uspace/lib/c/arch/ia32/include/fibril.h
r43cd499 r14f8fd4 38 38 #include <sys/types.h> 39 39 40 /* According to ABI the stack MUST be aligned on 40 /* 41 * According to ABI the stack MUST be aligned on 41 42 * 16-byte boundary. If it is not, the va_arg calling will 42 43 * panic sooner or later -
uspace/lib/c/arch/ia64/include/fibril.h
r43cd499 r14f8fd4 27 27 */ 28 28 29 /** @addtogroup libcia64 29 /** @addtogroup libcia64 30 30 * @{ 31 31 */ … … 45 45 * No need to allocate scratch area. 46 46 */ 47 #define SP_DELTA 47 #define SP_DELTA (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 48 48 49 #define PFM_MASK 49 #define PFM_MASK (~0x3fffffffff) 50 50 51 #define PSTHREAD_INITIAL_STACK_PAGES_NO 2 51 #define PSTHREAD_INITIAL_STACK_PAGES_NO 2 52 52 53 /* Stack is divided into two equal parts (for memory stack and register stack). */ 53 #define PSTHREAD_INITIAL_STACK_DIVISION 254 #define PSTHREAD_INITIAL_STACK_DIVISION 2 54 55 55 #define context_set(c, _pc, stack, size, tls) \ 56 do { \ 57 (c)->pc = (uint64_t) _pc; \ 58 (c)->bsp = ((uint64_t) stack) + size / PSTHREAD_INITIAL_STACK_DIVISION; \ 59 (c)->ar_pfs &= PFM_MASK; \ 60 (c)->sp = ((uint64_t) stack) + ALIGN_UP((size / PSTHREAD_INITIAL_STACK_DIVISION), STACK_ALIGNMENT) - SP_DELTA; \ 61 (c)->tp = (uint64_t) tls; \ 62 } while (0); 63 56 #define context_set(c, _pc, stack, size, tls) \ 57 do { \ 58 (c)->pc = (uint64_t) _pc; \ 59 (c)->bsp = ((uint64_t) stack) + \ 60 size / PSTHREAD_INITIAL_STACK_DIVISION; \ 61 (c)->ar_pfs &= PFM_MASK; \ 62 (c)->sp = ((uint64_t) stack) + \ 63 ALIGN_UP((size / PSTHREAD_INITIAL_STACK_DIVISION), STACK_ALIGNMENT) - \ 64 SP_DELTA; \ 65 (c)->tp = (uint64_t) tls; \ 66 } while (0) 64 67 65 68 /* -
uspace/lib/c/arch/mips32/Makefile.inc
r43cd499 r14f8fd4 28 28 29 29 ARCH_SOURCES = \ 30 arch/$(UARCH)/src/entry. s\31 arch/$(UARCH)/src/entryjmp. s\32 arch/$(UARCH)/src/thread_entry. s\30 arch/$(UARCH)/src/entry.S \ 31 arch/$(UARCH)/src/entryjmp.S \ 32 arch/$(UARCH)/src/thread_entry.S \ 33 33 arch/$(UARCH)/src/syscall.c \ 34 34 arch/$(UARCH)/src/fibril.S \ -
uspace/lib/c/arch/mips32/include/atomic.h
r43cd499 r14f8fd4 67 67 " ll %0, %1\n" 68 68 " addu %0, %0, %3\n" /* same as add, but never traps on overflow */ 69 " 69 " move %2, %0\n" 70 70 " sc %0, %1\n" 71 71 " beq %0, %4, 1b\n" /* if the atomic operation failed, try again */ -
uspace/lib/c/arch/mips32/include/config.h
r43cd499 r14f8fd4 36 36 #define LIBC_mips32_CONFIG_H_ 37 37 38 #define PAGE_WIDTH 39 #define PAGE_SIZE 38 #define PAGE_WIDTH 14 39 #define PAGE_SIZE (1 << PAGE_WIDTH) 40 40 41 41 #endif -
uspace/lib/c/arch/mips32/include/faddr.h
r43cd499 r14f8fd4 38 38 #include <libarch/types.h> 39 39 40 #define FADDR(fptr) 40 #define FADDR(fptr) ((uintptr_t) (fptr)) 41 41 42 42 #endif -
uspace/lib/c/arch/mips32/include/fibril.h
r43cd499 r14f8fd4 38 38 39 39 #include <sys/types.h> 40 #include <libarch/stack.h> 41 #include <align.h> 40 42 41 /* We define our own context_set, because we need to set 42 * the TLS pointer to the tcb+0x7000 43 #define SP_DELTA (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 44 45 /* 46 * We define our own context_set, because we need to set 47 * the TLS pointer to the tcb + 0x7000 43 48 * 44 49 * See tls_set in thread.h 45 50 */ 46 #define context_set(c, _pc, stack, size, ptls) \ 47 (c)->pc = (sysarg_t) (_pc); \ 48 (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \ 49 (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t); 50 51 52 /* +16 is just for sure that the called function 53 * have space to store it's arguments 54 */ 55 #define SP_DELTA (8+16) 51 #define context_set(c, _pc, stack, size, ptls) \ 52 do { \ 53 (c)->pc = (sysarg_t) (_pc); \ 54 (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \ 55 (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t); \ 56 } while (0) 56 57 57 58 typedef struct { -
uspace/lib/c/arch/mips32/src/entry.S
r43cd499 r14f8fd4 27 27 # 28 28 29 #include <libarch/stack.h> 30 29 31 .text 30 32 .section .init, "ax" … … 41 43 .ent __entry 42 44 __entry: 43 .frame $sp, 32, $3144 .cpload $ 2545 .frame $sp, ABI_STACK_FRAME, $ra 46 .cpload $t9 45 47 46 # FIXME: Reflect exactly ABI specs here 48 # Allocate the stack frame. 49 addiu $sp, -ABI_STACK_FRAME 47 50 48 addiu $sp, -3249 .cprestore 16 # Allow PIC code51 # Allow PIC code 52 .cprestore 16 50 53 51 # Pass pcb_ptr to __main() as the first argument. pcb_ptris already54 # Pass pcb_ptr to __main() as the first argument. It is already 52 55 # in $a0. As the first argument is passed in $a0, no operation 53 56 # is needed. … … 55 58 jal __main 56 59 nop 57 .end 60 61 # 62 # Not reached. 63 # 64 addiu $sp, ABI_STACK_FRAME 65 .end __entry -
uspace/lib/c/arch/mips32/src/entryjmp.S
r43cd499 r14f8fd4 27 27 # 28 28 29 #include <libarch/stack.h> 30 29 31 .text 30 32 .section .text … … 41 43 entry_point_jmp: 42 44 # tmp := entry_point 43 move $ 25, $a045 move $t9, $a0 44 46 45 47 # Pass pcb to the entry point in $a0 46 48 move $a0, $a1 47 jr $25 48 nop 49 .end 49 50 jr $t9 51 addiu $sp, -ABI_STACK_FRAME 52 addiu $sp, ABI_STACK_FRAME 53 .end entry_point_jmp -
uspace/lib/c/arch/mips32/src/fibril.S
r43cd499 r14f8fd4 33 33 34 34 #include <libarch/context_offset.h> 35 35 36 36 .global context_save 37 37 .global context_restore 38 38 39 39 context_save: 40 40 CONTEXT_SAVE_ARCH_CORE $a0 41 41 42 42 # context_save returns 1 43 43 j $ra 44 li $v0, 1 45 44 li $v0, 1 45 46 46 context_restore: 47 47 CONTEXT_RESTORE_ARCH_CORE $a0 48 49 # Just for the jump into first function, but one instruction 50 # should not bother us 51 move $t9, $ra 48 49 # Just for the jump into first function, 50 # but one instruction should not bother us 51 move $t9, $ra 52 52 53 # context_restore returns 0 53 54 j $ra 54 xor $v0, $v0 55 55 xor $v0, $v0 -
uspace/lib/c/arch/mips32/src/syscall.c
r43cd499 r14f8fd4 57 57 "r" (__mips_reg_t1), 58 58 "r" (__mips_reg_v0) 59 : "%ra" /* We are a function call, although C does not 60 * know it */ 59 /* 60 * We are a function call, although C 61 * does not know it. 62 */ 63 : "%ra" 61 64 ); 62 65 -
uspace/lib/c/arch/mips32/src/thread_entry.S
r43cd499 r14f8fd4 27 27 # 28 28 29 #include <libarch/stack.h> 30 29 31 .text 30 32 … … 40 42 .ent __thread_entry 41 43 __thread_entry: 42 .frame $sp, 32, $3143 .cpload $ 2544 .frame $sp, ABI_STACK_FRAME, $ra 45 .cpload $t9 44 46 45 47 # 46 48 # v0 contains address of uarg. 47 49 # 48 add $ 4, $2, 050 add $a0, $v0, 0 49 51 50 addiu $sp, -32 52 # Allocate the stack frame. 53 addiu $sp, -ABI_STACK_FRAME 54 55 # Allow PIC code 51 56 .cprestore 16 52 57 … … 57 62 # Not reached. 58 63 # 64 addiu $sp, ABI_STACK_FRAME 59 65 .end __thread_entry -
uspace/lib/c/arch/mips32eb/Makefile.inc
r43cd499 r14f8fd4 28 28 29 29 ARCH_SOURCES = \ 30 arch/$(UARCH)/src/entry. s\31 arch/$(UARCH)/src/entryjmp. s\32 arch/$(UARCH)/src/thread_entry. s\30 arch/$(UARCH)/src/entry.S \ 31 arch/$(UARCH)/src/entryjmp.S \ 32 arch/$(UARCH)/src/thread_entry.S \ 33 33 arch/$(UARCH)/src/syscall.c \ 34 34 arch/$(UARCH)/src/fibril.S \ -
uspace/lib/c/arch/mips64/Makefile.inc
r43cd499 r14f8fd4 28 28 29 29 ARCH_SOURCES = \ 30 arch/$(UARCH)/src/entry. s\31 arch/$(UARCH)/src/entryjmp. s\32 arch/$(UARCH)/src/thread_entry. s\30 arch/$(UARCH)/src/entry.S \ 31 arch/$(UARCH)/src/entryjmp.S \ 32 arch/$(UARCH)/src/thread_entry.S \ 33 33 arch/$(UARCH)/src/syscall.c \ 34 34 arch/$(UARCH)/src/fibril.S \ -
uspace/lib/c/arch/mips64/include/fibril.h
r43cd499 r14f8fd4 38 38 39 39 #include <sys/types.h> 40 #include <libarch/stack.h> 41 #include <align.h> 40 42 41 /* We define our own context_set, because we need to set 42 * the TLS pointer to the tcb+0x7000 43 #define SP_DELTA (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT)) 44 45 /* 46 * We define our own context_set, because we need to set 47 * the TLS pointer to the tcb + 0x7000 43 48 * 44 49 * See tls_set in thread.h 45 50 */ 46 51 #define context_set(c, _pc, stack, size, ptls) \ 47 (c)->pc = (sysarg_t) (_pc); \ 48 (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \ 49 (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t); 50 51 /* +16 is just for sure that the called function 52 * have space to store it's arguments 53 */ 54 #define SP_DELTA (8 + 16) 52 do { \ 53 (c)->pc = (sysarg_t) (_pc); \ 54 (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \ 55 (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t); \ 56 } while (0) 55 57 56 58 typedef struct { -
uspace/lib/c/arch/mips64/src/entry.S
r43cd499 r14f8fd4 27 27 # 28 28 29 #include <libarch/stack.h> 30 29 31 .text 30 32 .section .init, "ax" … … 41 43 .ent __entry 42 44 __entry: 43 .frame $sp, 32, $31 44 .cpload $25 45 46 # Mips o32 may store its arguments on stack, make space (16 bytes), 47 # so that it could work with -O0 48 # Make space additional 16 bytes for the stack frame 49 50 addiu $sp, -32 51 .cprestore 16 # Allow PIC code 52 53 # Pass pcb_ptr to __main() as the first argument. pcb_ptr is already 45 .frame $sp, ABI_STACK_FRAME, $ra 46 .cpload $t9 47 48 # Allocate the stack frame. 49 addiu $sp, -ABI_STACK_FRAME 50 51 # Allow PIC code 52 .cprestore 16 53 54 # Pass pcb_ptr to __main() as the first argument. It is already 54 55 # in $a0. As the first argument is passed in $a0, no operation 55 56 # is needed. 56 57 57 58 jal __main 58 59 nop 59 .end 60 61 # 62 # Not reached. 63 # 64 addiu $sp, ABI_STACK_FRAME 65 .end __entry -
uspace/lib/c/arch/mips64/src/entryjmp.S
r43cd499 r14f8fd4 27 27 # 28 28 29 #include <libarch/stack.h> 30 29 31 .text 30 32 .section .text … … 34 36 ## void entry_point_jmp(void *entry_point, void *pcb); 35 37 # 36 # $a0 (=$4) 37 # $a1 (=$5) 38 # $a0 (=$4) contains entry_point 39 # $a1 (=$5) contains pcb 38 40 # 39 41 # Jump to program entry point … … 41 43 entry_point_jmp: 42 44 # tmp := entry_point 43 move $ 25, $a044 45 move $t9, $a0 46 45 47 # Pass pcb to the entry point in $a0 46 48 move $a0, $a1 47 jr $25 48 nop 49 .end 49 50 jr $t9 51 addiu $sp, -ABI_STACK_FRAME 52 addiu $sp, ABI_STACK_FRAME 53 .end entry_point_jmp -
uspace/lib/c/arch/mips64/src/thread_entry.S
r43cd499 r14f8fd4 27 27 # 28 28 29 #include <libarch/stack.h> 30 29 31 .text 30 32 31 33 .set noat 32 34 .set noreorder 33 35 .option pic2 34 36 35 37 .globl __thread_entry 36 38 … … 40 42 .ent __thread_entry 41 43 __thread_entry: 42 .frame $sp, 32, $3143 .cpload $ 2544 44 .frame $sp, ABI_STACK_FRAME, $ra 45 .cpload $t9 46 45 47 # 46 48 # v0 contains address of uarg. 47 49 # 48 add $4, $2, 0 49 # Mips o32 may store its arguments on stack, make space 50 addiu $sp, -32 50 add $a0, $v0, 0 51 52 # Allocate the stack frame. 53 addiu $sp, -ABI_STACK_FRAME 54 55 # Allow PIC code 51 56 .cprestore 16 52 57 53 58 jal __thread_main 54 59 nop 55 60 56 61 # 57 62 # Not reached. 58 63 # 64 addiu $sp, ABI_STACK_FRAME 59 65 .end __thread_entry -
uspace/lib/c/arch/ppc32/include/fibril.h
r43cd499 r14f8fd4 27 27 */ 28 28 29 /** @addtogroup libcppc32 29 /** @addtogroup libcppc32 30 30 * @{ 31 31 */ … … 38 38 #include <sys/types.h> 39 39 40 /* We define our own context_set, because we need to set 41 * the TLS pointer to the tcb+0x7000 40 #define SP_DELTA 16 41 42 /* 43 * We define our own context_set, because we need to set 44 * the TLS pointer to the tcb + 0x7000 42 45 * 43 46 * See tls_set in thread.h 44 47 */ 45 #define context_set(c, _pc, stack, size, ptls) 46 (c)->pc = (sysarg_t) (_pc);\47 (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA;\48 (c)->tls = ((sysarg_t) (ptls)) + 0x7000 + sizeof(tcb_t);49 50 #define SP_DELTA 16 48 #define context_set(c, _pc, stack, size, ptls) \ 49 do { \ 50 (c)->pc = (sysarg_t) (_pc); \ 51 (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \ 52 (c)->tls = ((sysarg_t) (ptls)) + 0x7000 + sizeof(tcb_t); \ 53 } while (0) 51 54 52 55 typedef struct { -
uspace/lib/c/arch/sparc64/include/fibril.h
r43cd499 r14f8fd4 40 40 #include <align.h> 41 41 42 #define SP_DELTA 42 #define SP_DELTA (STACK_WINDOW_SAVE_AREA_SIZE + STACK_ARG_SAVE_AREA_SIZE) 43 43 44 44 #define context_set(c, _pc, stack, size, ptls) \ … … 50 50 (c)->tp = (uint64_t) ptls; \ 51 51 } while (0) 52 52 53 53 /* 54 54 * Save only registers that must be preserved across -
uspace/lib/c/generic/str.c
r43cd499 r14f8fd4 259 259 260 260 return offset; 261 } 262 263 /** Get size of string with size limit. 264 * 265 * Get the number of bytes which are used by the string @a str 266 * (excluding the NULL-terminator), but no more than @max_size bytes. 267 * 268 * @param str String to consider. 269 * @param max_size Maximum number of bytes to measure. 270 * 271 * @return Number of bytes used by the string 272 * 273 */ 274 size_t str_nsize(const char *str, size_t max_size) 275 { 276 size_t size = 0; 277 278 while ((*str++ != 0) && (size < max_size)) 279 size++; 280 281 return size; 282 } 283 284 /** Get size of wide string with size limit. 285 * 286 * Get the number of bytes which are used by the wide string @a str 287 * (excluding the NULL-terminator), but no more than @max_size bytes. 288 * 289 * @param str Wide string to consider. 290 * @param max_size Maximum number of bytes to measure. 291 * 292 * @return Number of bytes used by the wide string 293 * 294 */ 295 size_t wstr_nsize(const wchar_t *str, size_t max_size) 296 { 297 return (wstr_nlength(str, max_size) * sizeof(wchar_t)); 261 298 } 262 299 -
uspace/lib/c/generic/sysinfo.c
r43cd499 r14f8fd4 40 40 #include <bool.h> 41 41 42 /** Get sysinfo keys size 43 * 44 * @param path Sysinfo path. 45 * @param value Pointer to store the keys size. 46 * 47 * @return EOK if the keys were successfully read. 48 * 49 */ 50 static int sysinfo_get_keys_size(const char *path, size_t *size) 51 { 52 return (int) __SYSCALL3(SYS_SYSINFO_GET_KEYS_SIZE, (sysarg_t) path, 53 (sysarg_t) str_size(path), (sysarg_t) size); 54 } 55 56 /** Get sysinfo keys 57 * 58 * @param path Sysinfo path. 59 * @param value Pointer to store the keys size. 60 * 61 * @return Keys read from sysinfo or NULL if the 62 * sysinfo item has no subkeys. 63 * The returned non-NULL pointer should be 64 * freed by free(). 65 * 66 */ 67 char *sysinfo_get_keys(const char *path, size_t *size) 68 { 69 /* 70 * The size of the keys might change during time. 71 * Unfortunatelly we cannot allocate the buffer 72 * and transfer the keys as a single atomic operation. 73 */ 74 75 /* Get the keys size */ 76 int ret = sysinfo_get_keys_size(path, size); 77 if ((ret != EOK) || (size == 0)) { 78 /* 79 * Item with no subkeys. 80 */ 81 *size = 0; 82 return NULL; 83 } 84 85 char *data = malloc(*size); 86 if (data == NULL) { 87 *size = 0; 88 return NULL; 89 } 90 91 /* Get the data */ 92 size_t sz; 93 ret = __SYSCALL5(SYS_SYSINFO_GET_KEYS, (sysarg_t) path, 94 (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size, 95 (sysarg_t) &sz); 96 if (ret == EOK) { 97 *size = sz; 98 return data; 99 } 100 101 free(data); 102 *size = 0; 103 return NULL; 104 } 105 42 106 /** Get sysinfo item type 43 107 * … … 70 134 /** Get sysinfo binary data size 71 135 * 72 * @param path 73 * @param value Pointer to store the binary data size.136 * @param path Sysinfo path. 137 * @param size Pointer to store the binary data size. 74 138 * 75 139 * @return EOK if the value was successfully read and … … 85 149 /** Get sysinfo binary data 86 150 * 87 * @param path 88 * @param value Pointer to store the binary data size.151 * @param path Sysinfo path. 152 * @param size Pointer to store the binary data size. 89 153 * 90 154 * @return Binary data read from sysinfo or NULL if the … … 134 198 } 135 199 200 /** Get sysinfo property 201 * 202 * @param path Sysinfo path. 203 * @param name Property name. 204 * @param size Pointer to store the binary data size. 205 * 206 * @return Property value read from sysinfo or NULL if the 207 * sysinfo item value type is not binary data. 208 * The returned non-NULL pointer should be 209 * freed by free(). 210 * 211 */ 212 void *sysinfo_get_property(const char *path, const char *name, size_t *size) 213 { 214 size_t total_size; 215 void *data = sysinfo_get_data(path, &total_size); 216 if ((data == NULL) || (total_size == 0)) { 217 *size = 0; 218 return NULL; 219 } 220 221 size_t pos = 0; 222 while (pos < total_size) { 223 /* Process each property with sanity checks */ 224 size_t cur_size = str_nsize(data + pos, total_size - pos); 225 if (((char *) data)[pos + cur_size] != 0) 226 break; 227 228 bool found = (str_cmp(data + pos, name) == 0); 229 230 pos += cur_size + 1; 231 if (pos >= total_size) 232 break; 233 234 /* Process value size */ 235 size_t value_size; 236 memcpy(&value_size, data + pos, sizeof(value_size)); 237 238 pos += sizeof(value_size); 239 if ((pos >= total_size) || (pos + value_size > total_size)) 240 break; 241 242 if (found) { 243 void *value = malloc(value_size); 244 if (value == NULL) 245 break; 246 247 memcpy(value, data + pos, value_size); 248 free(data); 249 250 *size = value_size; 251 return value; 252 } 253 254 pos += value_size; 255 } 256 257 free(data); 258 259 *size = 0; 260 return NULL; 261 } 262 136 263 /** @} 137 264 */ -
uspace/lib/c/include/fibril.h
r43cd499 r14f8fd4 41 41 42 42 #define context_set_generic(c, _pc, stack, size, ptls) \ 43 (c)->pc = (sysarg_t) (_pc); \ 44 (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \ 45 (c)->tls = (sysarg_t) (ptls); 43 do { \ 44 (c)->pc = (sysarg_t) (_pc); \ 45 (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \ 46 (c)->tls = (sysarg_t) (ptls); \ 47 } while (0) 46 48 47 49 #define FIBRIL_SERIALIZED 1 -
uspace/lib/c/include/str.h
r43cd499 r14f8fd4 60 60 extern size_t str_size(const char *str); 61 61 extern size_t wstr_size(const wchar_t *str); 62 63 extern size_t str_nsize(const char *str, size_t max_size); 64 extern size_t wstr_nsize(const wchar_t *str, size_t max_size); 62 65 63 66 extern size_t str_lsize(const char *str, size_t max_len); -
uspace/lib/c/include/sysinfo.h
r43cd499 r14f8fd4 40 40 #include <abi/sysinfo.h> 41 41 42 extern char *sysinfo_get_keys(const char *, size_t *); 42 43 extern sysinfo_item_val_type_t sysinfo_get_val_type(const char *); 43 44 extern int sysinfo_get_value(const char *, sysarg_t *); 44 45 extern void *sysinfo_get_data(const char *, size_t *); 46 extern void *sysinfo_get_property(const char *, const char *, size_t *); 45 47 46 48 #endif -
uspace/srv/fs/exfat/exfat_bitmap.c
r43cd499 r14f8fd4 48 48 49 49 50 int bitmap_is_free(exfat_bs_t *bs, service_id_t service_id,50 int exfat_bitmap_is_free(exfat_bs_t *bs, service_id_t service_id, 51 51 exfat_cluster_t clst) 52 52 { … … 89 89 } 90 90 91 int bitmap_set_cluster(exfat_bs_t *bs, service_id_t service_id,91 int exfat_bitmap_set_cluster(exfat_bs_t *bs, service_id_t service_id, 92 92 exfat_cluster_t clst) 93 93 { … … 124 124 } 125 125 126 int bitmap_clear_cluster(exfat_bs_t *bs, service_id_t service_id,126 int exfat_bitmap_clear_cluster(exfat_bs_t *bs, service_id_t service_id, 127 127 exfat_cluster_t clst) 128 128 { … … 160 160 } 161 161 162 int bitmap_set_clusters(exfat_bs_t *bs, service_id_t service_id,162 int exfat_bitmap_set_clusters(exfat_bs_t *bs, service_id_t service_id, 163 163 exfat_cluster_t firstc, exfat_cluster_t count) 164 164 { … … 168 168 169 169 while (clst < firstc + count ) { 170 rc = bitmap_set_cluster(bs, service_id, clst);170 rc = exfat_bitmap_set_cluster(bs, service_id, clst); 171 171 if (rc != EOK) { 172 172 if (clst - firstc > 0) 173 (void) bitmap_clear_clusters(bs, service_id,173 (void) exfat_bitmap_clear_clusters(bs, service_id, 174 174 firstc, clst - firstc); 175 175 return rc; … … 180 180 } 181 181 182 int bitmap_clear_clusters(exfat_bs_t *bs, service_id_t service_id,182 int exfat_bitmap_clear_clusters(exfat_bs_t *bs, service_id_t service_id, 183 183 exfat_cluster_t firstc, exfat_cluster_t count) 184 184 { … … 188 188 189 189 while (clst < firstc + count) { 190 rc = bitmap_clear_cluster(bs, service_id, clst);190 rc = exfat_bitmap_clear_cluster(bs, service_id, clst); 191 191 if (rc != EOK) 192 192 return rc; … … 196 196 } 197 197 198 int bitmap_alloc_clusters(exfat_bs_t *bs, service_id_t service_id,198 int exfat_bitmap_alloc_clusters(exfat_bs_t *bs, service_id_t service_id, 199 199 exfat_cluster_t *firstc, exfat_cluster_t count) 200 200 { … … 204 204 while (startc < DATA_CNT(bs) + 2) { 205 205 endc = startc; 206 while ( bitmap_is_free(bs, service_id, endc) == EOK) {206 while (exfat_bitmap_is_free(bs, service_id, endc) == EOK) { 207 207 if ((endc - startc) + 1 == count) { 208 208 *firstc = startc; 209 return bitmap_set_clusters(bs, service_id, startc, count);209 return exfat_bitmap_set_clusters(bs, service_id, startc, count); 210 210 } else 211 211 endc++; … … 217 217 218 218 219 int bitmap_append_clusters(exfat_bs_t *bs, exfat_node_t *nodep,219 int exfat_bitmap_append_clusters(exfat_bs_t *bs, exfat_node_t *nodep, 220 220 exfat_cluster_t count) 221 221 { 222 222 if (nodep->firstc == 0) { 223 return bitmap_alloc_clusters(bs, nodep->idx->service_id,223 return exfat_bitmap_alloc_clusters(bs, nodep->idx->service_id, 224 224 &nodep->firstc, count); 225 225 } else { … … 228 228 229 229 clst = lastc + 1; 230 while ( bitmap_is_free(bs, nodep->idx->service_id, clst) == EOK) {230 while (exfat_bitmap_is_free(bs, nodep->idx->service_id, clst) == EOK) { 231 231 if (clst - lastc == count){ 232 return bitmap_set_clusters(bs, nodep->idx->service_id,232 return exfat_bitmap_set_clusters(bs, nodep->idx->service_id, 233 233 lastc + 1, count); 234 234 } else … … 240 240 241 241 242 int bitmap_free_clusters(exfat_bs_t *bs, exfat_node_t *nodep,242 int exfat_bitmap_free_clusters(exfat_bs_t *bs, exfat_node_t *nodep, 243 243 exfat_cluster_t count) 244 244 { … … 247 247 lastc -= count; 248 248 249 return bitmap_clear_clusters(bs, nodep->idx->service_id, lastc + 1, count);250 } 251 252 253 int bitmap_replicate_clusters(exfat_bs_t *bs, exfat_node_t *nodep)249 return exfat_bitmap_clear_clusters(bs, nodep->idx->service_id, lastc + 1, count); 250 } 251 252 253 int exfat_bitmap_replicate_clusters(exfat_bs_t *bs, exfat_node_t *nodep) 254 254 { 255 255 int rc; -
uspace/srv/fs/exfat/exfat_bitmap.h
r43cd499 r14f8fd4 42 42 struct exfat_bs; 43 43 44 extern int bitmap_alloc_clusters(struct exfat_bs *, service_id_t,44 extern int exfat_bitmap_alloc_clusters(struct exfat_bs *, service_id_t, 45 45 exfat_cluster_t *, exfat_cluster_t); 46 extern int bitmap_append_clusters(struct exfat_bs *, struct exfat_node *,46 extern int exfat_bitmap_append_clusters(struct exfat_bs *, struct exfat_node *, 47 47 exfat_cluster_t); 48 extern int bitmap_free_clusters(struct exfat_bs *, struct exfat_node *,48 extern int exfat_bitmap_free_clusters(struct exfat_bs *, struct exfat_node *, 49 49 exfat_cluster_t); 50 extern int bitmap_replicate_clusters(struct exfat_bs *, struct exfat_node *);50 extern int exfat_bitmap_replicate_clusters(struct exfat_bs *, struct exfat_node *); 51 51 52 extern int bitmap_is_free(struct exfat_bs *, service_id_t, exfat_cluster_t);53 extern int bitmap_set_cluster(struct exfat_bs *, service_id_t, exfat_cluster_t);54 extern int bitmap_clear_cluster(struct exfat_bs *, service_id_t,52 extern int exfat_bitmap_is_free(struct exfat_bs *, service_id_t, exfat_cluster_t); 53 extern int exfat_bitmap_set_cluster(struct exfat_bs *, service_id_t, exfat_cluster_t); 54 extern int exfat_bitmap_clear_cluster(struct exfat_bs *, service_id_t, 55 55 exfat_cluster_t); 56 56 57 extern int bitmap_set_clusters(struct exfat_bs *, service_id_t,57 extern int exfat_bitmap_set_clusters(struct exfat_bs *, service_id_t, 58 58 exfat_cluster_t, exfat_cluster_t); 59 extern int bitmap_clear_clusters(struct exfat_bs *, service_id_t,59 extern int exfat_bitmap_clear_clusters(struct exfat_bs *, service_id_t, 60 60 exfat_cluster_t, exfat_cluster_t); 61 61 -
uspace/srv/fs/exfat/exfat_dentry.c
r43cd499 r14f8fd4 130 130 } 131 131 132 size_t utf16_length(const uint16_t *wstr)132 size_t exfat_utf16_length(const uint16_t *wstr) 133 133 { 134 134 size_t len = 0; -
uspace/srv/fs/exfat/exfat_dentry.h
r43cd499 r14f8fd4 160 160 extern bool exfat_valid_name(const char *); 161 161 162 extern size_t utf16_length(const uint16_t *);162 extern size_t exfat_utf16_length(const uint16_t *); 163 163 164 164 -
uspace/srv/fs/exfat/exfat_directory.c
r43cd499 r14f8fd4 371 371 ds.stream.valid_data_size = 0; 372 372 ds.stream.data_size = 0; 373 ds.stream.name_size = utf16_length(wname);373 ds.stream.name_size = exfat_utf16_length(wname); 374 374 ds.stream.hash = host2uint16_t_le(exfat_name_hash(wname, uctable, 375 375 uctable_chars)); -
uspace/srv/fs/exfat/exfat_fat.c
r43cd499 r14f8fd4 314 314 clst++) { 315 315 /* Need to rewrite because of multiple exfat_bitmap_get calls */ 316 if ( bitmap_is_free(bs, service_id, clst) == EOK) {316 if (exfat_bitmap_is_free(bs, service_id, clst) == EOK) { 317 317 /* 318 318 * The cluster is free. Put it into our stack … … 325 325 goto exit_error; 326 326 found++; 327 rc = bitmap_set_cluster(bs, service_id, clst);327 rc = exfat_bitmap_set_cluster(bs, service_id, clst); 328 328 if (rc != EOK) 329 329 goto exit_error; … … 346 346 /* If something wrong - free the clusters */ 347 347 while (found--) { 348 (void) bitmap_clear_cluster(bs, service_id, lifo[found]);348 (void) exfat_bitmap_clear_cluster(bs, service_id, lifo[found]); 349 349 (void) exfat_set_cluster(bs, service_id, lifo[found], 0); 350 350 } … … 378 378 if (rc != EOK) 379 379 return rc; 380 rc = bitmap_clear_cluster(bs, service_id, firstc);380 rc = exfat_bitmap_clear_cluster(bs, service_id, firstc); 381 381 if (rc != EOK) 382 382 return rc; -
uspace/srv/fs/exfat/exfat_ops.c
r43cd499 r14f8fd4 405 405 406 406 if (!nodep->fragmented) { 407 rc = bitmap_append_clusters(bs, nodep, clusters);407 rc = exfat_bitmap_append_clusters(bs, nodep, clusters); 408 408 if (rc != ENOSPC) 409 409 return rc; … … 411 411 nodep->fragmented = true; 412 412 nodep->dirty = true; /* need to sync node */ 413 rc = bitmap_replicate_clusters(bs, nodep);413 rc = exfat_bitmap_replicate_clusters(bs, nodep); 414 414 if (rc != EOK) 415 415 return rc; … … 457 457 458 458 clsts = prev_clsts - new_clsts; 459 rc = bitmap_free_clusters(bs, nodep, clsts);459 rc = exfat_bitmap_free_clusters(bs, nodep, clsts); 460 460 if (rc != EOK) 461 461 return rc; … … 704 704 nodep->firstc); 705 705 else 706 rc = bitmap_free_clusters(bs, nodep,706 rc = exfat_bitmap_free_clusters(bs, nodep, 707 707 ROUND_UP(nodep->size, BPC(bs)) / BPC(bs)); 708 708 } … … 758 758 759 759 fibril_mutex_unlock(&parentp->idx->lock); 760 if (rc != EOK)761 return rc;762 763 760 fibril_mutex_lock(&childp->idx->lock); 764 765 761 766 762 childp->idx->pfc = parentp->firstc; … … 1463 1459 } 1464 1460 1465 (void) exfat_node_put(fn); 1461 int rc2 = exfat_node_put(fn); 1462 if (rc == EOK && rc2 != EOK) 1463 rc = rc2; 1464 1466 1465 return rc; 1467 1466 }
Note:
See TracChangeset
for help on using the changeset viewer.