Changeset 3f74275 in mainline for kernel/generic/src/ipc


Ignore:
Timestamp:
2017-08-20T16:45:01Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e68765e
Parents:
e7ac23d0
Message:

Fix terminology around capabilities, capability handles and kernel objects

Location:
kernel/generic/src/ipc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/ipc.c

    re7ac23d0 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

    re7ac23d0 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

    re7ac23d0 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;
Note: See TracChangeset for help on using the changeset viewer.