1 /*
2 *
3 * Device Tree Overlay functions.
4 * Copyright (C) 2021 Xilinx Inc.
5 * Author Vikram Garhwal <fnu.vikram@xilinx.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation;
10 * version 2.1 of the License.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "xc_private.h"
22
xc_dt_overlay(xc_interface * xch,void * overlay_fdt,uint32_t overlay_fdt_size,uint8_t overlay_op)23 int xc_dt_overlay(xc_interface *xch, void *overlay_fdt,
24 uint32_t overlay_fdt_size, uint8_t overlay_op)
25 {
26 int err;
27 struct xen_sysctl sysctl = {
28 .cmd = XEN_SYSCTL_dt_overlay,
29 .u.dt_overlay = {
30 .overlay_op = overlay_op,
31 .overlay_fdt_size = overlay_fdt_size,
32 }
33 };
34
35 DECLARE_HYPERCALL_BOUNCE(overlay_fdt, overlay_fdt_size,
36 XC_HYPERCALL_BUFFER_BOUNCE_IN);
37
38 if ( (err = xc_hypercall_bounce_pre(xch, overlay_fdt)) )
39 goto err;
40
41 set_xen_guest_handle(sysctl.u.dt_overlay.overlay_fdt, overlay_fdt);
42
43 if ( (err = do_sysctl(xch, &sysctl)) != 0 )
44 PERROR("%s failed", __func__);
45
46 err:
47 xc_hypercall_bounce_post(xch, overlay_fdt);
48
49 return err;
50 }
51
xc_dt_overlay_domain(xc_interface * xch,void * overlay_fdt,uint32_t overlay_fdt_size,uint8_t overlay_op,uint32_t domain_id)52 int xc_dt_overlay_domain(xc_interface *xch, void *overlay_fdt,
53 uint32_t overlay_fdt_size, uint8_t overlay_op,
54 uint32_t domain_id)
55 {
56 int err;
57 struct xen_domctl domctl = {
58 .cmd = XEN_DOMCTL_dt_overlay,
59 .domain = domain_id,
60 .u.dt_overlay = {
61 .overlay_op = overlay_op,
62 .overlay_fdt_size = overlay_fdt_size,
63 }
64 };
65
66 DECLARE_HYPERCALL_BOUNCE(overlay_fdt, overlay_fdt_size,
67 XC_HYPERCALL_BUFFER_BOUNCE_IN);
68
69 if ( (err = xc_hypercall_bounce_pre(xch, overlay_fdt)) )
70 goto err;
71
72 set_xen_guest_handle(domctl.u.dt_overlay.overlay_fdt, overlay_fdt);
73
74 if ( (err = do_domctl(xch, &domctl)) != 0 )
75 PERROR("%s failed", __func__);
76
77 err:
78 xc_hypercall_bounce_post(xch, overlay_fdt);
79
80 return err;
81 }
82