Commit SDMA driver changes.
[barrelfish] / usr / drivers / omap44xx / sdma / service.c
1 /*
2  * Copyright (c) 2014, ETH Zurich.
3  * All rights reserved.
4  *
5  * This file is distributed under the terms in the attached LICENSE file.
6  * If you do not find this file, copies can be found by writing to:
7  * ETH Zurich D-INFK, CAB F.78, Universitaetstr 6, CH-8092 Zurich.
8  */
9
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <assert.h>
14
15 #include <barrelfish/barrelfish.h>
16 #include <barrelfish/nameservice_client.h>
17
18 #include <if/omap_sdma_defs.h>
19 #include <if/omap_sdma_thc.h>
20 #include <thc/thc.h>
21
22 #include "sdma.h"
23
24 static void run_service(struct sdma_driver_state* st, struct omap_sdma_thc_service_binding_t *sv)
25 {
26     omap_sdma_service_msg_t msg;
27     bool loop = true;
28
29     // this is the bitmap of messages we are interested in receiving
30     struct omap_sdma_service_selector selector = {
31         .mem_copy = 1, .mem_copy_2d = 1,
32         .mem_fill = 1, .mem_fill_2d = 1,
33     };
34
35     while (loop) {
36         // receive any message
37         sv->recv_any(sv, &msg, selector);
38
39         errval_t reterr = SYS_ERR_OK;
40
41         // dispatch it
42         switch(msg.msg) {
43         case omap_sdma_mem_copy:
44             reterr = mem_copy(st,
45                 msg.args.mem_copy.in.dst,
46                 msg.args.mem_copy.in.src);
47             sv->send.mem_copy(sv, reterr);
48             break;
49         case omap_sdma_mem_fill:
50             reterr = mem_fill(st,
51                 msg.args.mem_fill.in.dst,
52                 msg.args.mem_fill.in.color);
53             sv->send.mem_fill(sv, reterr);
54             break;
55         case omap_sdma_mem_copy_2d:
56             reterr = mem_copy_2d(st,
57                 msg.args.mem_copy_2d.in.dst,
58                 msg.args.mem_copy_2d.in.src,
59                 msg.args.mem_copy_2d.in.count,
60                 msg.args.mem_copy_2d.in.transparent,
61                 msg.args.mem_copy_2d.in.color);
62             sv->send.mem_copy_2d(sv, reterr);
63             break;
64         case omap_sdma_mem_fill_2d:
65             reterr = mem_fill_2d(st,
66                 msg.args.mem_fill_2d.in.dst,
67                 msg.args.mem_fill_2d.in.count,
68                 msg.args.mem_fill_2d.in.color);
69             sv->send.mem_fill_2d(sv, reterr);
70             break;
71         default:
72             debug_printf("unexpected message: %d\n", msg.msg);
73             loop = false;
74             break;
75         }
76     }
77
78     free(sv);
79 }
80
81 void start_service(struct sdma_driver_state* st)
82 {
83     errval_t err;
84
85     struct omap_sdma_thc_export_info e_info;
86     struct omap_sdma_thc_service_binding_t *sv;
87     struct omap_sdma_binding *b;
88     iref_t iref;
89
90     err = omap_sdma_thc_export(&e_info, "sdma",
91                              get_default_waitset(),
92                              IDC_EXPORT_FLAGS_DEFAULT,
93                              &iref);
94     if (err_is_fail(err)) {
95         USER_PANIC_ERR(err, "thc export failed");
96     }
97
98     DO_FINISH({
99         while(true) {
100             err = omap_sdma_thc_accept(&e_info, &b);
101             if (err_is_fail(err)) {
102                 USER_PANIC_ERR(err, "thc accept failed");
103             }
104
105             sv = malloc(sizeof(struct omap_sdma_thc_service_binding_t));
106             assert(sv != NULL);
107
108             err = omap_sdma_thc_init_service(sv, b, b);
109             if (err_is_fail(err)) {
110                 USER_PANIC_ERR(err, "thc init failed");
111             }
112
113             ASYNC({run_service(st, sv);});
114         }
115     });
116 }