⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ieee1394_transactions.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
                return -EAGAIN;        }        HPSB_PANIC("reached unreachable code 2 in " __FUNCTION__);}int hpsb_read_trylocal(struct hpsb_host *host, nodeid_t node, u64 addr,                        quadlet_t *buffer, size_t length){        if (host->node_id != node) return -1;        return highlevel_read(host, node, buffer, addr, length);}struct hpsb_packet *hpsb_make_readqpacket(struct hpsb_host *host, nodeid_t node,                                          u64 addr){        struct hpsb_packet *p;        p = alloc_hpsb_packet(0);        if (!p) return NULL;        p->host = host;        p->tlabel = get_tlabel(host, node, 1);        p->node_id = node;        fill_async_readquad(p, addr);        return p;}struct hpsb_packet *hpsb_make_readbpacket(struct hpsb_host *host, nodeid_t node,                                          u64 addr, size_t length){        struct hpsb_packet *p;        p = alloc_hpsb_packet(length + (length % 4 ? 4 - (length % 4) : 0));        if (!p) return NULL;        p->host = host;        p->tlabel = get_tlabel(host, node, 1);        p->node_id = node;        fill_async_readblock(p, addr, length);        return p;}struct hpsb_packet *hpsb_make_writeqpacket(struct hpsb_host *host,                                           nodeid_t node, u64 addr,                                           quadlet_t data){        struct hpsb_packet *p;        p = alloc_hpsb_packet(0);        if (!p) return NULL;        p->host = host;        p->tlabel = get_tlabel(host, node, 1);        p->node_id = node;        fill_async_writequad(p, addr, data);        return p;}struct hpsb_packet *hpsb_make_writebpacket(struct hpsb_host *host,                                           nodeid_t node, u64 addr,                                           size_t length){        struct hpsb_packet *p;        p = alloc_hpsb_packet(length + (length % 4 ? 4 - (length % 4) : 0));        if (!p) return NULL;        if (length % 4) {                p->data[length / 4] = 0;        }        p->host = host;        p->tlabel = get_tlabel(host, node, 1);        p->node_id = node;        fill_async_writeblock(p, addr, length);        return p;}struct hpsb_packet *hpsb_make_lockpacket(struct hpsb_host *host, nodeid_t node,                                         u64 addr, int extcode){        struct hpsb_packet *p;        p = alloc_hpsb_packet(8);        if (!p) return NULL;        p->host = host;        p->tlabel = get_tlabel(host, node, 1);        p->node_id = node;        switch (extcode) {        case EXTCODE_FETCH_ADD:        case EXTCODE_LITTLE_ADD:                fill_async_lock(p, addr, extcode, 4);                break;        default:                fill_async_lock(p, addr, extcode, 8);                break;        }        return p;}/* * FIXME - these functions should probably read from / write to user space to * avoid in kernel buffers for user space callers */int hpsb_read(struct hpsb_host *host, nodeid_t node, u64 addr,              quadlet_t *buffer, size_t length){        struct hpsb_packet *packet;        int retval = 0;                if (length == 0) {                return -EINVAL;        }        if (host->node_id == node) {                switch(highlevel_read(host, node, buffer, addr, length)) {                case RCODE_COMPLETE:                        return 0;                case RCODE_TYPE_ERROR:                        return -EACCES;                case RCODE_ADDRESS_ERROR:                default:                        return -EINVAL;                }        }        if (length == 4) {                packet = hpsb_make_readqpacket(host, node, addr);        } else {                packet = hpsb_make_readbpacket(host, node, addr, length);        }        if (!packet) {                return -ENOMEM;        }        hpsb_send_packet(packet);        down(&packet->state_change);        down(&packet->state_change);        retval = hpsb_packet_success(packet);        if (retval == 0) {                if (length == 4) {                        *buffer = packet->header[3];                } else {                        memcpy(buffer, packet->data, length);                }        }        free_tlabel(host, node, packet->tlabel);        free_hpsb_packet(packet);        return retval;}int hpsb_write(struct hpsb_host *host, nodeid_t node, u64 addr,               quadlet_t *buffer, size_t length){        struct hpsb_packet *packet;        int retval = 0;                if (length == 0) {                return -EINVAL;        }        if (host->node_id == node) {                switch(highlevel_write(host, node, buffer, addr, length)) {                case RCODE_COMPLETE:                        return 0;                case RCODE_TYPE_ERROR:                        return -EACCES;                case RCODE_ADDRESS_ERROR:                default:                        return -EINVAL;                }        }        if (length == 4) {                packet = hpsb_make_writeqpacket(host, node, addr, *buffer);        } else {                packet = hpsb_make_writebpacket(host, node, addr, length);        }        if (!packet) {                return -ENOMEM;        }        if (length != 4) {                memcpy(packet->data, buffer, length);        }        hpsb_send_packet(packet);        down(&packet->state_change);        down(&packet->state_change);        retval = hpsb_packet_success(packet);        free_tlabel(host, node, packet->tlabel);        free_hpsb_packet(packet);        return retval;}/* We need a hpsb_lock64 function for the 64 bit equivalent.  Probably. */int hpsb_lock(struct hpsb_host *host, nodeid_t node, u64 addr, int extcode,              quadlet_t *data, quadlet_t arg){        struct hpsb_packet *packet;        int retval = 0, length;                if (host->node_id == node) {                switch(highlevel_lock(host, node, data, addr, *data, arg,                                      extcode)) {                case RCODE_COMPLETE:                        return 0;                case RCODE_TYPE_ERROR:                        return -EACCES;                case RCODE_ADDRESS_ERROR:                default:                        return -EINVAL;                }        }        packet = alloc_hpsb_packet(8);        if (!packet) {                return -ENOMEM;        }        packet->host = host;        packet->tlabel = get_tlabel(host, node, 1);        packet->node_id = node;        switch (extcode) {        case EXTCODE_MASK_SWAP:        case EXTCODE_COMPARE_SWAP:        case EXTCODE_BOUNDED_ADD:        case EXTCODE_WRAP_ADD:                length = 8;                packet->data[0] = arg;                packet->data[1] = *data;                break;        case EXTCODE_FETCH_ADD:        case EXTCODE_LITTLE_ADD:                length = 4;                packet->data[0] = *data;                break;        default:                return -EINVAL;        }        fill_async_lock(packet, addr, extcode, length);        hpsb_send_packet(packet);        down(&packet->state_change);        down(&packet->state_change);        retval = hpsb_packet_success(packet);        if (retval == 0) {                *data = packet->data[0];        }        free_tlabel(host, node, packet->tlabel);        free_hpsb_packet(packet);        return retval;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -