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 GEN8_CONTEXT_H
25b8e80941Smrg#define GEN8_CONTEXT_H
26b8e80941Smrg
27b8e80941Smrgstatic inline void gen8_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 */,
37b8e80941Smrg                             0x90009 /* Inhibit Synchronous Context Switch | Engine Context Restore Inhibit */,
38b8e80941Smrg                             0x2034 /* RING_HEAD */, 0,
39b8e80941Smrg                             0x2030 /* RING_TAIL */, 0,
40b8e80941Smrg                             0x2038 /* RING_BUFFER_START */,       params->ring_addr,
41b8e80941Smrg                             0x203C /* RING_BUFFER_CONTROL */,     (params->ring_addr - 4096) | 1 /* Buffer Length | Ring Buffer Enable */,
42b8e80941Smrg                             0x2168 /* BB_HEAD_U */,               0,
43b8e80941Smrg                             0x2140 /* BB_HEAD_L */,               0,
44b8e80941Smrg                             0x2110 /* BB_STATE */,                0,
45b8e80941Smrg                             0x211C /* SECOND_BB_HEAD_U */,        0,
46b8e80941Smrg                             0x2114 /* SECOND_BB_HEAD_L */,        0,
47b8e80941Smrg                             0x2118 /* SECOND_BB_STATE */,         0,
48b8e80941Smrg                             0x21C0 /* BB_PER_CTX_PTR */,          0,
49b8e80941Smrg                             0x21C4 /* RCS_INDIRECT_CTX */,        0,
50b8e80941Smrg                             0x21C8 /* RCS_INDIRECT_CTX_OFFSET */, 0);
51b8e80941Smrg   /* MI_NOOP */
52b8e80941Smrg   *data++ = 0;
53b8e80941Smrg   *data++ = 0;
54b8e80941Smrg
55b8e80941Smrg   *data++ = 0; /* MI_NOOP */
56b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, MI_LRI_FORCE_POSTED,
57b8e80941Smrg                             0x23A8 /* CTX_TIMESTAMP */, 0,
58b8e80941Smrg                             0x228C /* PDP3_UDW */,      0,
59b8e80941Smrg                             0x2288 /* PDP3_LDW */,      0,
60b8e80941Smrg                             0x2284 /* PDP2_UDW */,      0,
61b8e80941Smrg                             0x2280 /* PDP2_LDW */,      0,
62b8e80941Smrg                             0x227C /* PDP1_UDW */,      0,
63b8e80941Smrg                             0x2278 /* PDP1_LDW */,      0,
64b8e80941Smrg                             0x2274 /* PDP0_UDW */,      params->pml4_addr >> 32,
65b8e80941Smrg                             0x2270 /* PDP0_LDW */,      params->pml4_addr & 0xffffffff);
66b8e80941Smrg   /* MI_NOOP */
67b8e80941Smrg   for (int i = 0; i < 12; i++)
68b8e80941Smrg      *data++ = 0 /* MI_NOOP */;
69b8e80941Smrg
70b8e80941Smrg   *data++ = 0 /* MI_NOOP */;
71b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, 0,
72b8e80941Smrg                             0x20C8 /* R_PWR_CLK_STATE */, 0x7FFFFFFF);
73b8e80941Smrg   *data++ = MI_BATCH_BUFFER_END;
74b8e80941Smrg}
75b8e80941Smrg
76b8e80941Smrgstatic inline void gen8_blitter_context_init(const struct gen_context_parameters *params,
77b8e80941Smrg                                             uint32_t *data, uint32_t *size)
78b8e80941Smrg{
79b8e80941Smrg   *size = CONTEXT_OTHER_SIZE;
80b8e80941Smrg   if (!data)
81b8e80941Smrg      return;
82b8e80941Smrg
83b8e80941Smrg   *data++ = 0 /* MI_NOOP */;
84b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, MI_LRI_FORCE_POSTED,
85b8e80941Smrg                             0x22244 /* CONTEXT_CONTROL */,     0x90009 /* Inhibit Synchronous Context Switch | Engine Context Restore Inhibit */,
86b8e80941Smrg                             0x22034 /* RING_HEAD */,           0,
87b8e80941Smrg                             0x22030 /* RING_TAIL */,           0,
88b8e80941Smrg                             0x22038 /* RING_BUFFER_START */,   params->ring_addr,
89b8e80941Smrg                             0x2203C /* RING_BUFFER_CONTROL */, (params->ring_size - 4096) | 1 /* Buffer Length | Ring Buffer Enable */,
90b8e80941Smrg                             0x22168 /* BB_HEAD_U */,           0,
91b8e80941Smrg                             0x22140 /* BB_HEAD_L */,           0,
92b8e80941Smrg                             0x22110 /* BB_STATE */,            0,
93b8e80941Smrg                             0x2211C /* SECOND_BB_HEAD_U */,    0,
94b8e80941Smrg                             0x22114 /* SECOND_BB_HEAD_L */,    0,
95b8e80941Smrg                             0x22118 /* SECOND_BB_STATE */,     0);
96b8e80941Smrg
97b8e80941Smrg   for (int i = 0; i < 8; i++)
98b8e80941Smrg      *data++ = 0 /* MI_NOOP */;
99b8e80941Smrg
100b8e80941Smrg   *data = 0 /* MI_NOOP */;
101b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, MI_LRI_FORCE_POSTED,
102b8e80941Smrg                             0x223A8 /* CTX_TIMESTAMP */, 0,
103b8e80941Smrg                             0x2228C /* PDP3_UDW */,      0,
104b8e80941Smrg                             0x22288 /* PDP3_LDW */,      0,
105b8e80941Smrg                             0x22284 /* PDP2_UDW */,      0,
106b8e80941Smrg                             0x22280 /* PDP2_LDW */,      0,
107b8e80941Smrg                             0x2227C /* PDP1_UDW */,      0,
108b8e80941Smrg                             0x22278 /* PDP1_LDW */,      0,
109b8e80941Smrg                             0x22274 /* PDP0_UDW */,      params->pml4_addr >> 32,
110b8e80941Smrg                             0x22270 /* PDP0_LDW */,      params->pml4_addr & 0xffffffff);
111b8e80941Smrg
112b8e80941Smrg   for (int i = 0; i < 12; i++)
113b8e80941Smrg      *data++ = 0 /* MI_NOOP */;
114b8e80941Smrg
115b8e80941Smrg   *data++ = MI_BATCH_BUFFER_END;
116b8e80941Smrg}
117b8e80941Smrg
118b8e80941Smrgstatic inline void gen8_video_context_init(const struct gen_context_parameters *params,
119b8e80941Smrg                                           uint32_t *data, uint32_t *size)
120b8e80941Smrg{
121b8e80941Smrg   *size = CONTEXT_OTHER_SIZE;
122b8e80941Smrg   if (!data)
123b8e80941Smrg      return;
124b8e80941Smrg
125b8e80941Smrg   *data++ = 0 /* MI_NOOP */;
126b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, MI_LRI_FORCE_POSTED,
127b8e80941Smrg                             0x1C244 /* CONTEXT_CONTROL */,     0x90009 /* Inhibit Synchronous Context Switch | Engine Context Restore Inhibit */,
128b8e80941Smrg                             0x1C034 /* RING_HEAD */,           0,
129b8e80941Smrg                             0x1C030 /* RING_TAIL */,           0,
130b8e80941Smrg                             0x1C038 /* RING_BUFFER_START */,   params->ring_addr,
131b8e80941Smrg                             0x1C03C /* RING_BUFFER_CONTROL */, (params->ring_size - 4096) | 1 /* Buffer Length | Ring Buffer Enable */,
132b8e80941Smrg                             0x1C168 /* BB_HEAD_U */,           0,
133b8e80941Smrg                             0x1C140 /* BB_HEAD_L */,           0,
134b8e80941Smrg                             0x1C110 /* BB_STATE */,            0,
135b8e80941Smrg                             0x1C11C /* SECOND_BB_HEAD_U */,    0,
136b8e80941Smrg                             0x1C114 /* SECOND_BB_HEAD_L */,    0,
137b8e80941Smrg                             0x1C118 /* SECOND_BB_STATE */,     0);
138b8e80941Smrg   for (int i = 0; i < 8; i++)
139b8e80941Smrg      *data++ = 0 /* MI_NOOP */;
140b8e80941Smrg
141b8e80941Smrg   *data++ = 0 /* MI_NOOP */;
142b8e80941Smrg   MI_LOAD_REGISTER_IMM_vals(data, MI_LRI_FORCE_POSTED,
143b8e80941Smrg                             0x1C3A8 /* CTX_TIMESTAMP */, 0,
144b8e80941Smrg                             0x1C28C /* PDP3_UDW */,      0,
145b8e80941Smrg                             0x1C288 /* PDP3_LDW */,      0,
146b8e80941Smrg                             0x1C284 /* PDP2_UDW */,      0,
147b8e80941Smrg                             0x1C280 /* PDP2_LDW */,      0,
148b8e80941Smrg                             0x1C27C /* PDP1_UDW */,      0,
149b8e80941Smrg                             0x1C278 /* PDP1_LDW */,      0,
150b8e80941Smrg                             0x1C274 /* PDP0_UDW */,      params->pml4_addr >> 32,
151b8e80941Smrg                             0x1C270 /* PDP0_LDW */,      params->pml4_addr & 0xffffffff);
152b8e80941Smrg   for (int i = 0; i < 12; i++)
153b8e80941Smrg      *data++ = 0 /* MI_NOOP */;
154b8e80941Smrg
155b8e80941Smrg   *data++ = MI_BATCH_BUFFER_END;
156b8e80941Smrg}
157b8e80941Smrg
158b8e80941Smrg#endif /* GEN8_CONTEXT_H */
159