コード例 #1
0
ファイル: calg2.c プロジェクト: clopez/kgpu
static int __init minit(void)
{
    struct kgpu_req* req;
    struct kgpu_resp* resp;
    struct kgpu_buffer *buf;
    
    printk("[calg2]: loaded\n");

    req = alloc_kgpu_request();
    if (!req) {
	printk("[calg2] Error: request null\n");
	return 0;
    }
    resp = alloc_kgpu_response();
    if (!resp) {
	printk("[calg2] Error: response null\n");
	return 0;
    }
    buf = alloc_gpu_buffer(PAGE_SIZE);
    if (!buf) {
	printk("[calg2] Error: buffer null\n");
	return 0;
    }
    req->data = buf;
    /*req->kureq.id = next_kgpu_request_id();*/
    resp->kuresp.id = req->kureq.id;

    req->kureq.input = buf->va;
    req->kureq.insize = 1024;
    req->kureq.output = req->kureq.input;/*+1024;*/
    req->kureq.outsize = 1024;
    strcpy(req->kureq.sname, "test_service");
    req->cb = mycb;

    *(int*)(__va(buf->pas[0])) = 100;
    call_gpu(req, resp);
    
    return 0;
}
コード例 #2
0
ファイル: gaes_ecb.c プロジェクト: eeide/kgpu
static int crypto_gecb_crypt(struct blkcipher_desc *desc,
                             struct scatterlist *dst, struct scatterlist *src,
                             unsigned int sz,
                             int enc)
{
    int err=0;
    unsigned int nbytes;
    u8* gpos;
    int i = 0;

    struct kgpu_req *req;
    struct kgpu_resp *resp;
    struct kgpu_buffer *buf;

    struct crypto_blkcipher *tfm = desc->tfm;
    struct crypto_gecb_ctx *ctx = crypto_blkcipher_ctx(tfm);
    struct blkcipher_walk walk;


    blkcipher_walk_init(&walk, dst, src, sz);

    buf = alloc_gpu_buffer();
    if (!buf) {
        printk("[gecb] Error: GPU buffer is null.\n");
        return -EFAULT;
    }

    req = alloc_kgpu_request();
    resp = alloc_kgpu_response();
    if (!req || !resp) {
        return -EFAULT;
    }

    err = blkcipher_walk_virt(desc, &walk);

    while ((nbytes = walk.nbytes)) {
        u8 *wsrc = walk.src.virt.addr;
        if (nbytes > KGPU_BUF_FRAME_SIZE) {
            return -EFAULT;
        }

#ifndef _NDEBUG
        if (nbytes != PAGE_SIZE)
            printk("[gecb] WARNING: %u is not PAGE_SIZE\n", nbytes);

#endif

        gpos = buf->paddrs[i++];
        memcpy(__va(gpos), wsrc, nbytes);

        err = blkcipher_walk_done(desc, &walk, 0);
    }

    gpos = buf->paddrs[i];
    memcpy(__va(gpos), &(ctx->aes_ctx), sizeof(struct crypto_aes_ctx));

    strcpy(req->kureq.sname, enc?"gecb-enc":"gecb-dec");
    req->kureq.input = buf->gb.addr;
    req->kureq.output = buf->gb.addr;
    req->kureq.insize = sz+PAGE_SIZE;
    req->kureq.outsize = sz;

    if (call_gpu_sync(req, resp)) {
        err = -EFAULT;
        printk("[gecb] Error: callgpu error\n");
    } else {
        i=0;
        blkcipher_walk_init(&walk, dst, src, sz);
        err = blkcipher_walk_virt(desc, &walk);

        while ((nbytes = walk.nbytes)) {
            u8 *wdst = walk.dst.virt.addr;
            if (nbytes > KGPU_BUF_FRAME_SIZE) {
                return -EFAULT;
            }

#ifndef _NDEBUG
            if (nbytes != PAGE_SIZE)
                printk("[gecb] WARNING: %u is not PAGE_SIZE\n", nbytes);
#endif

            gpos = buf->paddrs[i++];
            memcpy(wdst, __va(gpos), nbytes);

            err = blkcipher_walk_done(desc, &walk, 0);
        }
    }

    free_kgpu_request(req);
    free_kgpu_response(resp);
    free_gpu_buffer(buf);

    return err;
}