tree: drop last paragraph of GPL copyright header
[coreboot.git] / src / drivers / aspeed / common / aspeed_coreboot.h
blob828bd122f7e1ba5e1f15f7424a42211cabe0d387
1 /*
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_
20 #include <delay.h>
21 #include <stdlib.h>
22 #include <stdint.h>
23 #include <string.h>
24 #include <arch/io.h>
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 */
33 #define __iomem
34 typedef u64 phys_addr_t;
35 #define pci_dev device
37 #define SZ_16M 0x01000000
39 #define min_t(type, x, y) ({ \
40 type __min1 = (x); \
41 type __min2 = (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
54 #define GFP_KERNEL 0
55 #define GFP_ATOMIC 1
56 #define kfree(address) free(address)
58 #define EIO 5
59 #define ENOMEM 12
61 struct firmware {
62 size_t size;
63 const u8 *data;
64 struct page **pages;
66 /* firmware loader private fields */
67 void *priv;
70 struct drm_device {
71 struct pci_dev *pdev;
72 void *dev_private;
75 static inline void *kzalloc(size_t size, int flags) {
76 void* ptr = malloc(size);
77 memset(ptr, 0, size);
78 return ptr;
81 static inline void writel(u32 val, volatile void *addr) {
82 *(u32*)addr = val;
85 static inline u32 readl(const volatile void *addr) {
86 return *(u32*)addr;
89 static inline void writew(u16 val, volatile void *addr) {
90 *(u16*)addr = val;
93 static inline u16 readw(const volatile void *addr) {
94 return *(u16*)addr;
97 static inline void writeb(u8 val, volatile void *addr) {
98 *(u8*)addr = val;
101 static inline u8 readb(const volatile void *addr) {
102 return *(u8*)addr;
105 static inline int pci_read_config_dword(struct pci_dev *dev, int where,
106 u32 *val)
108 *val = pci_read_config32(dev, where);
109 return 0;
112 static inline int pci_write_config_dword(struct pci_dev *dev, int where,
113 u32 val)
115 pci_write_config32(dev, where, val);
116 return 0;
119 static inline int pci_read_config_byte(struct pci_dev *dev, int where,
120 u8 *val)
122 *val = pci_read_config8(dev, where);
123 return 0;
126 static inline struct resource* resource_at_bar(struct pci_dev *dev, u8 bar) {
127 struct resource *res = dev->resource_list;
128 int i;
129 for (i = 0; i < bar; i++) {
130 res = res->next;
131 if (res == NULL)
132 return NULL;
135 return res;
138 static inline resource_t pci_resource_len(struct pci_dev *dev, u8 bar) {
139 struct resource *res = resource_at_bar(dev, bar);
140 if (res)
141 return res->size;
142 else
143 return 0;
146 static inline resource_t pci_resource_start(struct pci_dev *dev, u8 bar) {
147 struct resource *res = resource_at_bar(dev, bar);
148 if (res)
149 return res->base;
150 else
151 return 0;
154 static inline unsigned int ioread32(void __iomem *p) {
155 return readl(p);
158 static inline void iowrite32(u32 val, void __iomem *p) {
159 writel(val, p);
162 static inline unsigned int ioread16(void __iomem *p) {
163 return readw(p);
166 static inline void iowrite16(u16 val, void __iomem *p) {
167 writew(val, p);
170 static inline unsigned int ioread8(void __iomem *p) {
171 return readb(p);
174 static inline void iowrite8(u8 val, void __iomem *p) {
175 writeb(val, 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);
206 #endif