ccfc39ec887ab4aa3303fe6105288f60a7797ee3
[oweals/u-boot.git] / drivers / remoteproc / ti_sci_proc.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Texas Instruments TI-SCI Processor Controller Helper Functions
4  *
5  * Copyright (C) 2018-2019 Texas Instruments Incorporated - http://www.ti.com/
6  *      Lokesh Vutla <lokeshvutla@ti.com>
7  *      Suman Anna <s-anna@ti.com>
8  */
9
10 #ifndef REMOTEPROC_TI_SCI_PROC_H
11 #define REMOTEPROC_TI_SCI_PROC_H
12
13 #define TISCI_INVALID_HOST 0xff
14
15 /**
16  * struct ti_sci_proc - structure representing a processor control client
17  * @sci: cached TI-SCI protocol handle
18  * @ops: cached TI-SCI proc ops
19  * @proc_id: processor id for the consumer remoteproc device
20  * @host_id: host id to pass the control over for this consumer remoteproc
21  *           device
22  */
23 struct ti_sci_proc {
24         const struct ti_sci_handle *sci;
25         const struct ti_sci_proc_ops *ops;
26         u8 proc_id;
27         u8 host_id;
28 };
29
30 static inline int ti_sci_proc_request(struct ti_sci_proc *tsp)
31 {
32         int ret;
33
34         debug("%s: proc_id = %d\n", __func__, tsp->proc_id);
35
36         ret = tsp->ops->proc_request(tsp->sci, tsp->proc_id);
37         if (ret)
38                 pr_err("ti-sci processor request failed: %d\n", ret);
39         return ret;
40 }
41
42 static inline int ti_sci_proc_release(struct ti_sci_proc *tsp)
43 {
44         int ret;
45
46         debug("%s: proc_id = %d\n", __func__, tsp->proc_id);
47
48         if (tsp->host_id != TISCI_INVALID_HOST)
49                 ret = tsp->ops->proc_handover(tsp->sci, tsp->proc_id,
50                                               tsp->host_id);
51         else
52                 ret = tsp->ops->proc_release(tsp->sci, tsp->proc_id);
53
54         if (ret)
55                 pr_err("ti-sci processor release failed: %d\n", ret);
56         return ret;
57 }
58
59 static inline int ti_sci_proc_handover(struct ti_sci_proc *tsp)
60 {
61         int ret;
62
63         debug("%s: proc_id = %d\n", __func__, tsp->proc_id);
64
65         ret = tsp->ops->proc_handover(tsp->sci, tsp->proc_id, tsp->host_id);
66         if (ret)
67                 pr_err("ti-sci processor handover of %d to %d failed: %d\n",
68                        tsp->proc_id, tsp->host_id, ret);
69         return ret;
70 }
71
72 static inline int ti_sci_proc_get_status(struct ti_sci_proc *tsp,
73                                          u64 *boot_vector, u32 *cfg_flags,
74                                          u32 *ctrl_flags, u32 *status_flags)
75 {
76         int ret;
77
78         ret = tsp->ops->get_proc_boot_status(tsp->sci, tsp->proc_id,
79                                              boot_vector, cfg_flags, ctrl_flags,
80                                              status_flags);
81         if (ret)
82                 pr_err("ti-sci processor get_status failed: %d\n", ret);
83
84         debug("%s: proc_id = %d, boot_vector = 0x%llx, cfg_flags = 0x%x, ctrl_flags = 0x%x, sts = 0x%x\n",
85               __func__, tsp->proc_id, *boot_vector, *cfg_flags, *ctrl_flags,
86               *status_flags);
87         return ret;
88 }
89
90 static inline int ti_sci_proc_set_config(struct ti_sci_proc *tsp,
91                                          u64 boot_vector,
92                                          u32 cfg_set, u32 cfg_clr)
93 {
94         int ret;
95
96         debug("%s: proc_id = %d, boot_vector = 0x%llx, cfg_set = 0x%x, cfg_clr = 0x%x\n",
97               __func__, tsp->proc_id, boot_vector, cfg_set, cfg_clr);
98
99         ret = tsp->ops->set_proc_boot_cfg(tsp->sci, tsp->proc_id, boot_vector,
100                                           cfg_set, cfg_clr);
101         if (ret)
102                 pr_err("ti-sci processor set_config failed: %d\n", ret);
103         return ret;
104 }
105
106 static inline int ti_sci_proc_set_control(struct ti_sci_proc *tsp,
107                                           u32 ctrl_set, u32 ctrl_clr)
108 {
109         int ret;
110
111         debug("%s: proc_id = %d, ctrl_set = 0x%x, ctrl_clr = 0x%x\n", __func__,
112               tsp->proc_id, ctrl_set, ctrl_clr);
113
114         ret = tsp->ops->set_proc_boot_ctrl(tsp->sci, tsp->proc_id, ctrl_set,
115                                            ctrl_clr);
116         if (ret)
117                 pr_err("ti-sci processor set_control failed: %d\n", ret);
118         return ret;
119 }
120
121 #endif /* REMOTEPROC_TI_SCI_PROC_H */