38#ifndef __PCI_ACCESS_H__
39#define __PCI_ACCESS_H__
42#include <libcpu/byteorder.h>
51typedef uint16_t pci_dev_t;
53#define PCI_DEV(bus, slot, func) (((bus)<<8) | ((slot)<<3) | (func))
55#define PCI_DEV_BUS(dev) (((dev) >> 8) & 0xff)
57#define PCI_DEV_SLOT(dev) (((dev) >> 3) & 0x1f)
59#define PCI_DEV_FUNC(dev) ((dev) & 0x7)
61#define PCI_DEV_DEVFUNC(dev) ((dev) & 0xff)
63#define PCI_DEV_EXPAND(dev) PCI_DEV_BUS((dev)), PCI_DEV_SLOT((dev)), PCI_DEV_FUNC((dev))
68 int (*read8)(pci_dev_t dev,
int ofs, uint8_t *data);
69 int (*read16)(pci_dev_t dev,
int ofs, uint16_t *data);
70 int (*read32)(pci_dev_t dev,
int ofs, uint32_t *data);
71 int (*write8)(pci_dev_t dev,
int ofs, uint8_t data);
72 int (*write16)(pci_dev_t dev,
int ofs, uint16_t data);
73 int (*write32)(pci_dev_t dev,
int ofs, uint32_t data);
80 uint8_t (*read8)(uint8_t *adr);
81 uint16_t(*read16)(uint16_t *adr);
82 uint32_t (*read32)(uint32_t *adr);
83 void (*write8)(uint8_t *adr, uint8_t data);
84 void (*write16)(uint16_t *adr, uint16_t data);
85 void (*write32)(uint32_t *adr, uint32_t data);
92 uint8_t (*ld8)(uint8_t *adr);
93 void (*st8)(uint8_t *adr, uint8_t data);
95 uint16_t(*ld_le16)(uint16_t *adr);
96 void (*st_le16)(uint16_t *adr, uint16_t data);
97 uint16_t(*ld_be16)(uint16_t *adr);
98 void (*st_be16)(uint16_t *adr, uint16_t data);
100 uint32_t (*ld_le32)(uint32_t *adr);
101 void (*st_le32)(uint32_t *adr, uint32_t data);
102 uint32_t (*ld_be32)(uint32_t *adr);
103 void (*st_be32)(uint32_t *adr, uint32_t data);
106typedef uint8_t (*pci_ld8_t)(uint8_t *adr);
107typedef void (*pci_st8_t)(uint8_t *adr, uint8_t data);
108typedef uint16_t(pci_ld16_t)(uint16_t *adr);
109typedef void (*pci_st16_t)(uint16_t *adr, uint16_t data);
110typedef uint32_t (*pci_ld32_t)(uint32_t *adr);
111typedef void (*pci_st32_t)(uint32_t *adr, uint32_t data);
143 int (*translate)(uint32_t *address,
int type,
int dir);
153extern void pci_modify_cmdsts(pci_dev_t dev, uint32_t mask, uint32_t val);
156static inline void pci_mem_enable(pci_dev_t dev)
158 pci_modify_cmdsts(dev, PCIM_CMD_MEMEN, PCIM_CMD_MEMEN);
161static inline void pci_mem_disable(pci_dev_t dev)
163 pci_modify_cmdsts(dev, PCIM_CMD_MEMEN, 0);
166static inline void pci_io_enable(pci_dev_t dev)
168 pci_modify_cmdsts(dev, PCIM_CMD_PORTEN, PCIM_CMD_PORTEN);
171static inline void pci_io_disable(pci_dev_t dev)
173 pci_modify_cmdsts(dev, PCIM_CMD_PORTEN, 0);
176static inline void pci_master_enable(pci_dev_t dev)
178 pci_modify_cmdsts(dev, PCIM_CMD_BUSMASTEREN, PCIM_CMD_BUSMASTEREN);
181static inline void pci_master_disable(pci_dev_t dev)
183 pci_modify_cmdsts(dev, PCIM_CMD_BUSMASTEREN, 0);
187extern int pci_cfg_r8(pci_dev_t dev,
int ofs, uint8_t *data);
188extern int pci_cfg_r16(pci_dev_t dev,
int ofs, uint16_t *data);
189extern int pci_cfg_r32(pci_dev_t dev,
int ofs, uint32_t *data);
192extern int pci_cfg_w8(pci_dev_t dev,
int ofs, uint8_t data);
193extern int pci_cfg_w16(pci_dev_t dev,
int ofs, uint16_t data);
194extern int pci_cfg_w32(pci_dev_t dev,
int ofs, uint32_t data);
197extern uint8_t pci_io_r8(uint32_t adr);
198extern uint16_t pci_io_r16(uint32_t adr);
199extern uint32_t pci_io_r32(uint32_t adr);
202extern void pci_io_w8(uint32_t adr, uint8_t data);
203extern void pci_io_w16(uint32_t adr, uint16_t data);
204extern void pci_io_w32(uint32_t adr, uint32_t data);
207static inline int pci_pci2cpu(uint32_t *address,
int type)
209 return pci_access_ops.translate(address, type, 0);
213static inline int pci_cpu2pci(uint32_t *address,
int type)
215 return pci_access_ops.translate(address, type, 1);
220static inline uint8_t pci_ld8(
volatile uint8_t *addr)
225static inline void pci_st8(
volatile uint8_t *addr, uint8_t val)
237uint8_t pci_mem_ld8(uint8_t *adr);
238void pci_mem_st8(uint8_t *adr, uint8_t data);
240uint16_t pci_mem_be_ld_le16(uint16_t *adr);
241uint16_t pci_mem_be_ld_be16(uint16_t *adr);
242uint32_t pci_mem_be_ld_le32(uint32_t *adr);
243uint32_t pci_mem_be_ld_be32(uint32_t *adr);
244void pci_mem_be_st_le16(uint16_t *adr, uint16_t data);
245void pci_mem_be_st_be16(uint16_t *adr, uint16_t data);
246void pci_mem_be_st_le32(uint32_t *adr, uint32_t data);
247void pci_mem_be_st_be32(uint32_t *adr, uint32_t data);
249uint16_t pci_mem_le_ld_le16(uint16_t *adr);
250uint16_t pci_mem_le_ld_be16(uint16_t *adr);
251uint32_t pci_mem_le_ld_le32(uint32_t *adr);
252uint32_t pci_mem_le_ld_be32(uint32_t *adr);
253void pci_mem_le_st_le16(uint16_t *adr, uint16_t data);
254void pci_mem_le_st_be16(uint16_t *adr, uint16_t data);
255void pci_mem_le_st_le32(uint32_t *adr, uint32_t data);
256void pci_mem_le_st_be32(uint32_t *adr, uint32_t data);
272extern int pci_access_func(
int wr,
int size,
void **func,
int endian,
int type);
This header file provides basic definitions used by the API and the implementation.
unsigned size
Definition: tte.h:1