summaryrefslogtreecommitdiff
path: root/src/drivers/aspeed/common/aspeed_coreboot.h
blob: 3f740b21c4f425d5a9833d36b5b8a24399f6e2cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* SPDX-License-Identifier: GPL-2.0-or-later */

#ifndef _ASPEED_COREBOOT_
#define _ASPEED_COREBOOT_

#include <delay.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <arch/io.h>
#include <device/mmio.h>

#include <console/console.h>
#include <device/device.h>
#include <device/pci.h>
#include <device/pci_ops.h>

/* coreboot <--> kernel code interface */
#define __iomem
typedef u64 phys_addr_t;
#define pci_dev device

#define SZ_16M 0x01000000

#define min_t(type, x, y) ({			\
	type __min1 = (x);			\
	type __min2 = (y);			\
	__min1 < __min2 ? __min1 : __min2; })

#define dev_info(dev, format, arg...) printk(BIOS_INFO, "%s: " format, __func__, ##arg)
#define dev_dbg(dev, format, arg...) printk(BIOS_DEBUG, "%s: " format, __func__, ##arg)
#define dev_err(dev, format, arg...) printk(BIOS_ERR, "%s: " format, __func__, ##arg)

#define pr_info(format, arg...) printk(BIOS_INFO, "%s: " format, __func__, ##arg)
#define pr_debug(format, arg...) printk(BIOS_INFO, "%s: " format, __func__, ##arg)
#define pr_err(format, arg...) printk(BIOS_ERR, "%s: " format, __func__, ##arg)

#define DRM_INFO pr_info

#define GFP_KERNEL 0
#define GFP_ATOMIC 1
#define kfree(address) free(address)

#define EIO 5
#define ENOMEM 12

struct firmware {
	size_t size;
	const u8 *data;
	struct page **pages;

	/* firmware loader private fields */
	void *priv;
};

struct drm_device {
	struct pci_dev *pdev;
	void *dev_private;
};

static inline void *kzalloc(size_t size, int flags) {
	void *ptr = malloc(size);
	memset(ptr, 0, size);
	return ptr;
}

static inline int pci_read_config_dword(struct pci_dev *dev, int where,
	u32 *val)
{
	*val = pci_read_config32(dev, where);
	return 0;
}

static inline int pci_write_config_dword(struct pci_dev *dev, int where,
	u32 val)
{
	pci_write_config32(dev, where, val);
	return 0;
}

static inline int pci_read_config_byte(struct pci_dev *dev, int where,
	u8 *val)
{
	*val = pci_read_config8(dev, where);
	return 0;
}

static inline struct resource* resource_at_bar(struct pci_dev *dev, u8 bar) {
	struct resource *res = dev->resource_list;
	int i;
	for (i = 0; i < bar; i++) {
		res = res->next;
		if (res == NULL)
			return NULL;
	}

	return res;
}

static inline resource_t pci_resource_len(struct pci_dev *dev, u8 bar) {
	struct resource *res = resource_at_bar(dev, bar);
	if (res)
		return res->size;
	else
		return 0;
}

static inline resource_t pci_resource_start(struct pci_dev *dev, u8 bar) {
	struct resource *res = resource_at_bar(dev, bar);
	if (res)
		return res->base;
	else
		return 0;
}

static inline unsigned int ioread32(void __iomem *p) {
	return read32(p);
}

static inline void iowrite32(u32 val, void __iomem *p) {
	write32(p, val);
}

static inline unsigned int ioread16(void __iomem *p) {
	return read16(p);
}

static inline void iowrite16(u16 val, void __iomem *p) {
	write16(p, val);
}

static inline unsigned int ioread8(void __iomem *p) {
	return read8(p);
}

static inline void iowrite8(u8 val, void __iomem *p) {
	write8(p, val);
}

static inline unsigned int ioread_cbio32(void __iomem *p) {
	return inl((uint16_t)((intptr_t)p));
}

static inline void iowrite_cbio32(u32 val, void __iomem *p) {
	outl(val, (uint16_t)((intptr_t)p));
}

static inline unsigned int ioread_cbio16(void __iomem *p) {
	return inw((uint16_t)((intptr_t)p));
}

static inline void iowrite_cbio16(u16 val, void __iomem *p) {
	outw(val, (uint16_t)((intptr_t)p));
}

static inline unsigned int ioread_cbio8(void __iomem *p) {
	return inb((uint16_t)((intptr_t)p));
}

static inline void iowrite_cbio8(u8 val, void __iomem *p) {
	outb(val, (uint16_t)((intptr_t)p));
}

static inline void msleep(unsigned int msecs) {
	udelay(msecs * 1000);
}

#endif