Merge tag 'v3.14.25' into backport/v3.14.24-ltsi-rc1+v3.14.25/snapshot-merge.wip
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / staging / ktap / runtime / ffi / cdata.c
1 /*
2  * cdata.c - support functions for ktap_cdata
3  *
4  * This file is part of ktap by Jovi Zhangwei
5  *
6  * Copyright (C) 2012-2013 Jovi Zhangwei <jovi.zhangwei@gmail.com>.
7  *
8  * ktap is free software; you can redistribute it and/or modify it
9  * under the terms and conditions of the GNU General Public License,
10  * version 2, as published by the Free Software Foundation.
11  *
12  * ktap is distributed in the hope it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22
23 #include "../../include/ktap_types.h"
24 #include "../../include/ktap_ffi.h"
25 #include "../kp_obj.h"
26
27 ktap_cdata *kp_cdata_new(ktap_state *ks)
28 {
29         ktap_cdata *cd;
30
31         cd = &kp_newobject(ks, KTAP_TCDATA, sizeof(ktap_cdata), NULL)->cd;
32
33         return cd;
34 }
35
36 ktap_cdata *kp_cdata_new_ptr(ktap_state *ks, void *addr, csymbol_id id)
37 {
38         ktap_cdata *cd;
39
40         cd = kp_cdata_new(ks);
41         cd_set_csym_id(cd, id);
42         cd_ptr(cd) = addr;
43
44         return cd;
45 }
46
47 ktap_cdata *kp_cdata_new_struct(ktap_state *ks, void *val, csymbol_id id)
48 {
49         ktap_cdata *cd;
50
51         cd = kp_cdata_new(ks);
52         cd_set_csym_id(cd, id);
53         cd_struct(cd) = val;
54
55         return cd;
56 }
57
58 void kp_cdata_dump(ktap_state *ks, ktap_cdata *cd)
59 {
60         switch (cd_type(ks, cd)) {
61         case FFI_PTR:
62                 kp_printf(ks, "pointer(%p)", cd_ptr(cd));
63                 break;
64         default:
65                 kp_printf(ks, "unsupported cdata type %d!\n", cd_type(ks, cd));
66         }
67 }