1 #include <lunaix/blkio.h>
2 #include <lunaix/mm/cake.h>
3 #include <lunaix/mm/valloc.h>
5 static struct cake_pile* blkio_reqpile;
10 blkio_reqpile = cake_new_pile("blkio_req", sizeof(struct blkio_req), 1, 0);
13 static inline struct blkio_req*
14 __blkio_req_create(struct vecbuf* buffer,
20 options = options & ~0xf;
21 struct blkio_req* breq = (struct blkio_req*)cake_grab(blkio_reqpile);
22 *breq = (struct blkio_req){ .blk_addr = start_lba,
23 .completed = completed,
25 .evt_args = evt_args };
31 blkio_vrd(struct vecbuf* buffer,
37 return __blkio_req_create(buffer, start_lba, completed, evt_args, options);
41 blkio_vwr(struct vecbuf* buffer,
47 struct blkio_req* breq =
48 __blkio_req_create(buffer, start_lba, completed, evt_args, options);
49 breq->flags |= BLKIO_WRITE;
54 blkio_free_req(struct blkio_req* req)
56 cake_release(blkio_reqpile, (void*)req);
60 blkio_newctx(req_handler handler)
62 struct blkio_context* ctx =
63 (struct blkio_context*)vzalloc(sizeof(struct blkio_context));
64 ctx->handle_one = handler;
66 llist_init_head(&ctx->queue);
72 blkio_commit(struct blkio_context* ctx, struct blkio_req* req)
74 req->flags |= BLKIO_PENDING;
76 llist_append(&ctx->queue, &req->reqs);
78 // if the pipeline is not running (e.g., stalling). Then we should schedule
79 // one immediately and kick it start.
86 blkio_schedule(struct blkio_context* ctx)
88 if (llist_empty(&ctx->queue)) {
92 struct blkio_req* head = (struct blkio_req*)ctx->queue.next;
93 llist_delete(&head->reqs);
95 head->flags |= BLKIO_BUSY;
98 ctx->handle_one(head);
102 blkio_complete(struct blkio_req* req)
104 req->flags &= ~(BLKIO_BUSY | BLKIO_PENDING);
105 if (req->completed) {
108 if ((req->flags & BLKIO_FOC)) {
114 blkio_schedule(req->io_ctx);