Debian Codegraph @

src/soc/intel/apollolake/loader.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <assert.h>
4 #include <console/console.h>
5 #include <cpu/x86/cache.h>
6 #include <device/pci_ids.h>
7 #include <device/pci_ops.h>
8 #include <soc/cpu.h>
9 #include <soc/iomap.h>
10 #include <soc/loader.h>
11 #include <soc/pci_devs.h>
12 #include <string.h>
13 #include <symbols.h>
14
15 static void flush_cache(uintptr_t start, uintptr_t size)
16 {
17 uintptr_t end;
18 uintptr_t addr;
19
20 end = start + (ALIGN_UP(size, 4096));
21 for (addr = start; addr < end; addr += 64)
22 clflush((void *)addr);
23 }
24
25 /*
26 * This function is intentionally comment heavy, as the documentation for
27 * APL and GLK is almost non-existant.
28 */
29
30 bool load_ibb(uint32_t ibb_dest, uint32_t ibb_size)
31 {
32 uint32_t host_to_cse = (ibb_size << 4) | 0xc0000000;
33 uint32_t cse_to_host;
34 uint32_t state;
35 uint8_t ring_index;
36
37 uint32_t chunk_num;
38 uint32_t chunk_index = 0;
39 uint32_t chunk_size;
40 uint32_t number_of_chunks;
41 uint32_t ibb_size_left;
42
43 uint8_t *dst;
44 uint8_t *src;
45 uint32_t size;
46
47 /* Check if the CSE exists */
48 if ((pci_read_config32(PCH_DEV_CSE, 0) !=
49 ((PCI_DID_INTEL_APL_CSE0 << 16) | PCI_VID_INTEL)) &&
50 (pci_read_config32(PCH_DEV_CSE, 0) !=
51 ((PCI_DID_INTEL_GLK_CSE0 << 16) | PCI_VID_INTEL)))
52 return -1;
53
54 /* Request data from CSE */
55 pci_write_config32(PCH_DEV_CSE, HOST2CSE, host_to_cse);
56
57 /* Wait for response */
58 do {
59 cse_to_host = pci_read_config32(PCH_DEV_CSE, CSE2HOST);
60 chunk_num = (cse_to_host >> 28) & 3;
61 } while (chunk_num == 0);
62
63 /*
64 * As the size of the SRAM isn't divisible by 3, we split
65 * the data into 4 equally sized chunks of 0x8000.
66 */
67 if (chunk_num == 3)
68 chunk_num = 4;
69
70 /* Retrieve related information */
71 number_of_chunks = chunk_num;
72 /* Get the size of the IBB remaining bytes */
73 ibb_size_left = (cse_to_host & 0x0fffc000) >> 4;
74 ibb_size = ibb_size_left;
75 chunk_size = SHARED_SRAM_SIZE / number_of_chunks;
76
77 /* Loading IBBM */
78 while (ibb_size_left > 0) {
79
80 /* Check whether there is ring buffer ready to copy */
81 state = (cse_to_host ^ host_to_cse) & 0x0f;
82 while (state == 0) {
83 cse_to_host = pci_read_config32(PCH_DEV_CSE, CSE2HOST);
84 state = (cse_to_host ^ host_to_cse) & 0x0f;
85 }
86
87 /* Calculate ring index */
88 ring_index = (uint8_t)(chunk_index % number_of_chunks);
89 if ((state & (1 << ring_index)) != 0) {
90 /* Calculate the source and destination address in ring buffer */
91 src = (uint8_t *)(uintptr_t)
92 (SHARED_SRAM_BASE + chunk_size * ring_index);
93 dst = (uint8_t *)(uintptr_t)
94 (ibb_dest + chunk_size * chunk_index);
95
96 if (ibb_size_left < chunk_size)
97 size = ibb_size_left;
98 else
99 size = chunk_size;
100
101 /*
102 * The RBP can handle a maximum of 0x9be2 for each copy.
103 * Whilst the above code should account for this, copying
104 * more will break serial output so we die here so the
105 * issue is known.
106 */
107 if (size > CSE_RBP_LIMIT)
108 die("CSE RBP capabilities exceeded!\n");
109
110 /* Move data from SRAM into temporary memory */
111 if ((uint32_t)src >= SHARED_SRAM_BASE)
112 flush_cache((uint32_t)(uint32_t)src, size);
113
114 memcpy(dst, src, size);
115 assert(!memcmp(dst, src, size));
116 ibb_size_left -= size;
117
118 /* Send ACK to CSE */
119 host_to_cse ^= 1 << ring_index;
120 pci_write_config32(PCH_DEV_CSE, HOST2CSE, host_to_cse);
121
122 chunk_index++;
123 }
124 }
125
126 /* Check that there are no remaining chunks */
127 do {
128 cse_to_host = pci_read_config32(PCH_DEV_CSE, CSE2HOST);
129 } while ((cse_to_host & (BIT(10))) == 0);
130
131 if ((cse_to_host & ((BIT(9)))) != 0)
132 printk(BIOS_DEBUG, "CSE RBP: IBBM loaded to CAR!\n");
133
134 /* Clear MCA in BANK4 caused by the Clflush */
135 clear_mca_bank4();
136
137 return 0;
138 }