Fix cross compilation (e.g. on Darwin). Following changes to make.tmpl,
[AROS.git] / arch / all-pc / boot / grub2-aros / include / grub / pci.h
blob70d9a05131b240bbe3c7fe12df899c8e3de237ce
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2008,2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef GRUB_PCI_H
20 #define GRUB_PCI_H 1
22 #ifndef ASM_FILE
23 #include <grub/types.h>
24 #include <grub/symbol.h>
25 #endif
27 #define GRUB_PCI_ADDR_SPACE_MASK 0x01
28 #define GRUB_PCI_ADDR_SPACE_MEMORY 0x00
29 #define GRUB_PCI_ADDR_SPACE_IO 0x01
31 #define GRUB_PCI_ADDR_MEM_TYPE_MASK 0x06
32 #define GRUB_PCI_ADDR_MEM_TYPE_32 0x00 /* 32 bit address */
33 #define GRUB_PCI_ADDR_MEM_TYPE_1M 0x02 /* Below 1M [obsolete] */
34 #define GRUB_PCI_ADDR_MEM_TYPE_64 0x04 /* 64 bit address */
35 #define GRUB_PCI_ADDR_MEM_PREFETCH 0x08 /* prefetchable */
37 #define GRUB_PCI_ADDR_MEM_MASK ~0xf
38 #define GRUB_PCI_ADDR_IO_MASK ~0x03
40 #define GRUB_PCI_REG_PCI_ID 0x00
41 #define GRUB_PCI_REG_VENDOR 0x00
42 #define GRUB_PCI_REG_DEVICE 0x02
43 #define GRUB_PCI_REG_COMMAND 0x04
44 #define GRUB_PCI_REG_STATUS 0x06
45 #define GRUB_PCI_REG_REVISION 0x08
46 #define GRUB_PCI_REG_CLASS 0x08
47 #define GRUB_PCI_REG_CACHELINE 0x0c
48 #define GRUB_PCI_REG_LAT_TIMER 0x0d
49 #define GRUB_PCI_REG_HEADER_TYPE 0x0e
50 #define GRUB_PCI_REG_BIST 0x0f
51 #define GRUB_PCI_REG_ADDRESSES 0x10
53 /* Beware that 64-bit address takes 2 registers. */
54 #define GRUB_PCI_REG_ADDRESS_REG0 0x10
55 #define GRUB_PCI_REG_ADDRESS_REG1 0x14
56 #define GRUB_PCI_REG_ADDRESS_REG2 0x18
57 #define GRUB_PCI_REG_ADDRESS_REG3 0x1c
58 #define GRUB_PCI_REG_ADDRESS_REG4 0x20
59 #define GRUB_PCI_REG_ADDRESS_REG5 0x24
61 #define GRUB_PCI_REG_CIS_POINTER 0x28
62 #define GRUB_PCI_REG_SUBVENDOR 0x2c
63 #define GRUB_PCI_REG_SUBSYSTEM 0x2e
64 #define GRUB_PCI_REG_ROM_ADDRESS 0x30
65 #define GRUB_PCI_REG_CAP_POINTER 0x34
66 #define GRUB_PCI_REG_IRQ_LINE 0x3c
67 #define GRUB_PCI_REG_IRQ_PIN 0x3d
68 #define GRUB_PCI_REG_MIN_GNT 0x3e
69 #define GRUB_PCI_REG_MAX_LAT 0x3f
71 #define GRUB_PCI_COMMAND_IO_ENABLED 0x0001
72 #define GRUB_PCI_COMMAND_MEM_ENABLED 0x0002
73 #define GRUB_PCI_COMMAND_BUS_MASTER 0x0004
74 #define GRUB_PCI_COMMAND_PARITY_ERROR 0x0040
75 #define GRUB_PCI_COMMAND_SERR_ENABLE 0x0100
77 #define GRUB_PCI_STATUS_CAPABILITIES 0x0010
78 #define GRUB_PCI_STATUS_66MHZ_CAPABLE 0x0020
79 #define GRUB_PCI_STATUS_FAST_B2B_CAPABLE 0x0080
81 #define GRUB_PCI_STATUS_DEVSEL_TIMING_SHIFT 9
82 #define GRUB_PCI_STATUS_DEVSEL_TIMING_MASK 0x0600
83 #define GRUB_PCI_CLASS_SUBCLASS_VGA 0x0300
84 #define GRUB_PCI_CLASS_SUBCLASS_USB 0x0c03
86 #ifndef ASM_FILE
88 enum
90 GRUB_PCI_CLASS_NETWORK = 0x02
92 enum
94 GRUB_PCI_CAP_POWER_MANAGEMENT = 0x01
97 enum
99 GRUB_PCI_VENDOR_BROADCOM = 0x14e4
103 typedef grub_uint32_t grub_pci_id_t;
105 #ifdef GRUB_MACHINE_EMU
106 #include <grub/pciutils.h>
107 #else
108 typedef grub_uint32_t grub_pci_address_t;
109 struct grub_pci_device
111 int bus;
112 int device;
113 int function;
115 typedef struct grub_pci_device grub_pci_device_t;
116 static inline int
117 grub_pci_get_bus (grub_pci_device_t dev)
119 return dev.bus;
122 static inline int
123 grub_pci_get_device (grub_pci_device_t dev)
125 return dev.device;
128 static inline int
129 grub_pci_get_function (grub_pci_device_t dev)
131 return dev.function;
133 #include <grub/cpu/pci.h>
134 #endif
136 typedef int (*grub_pci_iteratefunc_t)
137 (grub_pci_device_t dev, grub_pci_id_t pciid, void *data);
139 grub_pci_address_t EXPORT_FUNC(grub_pci_make_address) (grub_pci_device_t dev,
140 int reg);
142 void EXPORT_FUNC(grub_pci_iterate) (grub_pci_iteratefunc_t hook,
143 void *hook_data);
145 struct grub_pci_dma_chunk;
147 struct grub_pci_dma_chunk *EXPORT_FUNC(grub_memalign_dma32) (grub_size_t align,
148 grub_size_t size);
149 void EXPORT_FUNC(grub_dma_free) (struct grub_pci_dma_chunk *ch);
150 volatile void *EXPORT_FUNC(grub_dma_get_virt) (struct grub_pci_dma_chunk *ch);
151 grub_uint32_t EXPORT_FUNC(grub_dma_get_phys) (struct grub_pci_dma_chunk *ch);
153 static inline void *
154 grub_dma_phys2virt (grub_uint32_t phys, struct grub_pci_dma_chunk *chunk)
156 return ((grub_uint8_t *) grub_dma_get_virt (chunk)
157 + (phys - grub_dma_get_phys (chunk)));
160 static inline grub_uint32_t
161 grub_dma_virt2phys (volatile void *virt, struct grub_pci_dma_chunk *chunk)
163 return (((grub_uint8_t *) virt - (grub_uint8_t *) grub_dma_get_virt (chunk))
164 + grub_dma_get_phys (chunk));
167 grub_uint8_t
168 EXPORT_FUNC (grub_pci_find_capability) (grub_pci_device_t dev, grub_uint8_t cap);
170 #endif
172 #endif /* GRUB_PCI_H */