3d58ab87156325de7097c51d6820c01b77414ecb
[linux-2.6-microblaze.git] / drivers / gpu / drm / nouveau / nvkm / subdev / secboot / acr_r352.h
1 /*
2  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 #ifndef __NVKM_SECBOOT_ACR_R352_H__
23 #define __NVKM_SECBOOT_ACR_R352_H__
24
25 #include "acr.h"
26 #include "ls_ucode.h"
27 #include "hs_ucode.h"
28
29 struct ls_ucode_img;
30
31 #define ACR_R352_MAX_APPS 8
32
33 #define LSF_FLAG_LOAD_CODE_AT_0         1
34 #define LSF_FLAG_DMACTL_REQ_CTX         4
35 #define LSF_FLAG_FORCE_PRIV_LOAD        8
36
37 static inline u32
38 hsf_load_header_app_off(const struct hsf_load_header *hdr, u32 app)
39 {
40         return hdr->apps[app];
41 }
42
43 static inline u32
44 hsf_load_header_app_size(const struct hsf_load_header *hdr, u32 app)
45 {
46         return hdr->apps[hdr->num_apps + app];
47 }
48
49 /**
50  * struct acr_r352_ls_func - manages a single LS firmware
51  *
52  * @load: load the external firmware into a ls_ucode_img
53  * @generate_bl_desc: function called on a block of bl_desc_size to generate the
54  *                    proper bootloader descriptor for this LS firmware
55  * @bl_desc_size: size of the bootloader descriptor
56  * @post_run: hook called right after the ACR is executed
57  * @lhdr_flags: LS flags
58  */
59 struct acr_r352_ls_func {
60         int (*load)(const struct nvkm_secboot *, struct ls_ucode_img *);
61         void (*generate_bl_desc)(const struct nvkm_acr *,
62                                  const struct ls_ucode_img *, u64, void *);
63         u32 bl_desc_size;
64         int (*post_run)(const struct nvkm_acr *, const struct nvkm_secboot *);
65         u32 lhdr_flags;
66 };
67
68 struct acr_r352;
69
70 /**
71  * struct acr_r352_func - manages nuances between ACR versions
72  *
73  * @generate_hs_bl_desc: function called on a block of bl_desc_size to generate
74  *                       the proper HS bootloader descriptor
75  * @hs_bl_desc_size: size of the HS bootloader descriptor
76  */
77 struct acr_r352_func {
78         void (*generate_hs_bl_desc)(const struct hsf_load_header *, void *,
79                                     u64);
80         void (*fixup_hs_desc)(struct acr_r352 *, struct nvkm_secboot *, void *);
81         u32 hs_bl_desc_size;
82         bool shadow_blob;
83
84         struct ls_ucode_img *(*ls_ucode_img_load)(const struct acr_r352 *,
85                                                   const struct nvkm_secboot *,
86                                                   enum nvkm_secboot_falcon);
87         int (*ls_fill_headers)(struct acr_r352 *, struct list_head *);
88         int (*ls_write_wpr)(struct acr_r352 *, struct list_head *,
89                             struct nvkm_gpuobj *, u64);
90
91         const struct acr_r352_ls_func *ls_func[NVKM_SECBOOT_FALCON_END];
92 };
93
94 /**
95  * struct acr_r352 - ACR data for driver release 352 (and beyond)
96  */
97 struct acr_r352 {
98         struct nvkm_acr base;
99         const struct acr_r352_func *func;
100
101         /*
102          * HS FW - lock WPR region (dGPU only) and load LS FWs
103          * on Tegra the HS FW copies the LS blob into the fixed WPR instead
104          */
105         struct nvkm_gpuobj *load_blob;
106         struct {
107                 struct hsf_load_header load_bl_header;
108                 u32 __load_apps[ACR_R352_MAX_APPS * 2];
109         };
110
111         /* HS FW - unlock WPR region (dGPU only) */
112         struct nvkm_gpuobj *unload_blob;
113         struct {
114                 struct hsf_load_header unload_bl_header;
115                 u32 __unload_apps[ACR_R352_MAX_APPS * 2];
116         };
117
118         /* HS bootloader */
119         void *hsbl_blob;
120
121         /* HS bootloader for unload blob, if using a different falcon */
122         void *hsbl_unload_blob;
123
124         /* LS FWs, to be loaded by the HS ACR */
125         struct nvkm_gpuobj *ls_blob;
126
127         /* Firmware already loaded? */
128         bool firmware_ok;
129
130         /* Falcons to lazy-bootstrap */
131         u32 lazy_bootstrap;
132
133         /* To keep track of the state of all managed falcons */
134         enum {
135                 /* In non-secure state, no firmware loaded, no privileges*/
136                 NON_SECURE = 0,
137                 /* In low-secure mode and ready to be started */
138                 RESET,
139                 /* In low-secure mode and running */
140                 RUNNING,
141         } falcon_state[NVKM_SECBOOT_FALCON_END];
142 };
143 #define acr_r352(acr) container_of(acr, struct acr_r352, base)
144
145 struct nvkm_acr *acr_r352_new_(const struct acr_r352_func *,
146                                enum nvkm_secboot_falcon, unsigned long);
147
148 struct ls_ucode_img *acr_r352_ls_ucode_img_load(const struct acr_r352 *,
149                                                 const struct nvkm_secboot *,
150                                                 enum nvkm_secboot_falcon);
151 int acr_r352_ls_fill_headers(struct acr_r352 *, struct list_head *);
152 int acr_r352_ls_write_wpr(struct acr_r352 *, struct list_head *,
153                           struct nvkm_gpuobj *, u64);
154
155 void acr_r352_fixup_hs_desc(struct acr_r352 *, struct nvkm_secboot *, void *);
156
157 #endif