Debian Codegraph @

src/soc/intel/common/block/systemagent-server/common.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #define __SIMPLE_DEVICE__
4
5 #include <device/pci_ops.h>
6 #include <intelblocks/systemagent_server.h>
7
8 static uint32_t pci_moving_config32(pci_devfn_t dev, unsigned int reg)
9 {
10 uint32_t value, ones, zeroes;
11
12 value = pci_read_config32(dev, reg);
13
14 pci_write_config32(dev, reg, 0xffffffff);
15 ones = pci_read_config32(dev, reg);
16
17 pci_write_config32(dev, reg, 0x00000000);
18 zeroes = pci_read_config32(dev, reg);
19
20 pci_write_config32(dev, reg, value);
21
22 return ones ^ zeroes;
23 }
24
25 uint64_t sa_server_read_map_entry(pci_devfn_t dev,
26 const struct sa_server_mem_map_descriptor *entry)
27 {
28 uint64_t value = 0;
29 uint32_t alignment = entry->alignment;
30
31 if (entry->is_64_bit) {
32 value = pci_s_read_config32(dev, entry->reg_offset + 4);
33 value <<= 32;
34 }
35
36 value |= pci_s_read_config32(dev, entry->reg_offset);
37
38 /**
39 * Probe the alignment if not provided, promising the lower bits are read only, otherwise
40 * SoC should give a initial value.
41 */
42 if (!alignment)
43 alignment = ~pci_moving_config32(dev, entry->reg_offset) + 1;
44
45 /**
46 * If register stores the limit address, where lower bits are read as 0s but treated as 1s,
47 * restore the lower bits and align it up.
48 */
49 if (entry->is_limit)
50 value = ALIGN_UP(value + alignment - 1, alignment);
51 else
52 value = ALIGN_DOWN(value, alignment);
53
54 return value;
55 }