Changeset 3f74275 in mainline
- Timestamp:
- 2017-08-20T16:45:01Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e68765e
- Parents:
- e7ac23d0
- Files:
-
- 12 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
kernel/Makefile
re7ac23d0 r3f74275 285 285 generic/src/ipc/irq.c \ 286 286 generic/src/ipc/event.c \ 287 generic/src/ kobject/kobject.c \287 generic/src/cap/cap.c \ 288 288 generic/src/security/perm.c \ 289 289 generic/src/sysinfo/sysinfo.c \ -
kernel/generic/include/cap/cap.h
re7ac23d0 r3f74275 33 33 */ 34 34 35 #ifndef KERN_ KOBJECT_H_36 #define KERN_ KOBJECT_H_35 #ifndef KERN_CAP_H_ 36 #define KERN_CAP_H_ 37 37 38 38 #include <typedefs.h> … … 40 40 #include <ddi/irq.h> 41 41 42 #define MAX_ KERNEL_OBJECTS 6442 #define MAX_CAPS 64 43 43 44 #define for_each_ kobject(task, ko, type) \45 for (int i = 0, l = 1; i < MAX_ KERNEL_OBJECTS && l; i++) \46 for ( kobject_t *(ko) = kobject_get((task), i, (type)); \47 ( ko) && !(l = 0); (ko) = NULL, l = 1)44 #define for_each_cap(task, cap, type) \ 45 for (int i = 0, l = 1; i < MAX_CAPS && l; i++) \ 46 for (cap_t *(cap) = cap_get((task), i, (type)); \ 47 (cap) && !(l = 0); (cap) = NULL, l = 1) 48 48 49 #define for_each_ kobject_current(ko, type) \50 for_each_ kobject(TASK, (ko), (type))49 #define for_each_cap_current(cap, type) \ 50 for_each_cap(TASK, (cap), (type)) 51 51 52 52 typedef enum { 53 KOBJECT_TYPE_INVALID,54 KOBJECT_TYPE_ALLOCATED,55 KOBJECT_TYPE_PHONE,56 KOBJECT_TYPE_IRQ57 } kobject_type_t;53 CAP_TYPE_INVALID, 54 CAP_TYPE_ALLOCATED, 55 CAP_TYPE_PHONE, 56 CAP_TYPE_IRQ 57 } cap_type_t; 58 58 59 typedef struct kobject{60 kobject_type_t type;61 bool (* can_reclaim)(struct kobject*);59 typedef struct cap { 60 cap_type_t type; 61 bool (* can_reclaim)(struct cap *); 62 62 63 /* The underlying kernel object. */ 63 64 union { 64 65 phone_t phone; 65 66 irq_t irq; 66 67 }; 67 } kobject_t;68 } cap_t; 68 69 69 70 struct task; 70 71 71 void kobject_task_alloc(struct task *);72 void kobject_task_free(struct task *);73 void kobject_task_init(struct task *);72 void caps_task_alloc(struct task *); 73 void caps_task_free(struct task *); 74 void caps_task_init(struct task *); 74 75 75 extern void kobject_initialize(kobject_t *);76 extern kobject_t *kobject_get(struct task *, int, kobject_type_t);77 extern kobject_t *kobject_get_current(int, kobject_type_t);78 extern int kobject_alloc(struct task *);79 extern void kobject_free(struct task *, int);76 extern void cap_initialize(cap_t *); 77 extern cap_t *cap_get(struct task *, int, cap_type_t); 78 extern cap_t *cap_get_current(int, cap_type_t); 79 extern int cap_alloc(struct task *); 80 extern void cap_free(struct task *, int); 80 81 81 extern int kobject_to_cap(struct task *, kobject_t *);82 extern int cap_get_handle(struct task *, cap_t *); 82 83 83 84 #endif -
kernel/generic/include/proc/task.h
re7ac23d0 r3f74275 65 65 66 66 struct thread; 67 struct kobject;67 struct cap; 68 68 69 69 /** Task structure. */ … … 97 97 perm_t perms; 98 98 99 /** Kernel objects */100 struct kobject *kobject;99 /** Capabilities */ 100 struct cap *caps; 101 101 102 102 /* IPC stuff */ -
kernel/generic/src/cap/cap.c
re7ac23d0 r3f74275 33 33 */ 34 34 35 #include < kobject/kobject.h>35 #include <cap/cap.h> 36 36 #include <proc/task.h> 37 37 #include <synch/spinlock.h> … … 39 39 #include <mm/slab.h> 40 40 41 void kobject_initialize(kobject_t *kobj)41 void cap_initialize(cap_t *cap) 42 42 { 43 kobj->type = KOBJECT_TYPE_INVALID;44 kobj->can_reclaim = NULL;43 cap->type = CAP_TYPE_INVALID; 44 cap->can_reclaim = NULL; 45 45 } 46 46 47 void kobject_task_alloc(task_t *task)47 void caps_task_alloc(task_t *task) 48 48 { 49 task-> kobject = malloc(sizeof(kobject_t) * MAX_KERNEL_OBJECTS, 0);49 task->caps = malloc(sizeof(cap_t) * MAX_CAPS, 0); 50 50 } 51 51 52 void kobject_task_init(task_t *task)52 void caps_task_init(task_t *task) 53 53 { 54 for (int cap = 0; cap < MAX_KERNEL_OBJECTS; cap++)55 kobject_initialize(&task->kobject[cap]);54 for (int i = 0; i < MAX_CAPS; i++) 55 cap_initialize(&task->caps[i]); 56 56 } 57 57 58 void kobject_task_free(task_t *task)58 void caps_task_free(task_t *task) 59 59 { 60 free(task-> kobject);60 free(task->caps); 61 61 } 62 62 63 kobject_t *kobject_get(task_t *task, int cap, kobject_type_t type)63 cap_t *cap_get(task_t *task, int handle, cap_type_t type) 64 64 { 65 if (( cap < 0) || (cap >= MAX_KERNEL_OBJECTS))65 if ((handle < 0) || (handle >= MAX_CAPS)) 66 66 return NULL; 67 if (task-> kobject[cap].type != type)67 if (task->caps[handle].type != type) 68 68 return NULL; 69 return &task-> kobject[cap];69 return &task->caps[handle]; 70 70 } 71 71 72 kobject_t *kobject_get_current(int cap, kobject_type_t type)72 cap_t *cap_get_current(int handle, cap_type_t type) 73 73 { 74 return kobject_get(TASK, cap, type);74 return cap_get(TASK, handle, type); 75 75 } 76 76 77 int kobject_alloc(task_t *task)77 int cap_alloc(task_t *task) 78 78 { 79 int cap;79 int handle; 80 80 81 81 irq_spinlock_lock(&task->lock, true); 82 for ( cap = 0; cap < MAX_KERNEL_OBJECTS; cap++) {83 kobject_t *kobj = &task->kobject[cap];84 if ( kobj->type > KOBJECT_TYPE_ALLOCATED) {85 if ( kobj->can_reclaim && kobj->can_reclaim(kobj))86 kobject_initialize(kobj);82 for (handle = 0; handle < MAX_CAPS; handle++) { 83 cap_t *cap = &task->caps[handle]; 84 if (cap->type > CAP_TYPE_ALLOCATED) { 85 if (cap->can_reclaim && cap->can_reclaim(cap)) 86 cap_initialize(cap); 87 87 } 88 if ( kobj->type == KOBJECT_TYPE_INVALID) {89 kobj->type = KOBJECT_TYPE_ALLOCATED;88 if (cap->type == CAP_TYPE_INVALID) { 89 cap->type = CAP_TYPE_ALLOCATED; 90 90 irq_spinlock_unlock(&task->lock, true); 91 return cap;91 return handle; 92 92 } 93 93 } … … 97 97 } 98 98 99 void kobject_free(task_t *task, int cap)99 void cap_free(task_t *task, int handle) 100 100 { 101 assert( cap>= 0);102 assert( cap < MAX_KERNEL_OBJECTS);103 assert(task-> kobject[cap].type != KOBJECT_TYPE_INVALID);101 assert(handle >= 0); 102 assert(handle < MAX_CAPS); 103 assert(task->caps[handle].type != CAP_TYPE_INVALID); 104 104 105 105 irq_spinlock_lock(&task->lock, true); 106 kobject_initialize(&task->kobject[cap]);106 cap_initialize(&task->caps[handle]); 107 107 irq_spinlock_unlock(&task->lock, true); 108 108 } 109 109 110 int kobject_to_cap(task_t *task, kobject_t *kobj)110 int cap_get_handle(task_t *task, cap_t *cap) 111 111 { 112 return kobj - task->kobject;112 return cap - task->caps; 113 113 } 114 114 -
kernel/generic/src/ipc/ipc.c
re7ac23d0 r3f74275 59 59 #include <arch/interrupt.h> 60 60 #include <ipc/irq.h> 61 #include < kobject/kobject.h>61 #include <cap/cap.h> 62 62 63 63 static void ipc_forget_call(call_t *); … … 743 743 */ 744 744 all_clean = true; 745 for_each_ kobject_current(kobj, KOBJECT_TYPE_PHONE) {746 phone_t *phone = & kobj->phone;745 for_each_cap_current(cap, CAP_TYPE_PHONE) { 746 phone_t *phone = &cap->phone; 747 747 748 748 mutex_lock(&phone->lock); … … 820 820 821 821 /* Disconnect all our phones ('ipc_phone_hangup') */ 822 for_each_ kobject_current(kobj, KOBJECT_TYPE_PHONE) {823 phone_t *phone = & kobj->phone;822 for_each_cap_current(cap, CAP_TYPE_PHONE) { 823 phone_t *phone = &cap->phone; 824 824 ipc_phone_hangup(phone); 825 825 } … … 911 911 printf("[phone cap] [calls] [state\n"); 912 912 913 for_each_ kobject(task, kobj, KOBJECT_TYPE_PHONE) {914 phone_t *phone = & kobj->phone;915 int cap = kobject_to_cap(task, kobj);916 913 for_each_cap(task, cap, CAP_TYPE_PHONE) { 914 phone_t *phone = &cap->phone; 915 int cap_handle = cap_get_handle(task, cap); 916 917 917 if (SYNCH_FAILED(mutex_trylock(&phone->lock))) { 918 printf("%-11d (mutex busy)\n", cap );918 printf("%-11d (mutex busy)\n", cap_handle); 919 919 continue; 920 920 } 921 921 922 922 if (phone->state != IPC_PHONE_FREE) { 923 printf("%-11d %7" PRIun " ", cap ,923 printf("%-11d %7" PRIun " ", cap_handle, 924 924 atomic_get(&phone->active_calls)); 925 925 -
kernel/generic/src/ipc/ipcrsc.c
re7ac23d0 r3f74275 133 133 #include <assert.h> 134 134 #include <abi/errno.h> 135 #include < kobject/kobject.h>135 #include <cap/cap.h> 136 136 137 137 /** Find call_t * in call table according to callid. … … 163 163 } 164 164 165 /** Get phone from the current task by capability .166 * 167 * @param cap Phone capability.168 * @param phone Place to store pointer to phone.165 /** Get phone from the current task by capability handle. 166 * 167 * @param handle Phone capability handle. 168 * @param phone Place to store pointer to phone. 169 169 * 170 170 * @return Address of the phone kernel object. … … 172 172 * 173 173 */ 174 phone_t *phone_get(task_t *task, int cap)175 { 176 kobject_t *kobj = kobject_get(task, cap, KOBJECT_TYPE_PHONE);177 if (! kobj)174 phone_t *phone_get(task_t *task, int handle) 175 { 176 cap_t *cap = cap_get(task, handle, CAP_TYPE_PHONE); 177 if (!cap) 178 178 return NULL; 179 179 180 return & kobj->phone;181 } 182 183 phone_t *phone_get_current(int cap)184 { 185 return phone_get(TASK, cap);186 } 187 188 static bool phone_can_reclaim( kobject_t *kobj)189 { 190 assert( kobj->type == KOBJECT_TYPE_PHONE);191 192 return ( kobj->phone.state == IPC_PHONE_HUNGUP) &&193 (atomic_get(& kobj->phone.active_calls) == 0);180 return &cap->phone; 181 } 182 183 phone_t *phone_get_current(int handle) 184 { 185 return phone_get(TASK, handle); 186 } 187 188 static bool phone_can_reclaim(cap_t *cap) 189 { 190 assert(cap->type == CAP_TYPE_PHONE); 191 192 return (cap->phone.state == IPC_PHONE_HUNGUP) && 193 (atomic_get(&cap->phone.active_calls) == 0); 194 194 } 195 195 … … 198 198 * @param task Task for which to allocate a new phone. 199 199 * 200 * @return New phone capability .200 * @return New phone capability handle. 201 201 * @return Negative error code if a new capability cannot be allocated. 202 202 */ 203 203 int phone_alloc(task_t *task) 204 204 { 205 int cap = kobject_alloc(task);206 if ( cap>= 0) {205 int handle = cap_alloc(task); 206 if (handle >= 0) { 207 207 irq_spinlock_lock(&task->lock, true); 208 kobject_t *kobj = &task->kobject[cap];209 ipc_phone_init(& kobj->phone, task);210 kobj->type = KOBJECT_TYPE_PHONE;211 kobj->can_reclaim = phone_can_reclaim;212 kobj->phone.state = IPC_PHONE_CONNECTING;208 cap_t *cap = &task->caps[handle]; 209 ipc_phone_init(&cap->phone, task); 210 cap->type = CAP_TYPE_PHONE; 211 cap->can_reclaim = phone_can_reclaim; 212 cap->phone.state = IPC_PHONE_CONNECTING; 213 213 irq_spinlock_unlock(&task->lock, true); 214 214 } 215 215 216 return cap;216 return handle; 217 217 } 218 218 … … 221 221 * All already sent messages will be correctly processed. 222 222 * 223 * @param phoneid Phonehandle of the phone to be freed.224 * 225 */ 226 void phone_dealloc(int cap)227 { 228 phone_t *phone = phone_get_current( cap);223 * @param handle Phone capability handle of the phone to be freed. 224 * 225 */ 226 void phone_dealloc(int handle) 227 { 228 phone_t *phone = phone_get_current(handle); 229 229 230 230 assert(phone); 231 231 assert(phone->state == IPC_PHONE_CONNECTING); 232 232 233 kobject_free(TASK, cap);233 cap_free(TASK, handle); 234 234 } 235 235 236 236 /** Connect phone to a given answerbox. 237 237 * 238 * @param cap Phone capabilityto be connected.239 * @param box Answerbox to which to connect the phone capability.240 * @return True if the phone was connected, false otherwise.238 * @param handle Capability handle of the phone to be connected. 239 * @param box Answerbox to which to connect the phone. 240 * @return True if the phone was connected, false otherwise. 241 241 * 242 242 * The procedure _enforces_ that the user first marks the phone busy (e.g. via … … 245 245 * 246 246 */ 247 bool phone_connect(int cap, answerbox_t *box)248 { 249 phone_t *phone = phone_get_current( cap);247 bool phone_connect(int handle, answerbox_t *box) 248 { 249 phone_t *phone = phone_get_current(handle); 250 250 251 251 assert(phone); -
kernel/generic/src/ipc/irq.c
re7ac23d0 r3f74275 84 84 #include <print.h> 85 85 #include <macros.h> 86 #include < kobject/kobject.h>86 #include <cap/cap.h> 87 87 88 88 static void ranges_unmap(irq_pio_range_t *ranges, size_t rangecount) … … 298 298 * @param ucode Uspace pointer to top-half pseudocode. 299 299 * 300 * @return IRQ capability .300 * @return IRQ capability handle. 301 301 * @return Negative error code. 302 302 * … … 324 324 * Allocate and populate the IRQ kernel object. 325 325 */ 326 int cap = kobject_alloc(TASK);327 if ( cap< 0)328 return cap;329 kobject_t *kobj = kobject_get_current(cap, KOBJECT_TYPE_ALLOCATED);330 assert( kobj);331 kobj->type = KOBJECT_TYPE_IRQ;332 333 irq_t *irq = & kobj->irq;326 int handle = cap_alloc(TASK); 327 if (handle < 0) 328 return handle; 329 cap_t *cap = cap_get_current(handle, CAP_TYPE_ALLOCATED); 330 assert(cap); 331 cap->type = CAP_TYPE_IRQ; 332 333 irq_t *irq = &cap->irq; 334 334 irq_initialize(irq); 335 335 irq->inr = inr; … … 357 357 irq_spinlock_unlock(&irq_uspace_hash_table_lock, true); 358 358 359 return cap;359 return handle; 360 360 } 361 361 362 362 /** Unsubscribe task from IRQ notification. 363 363 * 364 * @param box 365 * @param irq_cap IRQ capability.364 * @param box Answerbox associated with the notification. 365 * @param handle IRQ capability handle. 366 366 * 367 367 * @return EOK on success or a negative error code. 368 368 * 369 369 */ 370 int ipc_irq_unsubscribe(answerbox_t *box, int irq_cap)371 { 372 kobject_t *kobj = kobject_get_current(irq_cap, KOBJECT_TYPE_IRQ);373 if (! kobj)370 int ipc_irq_unsubscribe(answerbox_t *box, int handle) 371 { 372 cap_t *cap = cap_get_current(handle, CAP_TYPE_IRQ); 373 if (!cap) 374 374 return ENOENT; 375 irq_t *irq = & kobj->irq;375 irq_t *irq = &cap->irq; 376 376 377 377 irq_spinlock_lock(&irq_uspace_hash_table_lock, true); … … 394 394 code_free(irq->notif_cfg.code); 395 395 396 /* Free up the IRQ kernel object. */397 kobject_free(TASK, irq_cap);396 /* Free up the IRQ capability and the underlying kernel object. */ 397 cap_free(TASK, handle); 398 398 399 399 return EOK; -
kernel/generic/src/proc/task.c
re7ac23d0 r3f74275 50 50 #include <adt/btree.h> 51 51 #include <adt/list.h> 52 #include < kobject/kobject.h>52 #include <cap/cap.h> 53 53 #include <ipc/ipc.h> 54 54 #include <ipc/ipcrsc.h> … … 169 169 list_initialize(&task->threads); 170 170 171 kobject_task_alloc(task);171 caps_task_alloc(task); 172 172 173 173 ipc_answerbox_init(&task->answerbox, task); … … 190 190 task_t *task = (task_t *) obj; 191 191 192 kobject_task_free(task);192 caps_task_free(task); 193 193 return 0; 194 194 } … … 215 215 task->kcycles = 0; 216 216 217 kobject_task_init(task);217 caps_task_init(task); 218 218 219 219 task->ipc_info.call_sent = 0; … … 624 624 625 625 if (*additional) { 626 for_each_ kobject(task, ko, KOBJECT_TYPE_PHONE) {627 phone_t *phone = & ko->phone;626 for_each_cap(task, cap, CAP_TYPE_PHONE) { 627 phone_t *phone = &cap->phone; 628 628 if (phone->callee) 629 printf(" %d:%p", kobject_to_cap(task, ko),629 printf(" %d:%p", cap_get_handle(task, cap), 630 630 phone->callee); 631 631 } -
uspace/drv/char/ns8250/ns8250.c
re7ac23d0 r3f74275 160 160 /** The irq assigned to this device. */ 161 161 int irq; 162 /** IRQ capability */162 /** IRQ capability handle */ 163 163 int irq_cap; 164 164 /** The base i/o address of the devices registers. */ -
uspace/drv/nic/e1k/e1k.c
re7ac23d0 r3f74275 1253 1253 * @param nic Driver data 1254 1254 * 1255 * @return IRQ capability if the handler was registered1255 * @return IRQ capability handle if the handler was registered 1256 1256 * @return Negative error code otherwise 1257 1257 * -
uspace/drv/nic/rtl8139/driver.c
re7ac23d0 r3f74275 881 881 * @param nic_data The driver data 882 882 * 883 * @return IRQ capability if the handler was registered.883 * @return IRQ capability handle if the handler was registered. 884 884 * @return Negative error code otherwise. 885 885 */ -
uspace/lib/c/generic/async.c
re7ac23d0 r3f74275 1026 1026 * @param ucode Top-half pseudocode handler. 1027 1027 * 1028 * @return IRQ capability on success.1028 * @return IRQ capability handle on success. 1029 1029 * @return Negative error code. 1030 1030 * … … 1056 1056 /** Unsubscribe from IRQ notification. 1057 1057 * 1058 * @param cap IRQ capability .1058 * @param cap IRQ capability handle. 1059 1059 * 1060 1060 * @return Zero on success or a negative error code. -
uspace/lib/c/generic/irq.c
re7ac23d0 r3f74275 58 58 * @param ucode Top-half pseudocode handler. 59 59 * 60 * @return IRQ capability returned by the kernel.60 * @return IRQ capability handle returned by the kernel. 61 61 * @return Error code returned by the kernel. 62 62 * … … 72 72 /** Unsubscribe from IRQ notification. 73 73 * 74 * @param cap IRQ capability .74 * @param cap IRQ capability handle. 75 75 * 76 76 * @return Value returned by the kernel. -
uspace/lib/usbhost/src/ddf_helpers.c
re7ac23d0 r3f74275 748 748 * @param[in] gen_irq_code IRQ code generator. 749 749 * 750 * @return IRQ kernel object capabilityon success.750 * @return IRQ capability handle on success. 751 751 * @return Negative error code. 752 752 */
Note:
See TracChangeset
for help on using the changeset viewer.