1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <device/mmio.h>
5 #include <device/pci_ops.h>
6 #include <device/pci.h>
7 #include <device/device.h>
10 #include <soc/soc_util.h>
12 #include <soc/smbus.h>
14 #include <soc/pci_devs.h>
15 #include <soc/systemagent.h>
17 #ifdef __SIMPLE_DEVICE__
18 pci_devfn_t
get_hostbridge_dev(void)
20 return PCI_DEV(0, SA_DEV
, SA_FUNC
);
23 struct device
*get_hostbridge_dev(void)
25 return pcidev_on_root(SA_DEV
, SA_FUNC
);
29 #ifdef __SIMPLE_DEVICE__
30 pci_devfn_t
get_lpc_dev(void)
32 return PCI_DEV(0, LPC_DEV
, LPC_FUNC
);
35 struct device
*get_lpc_dev(void)
37 return pcidev_on_root(LPC_DEV
, LPC_FUNC
);
41 #ifdef __SIMPLE_DEVICE__
42 pci_devfn_t
get_pmc_dev(void)
44 return PCI_DEV(0, PMC_DEV
, PMC_FUNC
);
47 struct device
*get_pmc_dev(void)
49 return pcidev_on_root(PMC_DEV
, PMC_FUNC
);
53 #ifdef __SIMPLE_DEVICE__
54 pci_devfn_t
get_smbus_dev(void)
56 return PCI_DEV(0, SMBUS_DEV
, SMBUS_FUNC
);
59 struct device
*get_smbus_dev(void)
61 return pcidev_on_root(SMBUS_DEV
, SMBUS_FUNC
);
65 uint32_t get_pciebase(void)
67 #ifdef __SIMPLE_DEVICE__
74 dev
= get_hostbridge_dev();
78 pciexbar_reg
= pci_read_config32(dev
, PCIEXBAR
);
80 if (!(pciexbar_reg
& (1 << 0)))
83 switch (pciexbar_reg
& MASK_PCIEXBAR_LENGTH
) {
84 case MASK_PCIEXBAR_LENGTH_256M
:
85 pciexbar_reg
&= MASK_PCIEXBAR_256M
;
87 case MASK_PCIEXBAR_LENGTH_128M
:
88 pciexbar_reg
&= MASK_PCIEXBAR_128M
;
90 case MASK_PCIEXBAR_LENGTH_64M
:
91 pciexbar_reg
&= MASK_PCIEXBAR_64M
;
94 pciexbar_reg
&= MASK_PCIEXBAR_256M
;
101 uint32_t get_pcielength(void)
103 #ifdef __SIMPLE_DEVICE__
110 dev
= get_hostbridge_dev();
114 pciexbar_reg
= pci_read_config32(dev
, PCIEXBAR
);
116 if (!(pciexbar_reg
& (1 << 0)))
119 switch (pciexbar_reg
& MASK_PCIEXBAR_LENGTH
) {
120 case MASK_PCIEXBAR_LENGTH_256M
:
123 case MASK_PCIEXBAR_LENGTH_128M
:
126 case MASK_PCIEXBAR_LENGTH_64M
:
137 uint32_t get_tseg_memory(void)
139 #ifdef __SIMPLE_DEVICE__
144 dev
= get_hostbridge_dev();
149 return pci_read_config32(dev
, TSEGMB
) & MASK_TSEGMB
;
152 uint32_t get_top_of_low_memory(void)
154 #ifdef __SIMPLE_DEVICE__
159 dev
= get_hostbridge_dev();
164 return pci_read_config32(dev
, TOLUD
) & MASK_TOLUD
;
167 uint64_t get_top_of_upper_memory(void)
169 #ifdef __SIMPLE_DEVICE__
174 dev
= get_hostbridge_dev();
179 return ((uint64_t)(pci_read_config32(dev
, TOUUD_HI
) & MASK_TOUUD_HI
)
181 (uint64_t)(pci_read_config32(dev
, TOUUD_LO
) & MASK_TOUUD_LO
);
184 uint16_t get_pmbase(void)
186 #ifdef __SIMPLE_DEVICE__
196 return pci_read_config16(dev
, PMC_ACPI_BASE
) & 0xfff8;
199 uint16_t get_tcobase(void)
201 #ifdef __SIMPLE_DEVICE__
206 dev
= get_smbus_dev();
211 return pci_read_config16(dev
, TCOBASE
) & MASK_TCOBASE
;
214 void mmio_andthenor32(void *addr
, uint32_t val2and
, uint32_t val2or
)
218 reg32
= read32(addr
);
219 reg32
&= (uint32_t)val2and
;
220 reg32
|= (uint32_t)val2or
;
221 write32(addr
, reg32
);
224 uint8_t silicon_stepping(void)
227 #ifdef __SIMPLE_DEVICE__
237 revision_id
= pci_read_config8(dev
, PCI_REVISION_ID
);
242 void *memcpy_s(void *dest
, const void *src
, size_t n
)
247 dp
= (uint8_t *)dest
;
263 * overlap is undefined behavior, do not allow
265 if (((dp
> sp
) && (dp
< (sp
+ n
))) || ((sp
> dp
) && (sp
< (dp
+ n
))))
269 * now perform the copy
272 /* Original memcpy() function */
273 unsigned long d0
, d1
, d2
;
284 : "=&c"(d0
), "=&D"(d1
), "=&S"(d2
)
285 : "0"(n
>> 2), "g"(n
& 3), "1"(dest
), "2"(src
)