1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #ifndef _ASPEED_COREBOOT_
4 #define _ASPEED_COREBOOT_
11 #include <device/mmio.h>
13 #include <console/console.h>
14 #include <device/device.h>
15 #include <device/pci.h>
16 #include <device/pci_ops.h>
18 /* coreboot <--> kernel code interface */
20 typedef u64 phys_addr_t
;
21 #define pci_dev device
23 #define SZ_16M 0x01000000
25 #define min_t(type, x, y) ({ \
28 __min1 < __min2 ? __min1 : __min2; })
30 #define dev_info(dev, format, arg...) printk(BIOS_INFO, "%s: " format, __func__, ##arg)
31 #define dev_dbg(dev, format, arg...) printk(BIOS_DEBUG, "%s: " format, __func__, ##arg)
32 #define dev_err(dev, format, arg...) printk(BIOS_ERR, "%s: " format, __func__, ##arg)
34 #define pr_info(format, arg...) printk(BIOS_INFO, "%s: " format, __func__, ##arg)
35 #define pr_debug(format, arg...) printk(BIOS_INFO, "%s: " format, __func__, ##arg)
36 #define pr_err(format, arg...) printk(BIOS_ERR, "%s: " format, __func__, ##arg)
38 #define DRM_INFO pr_info
42 #define kfree(address) free(address)
52 /* firmware loader private fields */
61 static inline void *kzalloc(size_t size
, int flags
) {
62 void *ptr
= malloc(size
);
67 static inline int pci_read_config_dword(struct pci_dev
*dev
, int where
,
70 *val
= pci_read_config32(dev
, where
);
74 static inline int pci_write_config_dword(struct pci_dev
*dev
, int where
,
77 pci_write_config32(dev
, where
, val
);
81 static inline int pci_read_config_byte(struct pci_dev
*dev
, int where
,
84 *val
= pci_read_config8(dev
, where
);
88 static inline struct resource
* resource_at_bar(struct pci_dev
*dev
, u8 bar
) {
89 struct resource
*res
= dev
->resource_list
;
91 for (i
= 0; i
< bar
; i
++) {
100 static inline resource_t
pci_resource_len(struct pci_dev
*dev
, u8 bar
) {
101 struct resource
*res
= resource_at_bar(dev
, bar
);
108 static inline resource_t
pci_resource_start(struct pci_dev
*dev
, u8 bar
) {
109 struct resource
*res
= resource_at_bar(dev
, bar
);
116 static inline unsigned int ioread32(void __iomem
*p
) {
120 static inline void iowrite32(u32 val
, void __iomem
*p
) {
124 static inline unsigned int ioread16(void __iomem
*p
) {
128 static inline void iowrite16(u16 val
, void __iomem
*p
) {
132 static inline unsigned int ioread8(void __iomem
*p
) {
136 static inline void iowrite8(u8 val
, void __iomem
*p
) {
140 static inline unsigned int ioread_cbio32(void __iomem
*p
) {
141 return inl((uint16_t)((intptr_t)p
));
144 static inline void iowrite_cbio32(u32 val
, void __iomem
*p
) {
145 outl(val
, (uint16_t)((intptr_t)p
));
148 static inline unsigned int ioread_cbio16(void __iomem
*p
) {
149 return inw((uint16_t)((intptr_t)p
));
152 static inline void iowrite_cbio16(u16 val
, void __iomem
*p
) {
153 outw(val
, (uint16_t)((intptr_t)p
));
156 static inline unsigned int ioread_cbio8(void __iomem
*p
) {
157 return inb((uint16_t)((intptr_t)p
));
160 static inline void iowrite_cbio8(u8 val
, void __iomem
*p
) {
161 outb(val
, (uint16_t)((intptr_t)p
));
164 static inline void msleep(unsigned int msecs
) {
165 udelay(msecs
* 1000);