Changeset 26beeda in mainline


Ignore:
Timestamp:
2018-01-20T19:17:35Z (6 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4397984
Parents:
45e49e6
Message:

xhci: simplify context macros and make them check types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/hw_struct/context.h

    r45e49e6 r26beeda  
    179179#define XHCI_CTX_SIZE_SMALL 32
    180180#define XHCI_ONE_CTX_SIZE(hc) (XHCI_CTX_SIZE_SMALL << hc->csz)
     181#define XHCI_GET_CTX_FIELD(type, ctx, hc, ci) (xhci_##type##_ctx_to_charptr(ctx) + (ci) * XHCI_ONE_CTX_SIZE(hc))
     182
     183/**
     184 * Device context: section 6.2.1
     185 */
    181186#define XHCI_DEVICE_CTX_SIZE(hc) ((1 + XHCI_EP_COUNT) * XHCI_ONE_CTX_SIZE(hc))
    182 
    183 /**
    184  * Device context: section 6.2.1
    185  */
    186 #define XHCI_GET_DC_FIELD(dev_ctx, hc, dci) ((char*)dev_ctx + (dci) * XHCI_ONE_CTX_SIZE(hc))
    187 #define XHCI_GET_EP_CTX(dev_ctx, hc, dci) ((xhci_ep_ctx_t *)   XHCI_GET_DC_FIELD(dev_ctx, hc, dci))
    188 #define XHCI_GET_SLOT_CTX(dev_ctx, hc)    ((xhci_slot_ctx_t *) XHCI_GET_DC_FIELD(dev_ctx, hc, 0))
     187#define XHCI_GET_EP_CTX(dev_ctx, hc, dci) ((xhci_ep_ctx_t *)   XHCI_GET_CTX_FIELD(device, (dev_ctx), (hc), (dci)))
     188#define XHCI_GET_SLOT_CTX(dev_ctx, hc)    ((xhci_slot_ctx_t *) XHCI_GET_CTX_FIELD(device, (dev_ctx), (hc), 0))
    189189
    190190/**
     
    196196typedef struct xhci_device_ctx {
    197197} xhci_device_ctx_t;
     198
     199/**
     200 * Force type checking.
     201 */
     202static inline char *xhci_device_ctx_to_charptr(const xhci_device_ctx_t *ctx)
     203{
     204        return (char *) ctx;
     205}
    198206
    199207/**
     
    243251 * Input context: section 6.2.5
    244252 */
    245 
    246 #define XHCI_CTRL_CTX_OFFSET 0
    247 #define XHCI_DEVICE_CTX_OFFSET 1
    248 #define XHCI_INPUT_CTX_SIZE(hc) (XHCI_DEVICE_CTX_OFFSET * XHCI_ONE_CTX_SIZE(hc) + XHCI_DEVICE_CTX_SIZE(hc))
    249 #define XHCI_GET_CTRL_CTX(ictx, hc) (xhci_input_ctrl_ctx_t*)((char*)ictx + XHCI_CTRL_CTX_OFFSET * XHCI_ONE_CTX_SIZE(hc))
    250 #define XHCI_GET_DEVICE_CTX(ictx, hc) (xhci_device_ctx_t *)((char*)ictx + XHCI_DEVICE_CTX_OFFSET * XHCI_ONE_CTX_SIZE(hc))
     253#define XHCI_INPUT_CTX_SIZE(hc) (XHCI_ONE_CTX_SIZE(hc) + XHCI_DEVICE_CTX_SIZE(hc))
     254#define XHCI_GET_CTRL_CTX(ictx, hc)  ((xhci_input_ctrl_ctx_t *) XHCI_GET_CTX_FIELD(input, (ictx), (hc), 0))
     255#define XHCI_GET_DEVICE_CTX(dev_ctx, hc) ((xhci_device_ctx_t *) XHCI_GET_CTX_FIELD(input, (ictx), (hc), 1))
    251256
    252257typedef struct xhci_input_ctx {
    253258} xhci_input_ctx_t;
     259
     260/**
     261 * Force type checking.
     262 */
     263static inline char *xhci_input_ctx_to_charptr(const xhci_input_ctx_t *ctx)
     264{
     265        return (char *) ctx;
     266}
    254267
    255268/**
Note: See TracChangeset for help on using the changeset viewer.