1b8e80941Smrg/*
2b8e80941Smrg * Copyright © 2018 Intel Corporation
3b8e80941Smrg *
4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5b8e80941Smrg * copy of this software and associated documentation files (the "Software"),
6b8e80941Smrg * to deal in the Software without restriction, including without limitation
7b8e80941Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the
9b8e80941Smrg * Software is furnished to do so, subject to the following conditions:
10b8e80941Smrg *
11b8e80941Smrg * The above copyright notice and this permission notice (including the next
12b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the
13b8e80941Smrg * Software.
14b8e80941Smrg *
15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21b8e80941Smrg * IN THE SOFTWARE.
22b8e80941Smrg */
23b8e80941Smrg
24b8e80941Smrg#ifndef GEN10_CONTEXT_H
25b8e80941Smrg#define GEN10_CONTEXT_H
26b8e80941Smrg
27b8e80941Smrgstatic inline void gen10_render_context_init(const struct gen_context_parameters *params,
28b8e80941Smrg                                             uint32_t *data, uint32_t *size)
29b8e80941Smrg{
30b8e80941Smrg   *size = CONTEXT_RENDER_SIZE;
31b8e80941Smrg   if (!data)
32b8e80941Smrg      return;
33b8e80941Smrg
34b8e80941Smrg   *data++ = 0; /* MI_NOOP */
35b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, MI_LRI_FORCE_POSTED,
36b8e80941Smrg                             0x2244 /* CONTEXT_CONTROL */,         0x90009 /* Inhibit Synchronous Context Switch | Engine Context Restore Inhibit */,
37b8e80941Smrg                             0x2034 /* RING_HEAD */,               0,
38b8e80941Smrg                             0x2030 /* RING_TAIL */,               0,
39b8e80941Smrg                             0x2038 /* RING_BUFFER_START */,       params->ring_addr,
40b8e80941Smrg                             0x203C /* RING_BUFFER_CONTROL */,     (params->ring_size - 4096) | 1 /* Buffer Length | Ring Buffer Enable */,
41b8e80941Smrg                             0x2168 /* BB_HEAD_U */,               0,
42b8e80941Smrg                             0x2140 /* BB_HEAD_L */,               0,
43b8e80941Smrg                             0x2110 /* BB_STATE */,                0,
44b8e80941Smrg                             0x211C /* SECOND_BB_HEAD_U */,        0,
45b8e80941Smrg                             0x2114 /* SECOND_BB_HEAD_L */,        0,
46b8e80941Smrg                             0x2118 /* SECOND_BB_STATE */,         0,
47b8e80941Smrg                             0x21C0 /* BB_PER_CTX_PTR */,          0,
48b8e80941Smrg                             0x21C4 /* RCS_INDIRECT_CTX */,        0,
49b8e80941Smrg                             0x21C8 /* RCS_INDIRECT_CTX_OFFSET */, 0,
50b8e80941Smrg                             0x2180 /* CCID */,		           0);
51b8e80941Smrg   *data++ = 0; /* MI_NOOP */
52b8e80941Smrg
53b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, MI_LRI_FORCE_POSTED,
54b8e80941Smrg                             0x23A8 /* CTX_TIMESTAMP */, 0,
55b8e80941Smrg                             0x228C /* PDP3_UDW */,      0,
56b8e80941Smrg                             0x2288 /* PDP3_LDW */,      0,
57b8e80941Smrg                             0x2284 /* PDP2_UDW */,      0,
58b8e80941Smrg                             0x2280 /* PDP2_LDW */,      0,
59b8e80941Smrg                             0x227C /* PDP1_UDW */,      0,
60b8e80941Smrg                             0x2278 /* PDP1_LDW */,      0,
61b8e80941Smrg                             0x2274 /* PDP0_UDW */,      params->pml4_addr >> 32,
62b8e80941Smrg                             0x2270 /* PDP0_LDW */,      params->pml4_addr & 0xffffffff);
63b8e80941Smrg   for (int i = 0; i < 12; i++)
64b8e80941Smrg      *data++ = 0; /* MI_NOOP */
65b8e80941Smrg
66b8e80941Smrg   *data++ = 0; /* MI_NOOP */
67b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, 0,
68b8e80941Smrg                             0x20C8 /* R_PWR_CLK_STATE */, 0x7FFFFFFF,
69b8e80941Smrg                             0, /* GPGPU_CSR_BASE_ADDRESS ? */ 0);
70b8e80941Smrg   *data++ = 0; /* MI_NOOP */
71b8e80941Smrg
72b8e80941Smrg   for (int i = 0; i < 9; i++)
73b8e80941Smrg      *data++ = 0;
74b8e80941Smrg
75b8e80941Smrg   *data++ = MI_BATCH_BUFFER_END | 1 /* End Context */;
76b8e80941Smrg}
77b8e80941Smrg
78b8e80941Smrgstatic inline void gen10_blitter_context_init(const struct gen_context_parameters *params,
79b8e80941Smrg                                              uint32_t *data, uint32_t *size)
80b8e80941Smrg{
81b8e80941Smrg   *size = CONTEXT_OTHER_SIZE;
82b8e80941Smrg   if (!data)
83b8e80941Smrg      return;
84b8e80941Smrg
85b8e80941Smrg   *data++ = 0 /* MI_NOOP */;
86b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, MI_LRI_FORCE_POSTED,
87b8e80941Smrg                             0x22244 /* CONTEXT_CONTROL */,     0x90009 /* Inhibit Synchronous Context Switch | Engine Context Restore Inhibit */,
88b8e80941Smrg                             0x22034 /* RING_HEAD */,           0,
89b8e80941Smrg                             0x22030 /* RING_TAIL */,           0,
90b8e80941Smrg                             0x22038 /* RING_BUFFER_START */,   params->ring_addr,
91b8e80941Smrg                             0x2203C /* RING_BUFFER_CONTROL */, (params->ring_size - 4096) | 1 /* Buffer Length | Ring Buffer Enable */,
92b8e80941Smrg                             0x22168 /* BB_HEAD_U */,           0,
93b8e80941Smrg                             0x22140 /* BB_HEAD_L */,           0,
94b8e80941Smrg                             0x22110 /* BB_STATE */,            0,
95b8e80941Smrg                             0x2211C /* SECOND_BB_HEAD_U */,    0,
96b8e80941Smrg                             0x22114 /* SECOND_BB_HEAD_L */,    0,
97b8e80941Smrg                             0x22118 /* SECOND_BB_STATE */,     0,
98b8e80941Smrg                             0x221C0 /* BB_PER_CTX_PTR */,	0,
99b8e80941Smrg                             0x221C4 /* INDIRECT_CTX */,	0,
100b8e80941Smrg                             0x221C8 /* INDIRECT_CTX_OFFSET */, 0);
101b8e80941Smrg   *data++ = 0 /* MI_NOOP */;
102b8e80941Smrg   *data++ = 0 /* MI_NOOP */;
103b8e80941Smrg
104b8e80941Smrg   *data++ = 0 /* MI_NOOP */;
105b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, MI_LRI_FORCE_POSTED,
106b8e80941Smrg                             0x223A8 /* CTX_TIMESTAMP */, 0,
107b8e80941Smrg                             0x2228C /* PDP3_UDW */,      0,
108b8e80941Smrg                             0x22288 /* PDP3_LDW */,      0,
109b8e80941Smrg                             0x22284 /* PDP2_UDW */,      0,
110b8e80941Smrg                             0x22280 /* PDP2_LDW */,      0,
111b8e80941Smrg                             0x2227C /* PDP1_UDW */,      0,
112b8e80941Smrg                             0x22278 /* PDP1_LDW */,      0,
113b8e80941Smrg                             0x22274 /* PDP0_UDW */,      params->pml4_addr >> 32,
114b8e80941Smrg                             0x22270 /* PDP0_LDW */,      params->pml4_addr & 0xffffffff);
115b8e80941Smrg   for (int i = 0; i < 13; i++)
116b8e80941Smrg      *data++ = 0 /* MI_NOOP */;
117b8e80941Smrg
118b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, 0,
119b8e80941Smrg                             0x22200 /* BCS_SWCTRL */,	0);
120b8e80941Smrg
121b8e80941Smrg   for (int i = 0; i < 12; i++)
122b8e80941Smrg      *data++ = 0 /* MI_NOOP */;
123b8e80941Smrg
124b8e80941Smrg
125b8e80941Smrg   *data++ = MI_BATCH_BUFFER_END | 1 /* End Context */;
126b8e80941Smrg}
127b8e80941Smrg
128b8e80941Smrgstatic inline void gen10_video_context_init(const struct gen_context_parameters *params,
129b8e80941Smrg                                            uint32_t *data, uint32_t *size)
130b8e80941Smrg{
131b8e80941Smrg   *size = CONTEXT_OTHER_SIZE;
132b8e80941Smrg   if (!data)
133b8e80941Smrg      return;
134b8e80941Smrg
135b8e80941Smrg   *data++ = 0 /* MI_NOOP */;
136b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, MI_LRI_FORCE_POSTED,
137b8e80941Smrg                             0x1C244 /* CONTEXT_CONTROL */,     0x90009 /* Inhibit Synchronous Context Switch | Engine Context Restore Inhibit */,
138b8e80941Smrg                             0x1C034 /* RING_HEAD */,           0,
139b8e80941Smrg                             0x1C030 /* RING_TAIL */,           0,
140b8e80941Smrg                             0x1C038 /* RING_BUFFER_START */,   params->ring_addr,
141b8e80941Smrg                             0x1C03C /* RING_BUFFER_CONTROL */, (params->ring_size - 4096) | 1 /* Buffer Length | Ring Buffer Enable */,
142b8e80941Smrg                             0x1C168 /* BB_HEAD_U */,           0,
143b8e80941Smrg                             0x1C140 /* BB_HEAD_L */,           0,
144b8e80941Smrg                             0x1C110 /* BB_STATE */,            0,
145b8e80941Smrg                             0x1C11C /* SECOND_BB_HEAD_U */,    0,
146b8e80941Smrg                             0x1C114 /* SECOND_BB_HEAD_L */,    0,
147b8e80941Smrg                             0x1C118 /* SECOND_BB_STATE */,     0);
148b8e80941Smrg   for (int i = 0; i < 8; i++)
149b8e80941Smrg      *data++ = 0 /* MI_NOOP */;
150b8e80941Smrg
151b8e80941Smrg   *data++ = 0 /* MI_NOOP */;
152b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, MI_LRI_FORCE_POSTED,
153b8e80941Smrg                             0x1C3A8 /* CTX_TIMESTAMP */, 0,
154b8e80941Smrg                             0x1C28C /* PDP3_UDW */,      0,
155b8e80941Smrg                             0x1C288 /* PDP3_LDW */,      0,
156b8e80941Smrg                             0x1C284 /* PDP2_UDW */,      0,
157b8e80941Smrg                             0x1C280 /* PDP2_LDW */,      0,
158b8e80941Smrg                             0x1C27C /* PDP1_UDW */,      0,
159b8e80941Smrg                             0x1C278 /* PDP1_LDW */,      0,
160b8e80941Smrg                             0x1C274 /* PDP0_UDW */,      params->pml4_addr >> 32,
161b8e80941Smrg                             0x1C270 /* PDP0_LDW */,      params->pml4_addr & 0xffffffff);
162b8e80941Smrg   for (int i = 0; i < 12; i++)
163b8e80941Smrg      *data++ = 0 /* MI_NOOP */;
164b8e80941Smrg
165b8e80941Smrg   *data++ = MI_BATCH_BUFFER_END | 1  /* End Context */;
166b8e80941Smrg}
167b8e80941Smrg
168b8e80941Smrg#endif /* GEN10_CONTEXT_H */
169