2 * This file is part of the coreboot project.
4 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #ifndef _ASPEED_COREBOOT_
18 #define _ASPEED_COREBOOT_
26 #include <console/console.h>
27 #include <device/device.h>
28 #include <device/pci.h>
29 #include <device/pci_ids.h>
30 #include <device/pci_ops.h>
32 /* coreboot <--> kernel code interface */
34 typedef u64 phys_addr_t
;
35 #define pci_dev device
37 #define SZ_16M 0x01000000
39 #define min_t(type, x, y) ({ \
42 __min1 < __min2 ? __min1 : __min2; })
44 #define dev_info(dev, format, arg...) printk(BIOS_INFO, "%s: " format, __func__, ##arg)
45 #define dev_dbg(dev, format, arg...) printk(BIOS_DEBUG, "%s: " format, __func__, ##arg)
46 #define dev_err(dev, format, arg...) printk(BIOS_ERR, "%s: " format, __func__, ##arg)
48 #define pr_info(format, arg...) printk(BIOS_INFO, "%s: " format, __func__, ##arg)
49 #define pr_debug(format, arg...) printk(BIOS_INFO, "%s: " format, __func__, ##arg)
50 #define pr_err(format, arg...) printk(BIOS_ERR, "%s: " format, __func__, ##arg)
52 #define DRM_INFO pr_info
56 #define kfree(address) free(address)
66 /* firmware loader private fields */
75 static inline void *kzalloc(size_t size
, int flags
) {
76 void* ptr
= malloc(size
);
81 static inline void writel(u32 val
, volatile void *addr
) {
85 static inline u32
readl(const volatile void *addr
) {
89 static inline void writew(u16 val
, volatile void *addr
) {
93 static inline u16
readw(const volatile void *addr
) {
97 static inline void writeb(u8 val
, volatile void *addr
) {
101 static inline u8
readb(const volatile void *addr
) {
105 static inline int pci_read_config_dword(struct pci_dev
*dev
, int where
,
108 *val
= pci_read_config32(dev
, where
);
112 static inline int pci_write_config_dword(struct pci_dev
*dev
, int where
,
115 pci_write_config32(dev
, where
, val
);
119 static inline int pci_read_config_byte(struct pci_dev
*dev
, int where
,
122 *val
= pci_read_config8(dev
, where
);
126 static inline struct resource
* resource_at_bar(struct pci_dev
*dev
, u8 bar
) {
127 struct resource
*res
= dev
->resource_list
;
129 for (i
= 0; i
< bar
; i
++) {
138 static inline resource_t
pci_resource_len(struct pci_dev
*dev
, u8 bar
) {
139 struct resource
*res
= resource_at_bar(dev
, bar
);
146 static inline resource_t
pci_resource_start(struct pci_dev
*dev
, u8 bar
) {
147 struct resource
*res
= resource_at_bar(dev
, bar
);
154 static inline unsigned int ioread32(void __iomem
*p
) {
158 static inline void iowrite32(u32 val
, void __iomem
*p
) {
162 static inline unsigned int ioread16(void __iomem
*p
) {
166 static inline void iowrite16(u16 val
, void __iomem
*p
) {
170 static inline unsigned int ioread8(void __iomem
*p
) {
174 static inline void iowrite8(u8 val
, void __iomem
*p
) {
178 static inline unsigned int ioread_cbio32(void __iomem
*p
) {
179 return inl((uint16_t)((intptr_t)p
));
182 static inline void iowrite_cbio32(u32 val
, void __iomem
*p
) {
183 outl(val
, (uint16_t)((intptr_t)p
));
186 static inline unsigned int ioread_cbio16(void __iomem
*p
) {
187 return inw((uint16_t)((intptr_t)p
));
190 static inline void iowrite_cbio16(u16 val
, void __iomem
*p
) {
191 outw(val
, (uint16_t)((intptr_t)p
));
194 static inline unsigned int ioread_cbio8(void __iomem
*p
) {
195 return inb((uint16_t)((intptr_t)p
));
198 static inline void iowrite_cbio8(u8 val
, void __iomem
*p
) {
199 outb(val
, (uint16_t)((intptr_t)p
));
202 static inline void msleep(unsigned int msecs
) {
203 udelay(msecs
* 1000);