Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 3f74275 in mainline


Ignore:
Timestamp:
2017-08-20T16:45:01Z (3 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
Children:
e68765e
Parents:
e7ac23d
Message:

Fix terminology around capabilities, capability handles and kernel objects

Files:
12 edited
2 moved

Legend:

Unmodified
Added
Removed
  • kernel/Makefile

    re7ac23d r3f74275  
    285285        generic/src/ipc/irq.c \
    286286        generic/src/ipc/event.c \
    287         generic/src/kobject/kobject.c \
     287        generic/src/cap/cap.c \
    288288        generic/src/security/perm.c \
    289289        generic/src/sysinfo/sysinfo.c \
  • kernel/generic/include/cap/cap.h

    re7ac23d r3f74275  
    3333 */
    3434
    35 #ifndef KERN_KOBJECT_H_
    36 #define KERN_KOBJECT_H_
     35#ifndef KERN_CAP_H_
     36#define KERN_CAP_H_
    3737
    3838#include <typedefs.h>
     
    4040#include <ddi/irq.h>
    4141
    42 #define MAX_KERNEL_OBJECTS  64
     42#define MAX_CAPS  64
    4343
    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)
    4848
    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))
    5151
    5252typedef enum {
    53         KOBJECT_TYPE_INVALID,
    54         KOBJECT_TYPE_ALLOCATED,
    55         KOBJECT_TYPE_PHONE,
    56         KOBJECT_TYPE_IRQ
    57 } kobject_type_t;
     53        CAP_TYPE_INVALID,
     54        CAP_TYPE_ALLOCATED,
     55        CAP_TYPE_PHONE,
     56        CAP_TYPE_IRQ
     57} cap_type_t;
    5858
    59 typedef struct kobject {
    60         kobject_type_t type;
    61         bool (* can_reclaim)(struct kobject *);
     59typedef struct cap {
     60        cap_type_t type;
     61        bool (* can_reclaim)(struct cap *);
    6262
     63        /* The underlying kernel object. */
    6364        union {
    6465                phone_t phone;
    6566                irq_t irq;
    6667        };
    67 } kobject_t;
     68} cap_t;
    6869
    6970struct task;
    7071
    71 void kobject_task_alloc(struct task *);
    72 void kobject_task_free(struct task *);
    73 void kobject_task_init(struct task *);
     72void caps_task_alloc(struct task *);
     73void caps_task_free(struct task *);
     74void caps_task_init(struct task *);
    7475
    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);
     76extern void cap_initialize(cap_t *);
     77extern cap_t *cap_get(struct task *, int, cap_type_t);
     78extern cap_t *cap_get_current(int, cap_type_t);
     79extern int cap_alloc(struct task *);
     80extern void cap_free(struct task *, int);
    8081
    81 extern int kobject_to_cap(struct task *, kobject_t *);
     82extern int cap_get_handle(struct task *, cap_t *);
    8283
    8384#endif
  • kernel/generic/include/proc/task.h

    re7ac23d r3f74275  
    6565
    6666struct thread;
    67 struct kobject;
     67struct cap;
    6868
    6969/** Task structure. */
     
    9797        perm_t perms;
    9898
    99         /** Kernel objects */
    100         struct kobject *kobject;
     99        /** Capabilities */
     100        struct cap *caps;
    101101       
    102102        /* IPC stuff */
  • kernel/generic/src/cap/cap.c

    re7ac23d r3f74275  
    3333 */
    3434
    35 #include <kobject/kobject.h>
     35#include <cap/cap.h>
    3636#include <proc/task.h>
    3737#include <synch/spinlock.h>
     
    3939#include <mm/slab.h>
    4040
    41 void kobject_initialize(kobject_t *kobj)
     41void cap_initialize(cap_t *cap)
    4242{
    43         kobj->type = KOBJECT_TYPE_INVALID;
    44         kobj->can_reclaim = NULL;
     43        cap->type = CAP_TYPE_INVALID;
     44        cap->can_reclaim = NULL;
    4545}
    4646
    47 void kobject_task_alloc(task_t *task)
     47void caps_task_alloc(task_t *task)
    4848{
    49         task->kobject = malloc(sizeof(kobject_t) * MAX_KERNEL_OBJECTS, 0);
     49        task->caps = malloc(sizeof(cap_t) * MAX_CAPS, 0);
    5050}
    5151
    52 void kobject_task_init(task_t *task)
     52void caps_task_init(task_t *task)
    5353{
    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]);
    5656}
    5757
    58 void kobject_task_free(task_t *task)
     58void caps_task_free(task_t *task)
    5959{
    60         free(task->kobject);
     60        free(task->caps);
    6161}
    6262
    63 kobject_t *kobject_get(task_t *task, int cap, kobject_type_t type)
     63cap_t *cap_get(task_t *task, int handle, cap_type_t type)
    6464{
    65         if ((cap < 0) || (cap >= MAX_KERNEL_OBJECTS))
     65        if ((handle < 0) || (handle >= MAX_CAPS))
    6666                return NULL;
    67         if (task->kobject[cap].type != type)
     67        if (task->caps[handle].type != type)
    6868                return NULL;
    69         return &task->kobject[cap];
     69        return &task->caps[handle];
    7070}
    7171
    72 kobject_t *kobject_get_current(int cap, kobject_type_t type)
     72cap_t *cap_get_current(int handle, cap_type_t type)
    7373{
    74         return kobject_get(TASK, cap, type);
     74        return cap_get(TASK, handle, type);
    7575}
    7676
    77 int kobject_alloc(task_t *task)
     77int cap_alloc(task_t *task)
    7878{
    79         int cap;
     79        int handle;
    8080
    8181        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);
    8787                }
    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;
    9090                        irq_spinlock_unlock(&task->lock, true);
    91                         return cap;
     91                        return handle;
    9292                }
    9393        }
     
    9797}
    9898
    99 void kobject_free(task_t *task, int cap)
     99void cap_free(task_t *task, int handle)
    100100{
    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);
    104104
    105105        irq_spinlock_lock(&task->lock, true);
    106         kobject_initialize(&task->kobject[cap]);
     106        cap_initialize(&task->caps[handle]);
    107107        irq_spinlock_unlock(&task->lock, true);
    108108}
    109109
    110 int kobject_to_cap(task_t *task, kobject_t *kobj)
     110int cap_get_handle(task_t *task, cap_t *cap)
    111111{
    112         return kobj - task->kobject;
     112        return cap - task->caps;
    113113}
    114114
  • kernel/generic/src/ipc/ipc.c

    re7ac23d r3f74275  
    5959#include <arch/interrupt.h>
    6060#include <ipc/irq.h>
    61 #include <kobject/kobject.h>
     61#include <cap/cap.h>
    6262
    6363static void ipc_forget_call(call_t *);
     
    743743         */
    744744        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;
    747747
    748748                mutex_lock(&phone->lock);
     
    820820
    821821        /* 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;
    824824                ipc_phone_hangup(phone);
    825825        }
     
    911911        printf("[phone cap] [calls] [state\n");
    912912       
    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       
    917917                if (SYNCH_FAILED(mutex_trylock(&phone->lock))) {
    918                         printf("%-11d (mutex busy)\n", cap);
     918                        printf("%-11d (mutex busy)\n", cap_handle);
    919919                        continue;
    920920                }
    921921               
    922922                if (phone->state != IPC_PHONE_FREE) {
    923                         printf("%-11d %7" PRIun " ", cap,
     923                        printf("%-11d %7" PRIun " ", cap_handle,
    924924                            atomic_get(&phone->active_calls));
    925925                       
  • kernel/generic/src/ipc/ipcrsc.c

    re7ac23d r3f74275  
    133133#include <assert.h>
    134134#include <abi/errno.h>
    135 #include <kobject/kobject.h>
     135#include <cap/cap.h>
    136136
    137137/** Find call_t * in call table according to callid.
     
    163163}
    164164
    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.
    169169 *
    170170 * @return  Address of the phone kernel object.
     
    172172 *
    173173 */
    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)
     174phone_t *phone_get(task_t *task, int handle)
     175{
     176        cap_t *cap = cap_get(task, handle, CAP_TYPE_PHONE);
     177        if (!cap)
    178178                return NULL;
    179179       
    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
     183phone_t *phone_get_current(int handle)
     184{
     185        return phone_get(TASK, handle);
     186}
     187
     188static 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);
    194194}
    195195
     
    198198 * @param task  Task for which to allocate a new phone.
    199199 *
    200  * @return  New phone capability.
     200 * @return  New phone capability handle.
    201201 * @return  Negative error code if a new capability cannot be allocated.
    202202 */
    203203int phone_alloc(task_t *task)
    204204{
    205         int cap = kobject_alloc(task);
    206         if (cap >= 0) {
     205        int handle = cap_alloc(task);
     206        if (handle >= 0) {
    207207                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;
    213213                irq_spinlock_unlock(&task->lock, true);
    214214        }
    215215       
    216         return cap;
     216        return handle;
    217217}
    218218
     
    221221 * All already sent messages will be correctly processed.
    222222 *
    223  * @param phoneid Phone handle 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 */
     226void phone_dealloc(int handle)
     227{
     228        phone_t *phone = phone_get_current(handle);
    229229       
    230230        assert(phone);
    231231        assert(phone->state == IPC_PHONE_CONNECTING);
    232232
    233         kobject_free(TASK, cap);
     233        cap_free(TASK, handle);
    234234}
    235235
    236236/** Connect phone to a given answerbox.
    237237 *
    238  * @param cap  Phone capability to 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.
    241241 *
    242242 * The procedure _enforces_ that the user first marks the phone busy (e.g. via
     
    245245 *
    246246 */
    247 bool phone_connect(int cap, answerbox_t *box)
    248 {
    249         phone_t *phone = phone_get_current(cap);
     247bool phone_connect(int handle, answerbox_t *box)
     248{
     249        phone_t *phone = phone_get_current(handle);
    250250       
    251251        assert(phone);
  • kernel/generic/src/ipc/irq.c

    re7ac23d r3f74275  
    8484#include <print.h>
    8585#include <macros.h>
    86 #include <kobject/kobject.h>
     86#include <cap/cap.h>
    8787
    8888static void ranges_unmap(irq_pio_range_t *ranges, size_t rangecount)
     
    298298 * @param ucode   Uspace pointer to top-half pseudocode.
    299299 *
    300  * @return  IRQ capability.
     300 * @return  IRQ capability handle.
    301301 * @return  Negative error code.
    302302 *
     
    324324         * Allocate and populate the IRQ kernel object.
    325325         */
    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;
    334334        irq_initialize(irq);
    335335        irq->inr = inr;
     
    357357        irq_spinlock_unlock(&irq_uspace_hash_table_lock, true);
    358358       
    359         return cap;
     359        return handle;
    360360}
    361361
    362362/** Unsubscribe task from IRQ notification.
    363363 *
    364  * @param box      Answerbox associated with the notification.
    365  * @param irq_cap  IRQ capability.
     364 * @param box     Answerbox associated with the notification.
     365 * @param handle  IRQ capability handle.
    366366 *
    367367 * @return EOK on success or a negative error code.
    368368 *
    369369 */
    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)
     370int ipc_irq_unsubscribe(answerbox_t *box, int handle)
     371{
     372        cap_t *cap = cap_get_current(handle, CAP_TYPE_IRQ);
     373        if (!cap)
    374374                return ENOENT;
    375         irq_t *irq = &kobj->irq;
     375        irq_t *irq = &cap->irq;
    376376
    377377        irq_spinlock_lock(&irq_uspace_hash_table_lock, true);
     
    394394        code_free(irq->notif_cfg.code);
    395395       
    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);
    398398       
    399399        return EOK;
  • kernel/generic/src/proc/task.c

    re7ac23d r3f74275  
    5050#include <adt/btree.h>
    5151#include <adt/list.h>
    52 #include <kobject/kobject.h>
     52#include <cap/cap.h>
    5353#include <ipc/ipc.h>
    5454#include <ipc/ipcrsc.h>
     
    169169        list_initialize(&task->threads);
    170170       
    171         kobject_task_alloc(task);
     171        caps_task_alloc(task);
    172172       
    173173        ipc_answerbox_init(&task->answerbox, task);
     
    190190        task_t *task = (task_t *) obj;
    191191       
    192         kobject_task_free(task);
     192        caps_task_free(task);
    193193        return 0;
    194194}
     
    215215        task->kcycles = 0;
    216216
    217         kobject_task_init(task);
     217        caps_task_init(task);
    218218
    219219        task->ipc_info.call_sent = 0;
     
    624624       
    625625        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;
    628628                        if (phone->callee)
    629                                 printf(" %d:%p", kobject_to_cap(task, ko),
     629                                printf(" %d:%p", cap_get_handle(task, cap),
    630630                                    phone->callee);
    631631                }
  • uspace/drv/char/ns8250/ns8250.c

    re7ac23d r3f74275  
    160160        /** The irq assigned to this device. */
    161161        int irq;
    162         /** IRQ capability */
     162        /** IRQ capability handle */
    163163        int irq_cap;
    164164        /** The base i/o address of the devices registers. */
  • uspace/drv/nic/e1k/e1k.c

    re7ac23d r3f74275  
    12531253 * @param nic Driver data
    12541254 *
    1255  * @return IRQ capability if the handler was registered
     1255 * @return IRQ capability handle if the handler was registered
    12561256 * @return Negative error code otherwise
    12571257 *
  • uspace/drv/nic/rtl8139/driver.c

    re7ac23d r3f74275  
    881881 *  @param nic_data  The driver data
    882882 *
    883  *  @return IRQ capability if the handler was registered.
     883 *  @return IRQ capability handle if the handler was registered.
    884884 *  @return Negative error code otherwise.
    885885 */
  • uspace/lib/c/generic/async.c

    re7ac23d r3f74275  
    10261026 * @param ucode   Top-half pseudocode handler.
    10271027 *
    1028  * @return IRQ capability on success.
     1028 * @return IRQ capability handle on success.
    10291029 * @return Negative error code.
    10301030 *
     
    10561056/** Unsubscribe from IRQ notification.
    10571057 *
    1058  * @param cap     IRQ capability.
     1058 * @param cap     IRQ capability handle.
    10591059 *
    10601060 * @return Zero on success or a negative error code.
  • uspace/lib/c/generic/irq.c

    re7ac23d r3f74275  
    5858 * @param ucode  Top-half pseudocode handler.
    5959 *
    60  * @return IRQ capability returned by the kernel.
     60 * @return IRQ capability handle returned by the kernel.
    6161 * @return Error code returned by the kernel.
    6262 *
     
    7272/** Unsubscribe from IRQ notification.
    7373 *
    74  * @param cap   IRQ capability.
     74 * @param cap   IRQ capability handle.
    7575 *
    7676 * @return Value returned by the kernel.
  • uspace/lib/usbhost/src/ddf_helpers.c

    re7ac23d r3f74275  
    748748 * @param[in] gen_irq_code IRQ code generator.
    749749 *
    750  * @return IRQ kernel object capability on success.
     750 * @return IRQ capability handle on success.
    751751 * @return Negative error code.
    752752 */
Note: See TracChangeset for help on using the changeset viewer.