PCI: designware-ep: Remove static keyword from dw_pcie_ep_reset_bar()
[linux-2.6-block.git] / drivers / pci / dwc / pcie-designware.h
CommitLineData
4b1ced84 1/*
96291d56 2 * Synopsys DesignWare PCIe host controller driver
4b1ced84
JH
3 *
4 * Copyright (C) 2013 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
6 *
7 * Author: Jingoo Han <jg1.han@samsung.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
18edf451
SJ
14#ifndef _PCIE_DESIGNWARE_H
15#define _PCIE_DESIGNWARE_H
16
111111a7 17#include <linux/dma-mapping.h>
feb85d9b
KVA
18#include <linux/irq.h>
19#include <linux/msi.h>
20#include <linux/pci.h>
21
f8aed6ec
KVA
22#include <linux/pci-epc.h>
23#include <linux/pci-epf.h>
24
b90dc392
KVA
25/* Parameters for the waiting for link up routine */
26#define LINK_WAIT_MAX_RETRIES 10
27#define LINK_WAIT_USLEEP_MIN 90000
28#define LINK_WAIT_USLEEP_MAX 100000
29
30/* Parameters for the waiting for iATU enabled routine */
31#define LINK_WAIT_MAX_IATU_RETRIES 5
32#define LINK_WAIT_IATU_MIN 9000
33#define LINK_WAIT_IATU_MAX 10000
34
35/* Synopsys-specific PCIe configuration registers */
36#define PCIE_PORT_LINK_CONTROL 0x710
37#define PORT_LINK_MODE_MASK (0x3f << 16)
38#define PORT_LINK_MODE_1_LANES (0x1 << 16)
39#define PORT_LINK_MODE_2_LANES (0x3 << 16)
40#define PORT_LINK_MODE_4_LANES (0x7 << 16)
41#define PORT_LINK_MODE_8_LANES (0xf << 16)
42
43#define PCIE_LINK_WIDTH_SPEED_CONTROL 0x80C
44#define PORT_LOGIC_SPEED_CHANGE (0x1 << 17)
45#define PORT_LOGIC_LINK_WIDTH_MASK (0x1f << 8)
46#define PORT_LOGIC_LINK_WIDTH_1_LANES (0x1 << 8)
47#define PORT_LOGIC_LINK_WIDTH_2_LANES (0x2 << 8)
48#define PORT_LOGIC_LINK_WIDTH_4_LANES (0x4 << 8)
49#define PORT_LOGIC_LINK_WIDTH_8_LANES (0x8 << 8)
50
51#define PCIE_MSI_ADDR_LO 0x820
52#define PCIE_MSI_ADDR_HI 0x824
53#define PCIE_MSI_INTR0_ENABLE 0x828
54#define PCIE_MSI_INTR0_MASK 0x82C
55#define PCIE_MSI_INTR0_STATUS 0x830
56
57#define PCIE_ATU_VIEWPORT 0x900
58#define PCIE_ATU_REGION_INBOUND (0x1 << 31)
59#define PCIE_ATU_REGION_OUTBOUND (0x0 << 31)
60#define PCIE_ATU_REGION_INDEX2 (0x2 << 0)
61#define PCIE_ATU_REGION_INDEX1 (0x1 << 0)
62#define PCIE_ATU_REGION_INDEX0 (0x0 << 0)
63#define PCIE_ATU_CR1 0x904
64#define PCIE_ATU_TYPE_MEM (0x0 << 0)
65#define PCIE_ATU_TYPE_IO (0x2 << 0)
66#define PCIE_ATU_TYPE_CFG0 (0x4 << 0)
67#define PCIE_ATU_TYPE_CFG1 (0x5 << 0)
68#define PCIE_ATU_CR2 0x908
69#define PCIE_ATU_ENABLE (0x1 << 31)
70#define PCIE_ATU_BAR_MODE_ENABLE (0x1 << 30)
71#define PCIE_ATU_LOWER_BASE 0x90C
72#define PCIE_ATU_UPPER_BASE 0x910
73#define PCIE_ATU_LIMIT 0x914
74#define PCIE_ATU_LOWER_TARGET 0x918
75#define PCIE_ATU_BUS(x) (((x) & 0xff) << 24)
76#define PCIE_ATU_DEV(x) (((x) & 0x1f) << 19)
77#define PCIE_ATU_FUNC(x) (((x) & 0x7) << 16)
78#define PCIE_ATU_UPPER_TARGET 0x91C
79
e44abfed
HZ
80#define PCIE_MISC_CONTROL_1_OFF 0x8BC
81#define PCIE_DBI_RO_WR_EN (0x1 << 0)
82
b90dc392
KVA
83/*
84 * iATU Unroll-specific register definitions
85 * From 4.80 core version the address translation will be made by unroll
86 */
87#define PCIE_ATU_UNR_REGION_CTRL1 0x00
88#define PCIE_ATU_UNR_REGION_CTRL2 0x04
89#define PCIE_ATU_UNR_LOWER_BASE 0x08
90#define PCIE_ATU_UNR_UPPER_BASE 0x0C
91#define PCIE_ATU_UNR_LIMIT 0x10
92#define PCIE_ATU_UNR_LOWER_TARGET 0x14
93#define PCIE_ATU_UNR_UPPER_TARGET 0x18
94
95/* Register address builder */
96#define PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(region) \
97 ((0x3 << 20) | ((region) << 9))
98
f8aed6ec
KVA
99#define PCIE_GET_ATU_INB_UNR_REG_OFFSET(region) \
100 ((0x3 << 20) | ((region) << 9) | (0x1 << 8))
101
102#define MSI_MESSAGE_CONTROL 0x52
103#define MSI_CAP_MMC_SHIFT 1
099a95f3 104#define MSI_CAP_MMC_MASK (7 << MSI_CAP_MMC_SHIFT)
f8aed6ec
KVA
105#define MSI_CAP_MME_SHIFT 4
106#define MSI_CAP_MME_MASK (7 << MSI_CAP_MME_SHIFT)
107#define MSI_MESSAGE_ADDR_L32 0x54
108#define MSI_MESSAGE_ADDR_U32 0x58
109
f342d940
JH
110/*
111 * Maximum number of MSI IRQs can be 256 per controller. But keep
112 * it 32 as of now. Probably we will never need more than 32. If needed,
113 * then increment it in multiple of 32.
114 */
115#define MAX_MSI_IRQS 32
116#define MAX_MSI_CTRLS (MAX_MSI_IRQS / 32)
117
442ec4c0
KVA
118struct pcie_port;
119struct dw_pcie;
f8aed6ec
KVA
120struct dw_pcie_ep;
121
122enum dw_pcie_region_type {
123 DW_PCIE_REGION_UNKNOWN,
124 DW_PCIE_REGION_INBOUND,
125 DW_PCIE_REGION_OUTBOUND,
126};
442ec4c0 127
608793e2
KVA
128enum dw_pcie_device_mode {
129 DW_PCIE_UNKNOWN_TYPE,
130 DW_PCIE_EP_TYPE,
131 DW_PCIE_LEG_EP_TYPE,
132 DW_PCIE_RC_TYPE,
133};
134
442ec4c0
KVA
135struct dw_pcie_host_ops {
136 int (*rd_own_conf)(struct pcie_port *pp, int where, int size, u32 *val);
137 int (*wr_own_conf)(struct pcie_port *pp, int where, int size, u32 val);
138 int (*rd_other_conf)(struct pcie_port *pp, struct pci_bus *bus,
139 unsigned int devfn, int where, int size, u32 *val);
140 int (*wr_other_conf)(struct pcie_port *pp, struct pci_bus *bus,
141 unsigned int devfn, int where, int size, u32 val);
4a301766 142 int (*host_init)(struct pcie_port *pp);
442ec4c0
KVA
143 void (*msi_set_irq)(struct pcie_port *pp, int irq);
144 void (*msi_clear_irq)(struct pcie_port *pp, int irq);
145 phys_addr_t (*get_msi_addr)(struct pcie_port *pp);
146 u32 (*get_msi_data)(struct pcie_port *pp, int pos);
147 void (*scan_bus)(struct pcie_port *pp);
148 int (*msi_host_init)(struct pcie_port *pp, struct msi_controller *chip);
149};
150
4b1ced84 151struct pcie_port {
4b1ced84 152 u8 root_bus_nr;
4b1ced84
JH
153 u64 cfg0_base;
154 void __iomem *va_cfg0_base;
adf70fc0 155 u32 cfg0_size;
4b1ced84
JH
156 u64 cfg1_base;
157 void __iomem *va_cfg1_base;
adf70fc0 158 u32 cfg1_size;
0021d22b 159 resource_size_t io_base;
adf70fc0
PA
160 phys_addr_t io_bus_addr;
161 u32 io_size;
4b1ced84 162 u64 mem_base;
adf70fc0
PA
163 phys_addr_t mem_bus_addr;
164 u32 mem_size;
0021d22b
ZW
165 struct resource *cfg;
166 struct resource *io;
167 struct resource *mem;
168 struct resource *busn;
4b1ced84 169 int irq;
4ab2e7c0 170 const struct dw_pcie_host_ops *ops;
f342d940 171 int msi_irq;
904d0e78 172 struct irq_domain *irq_domain;
111111a7 173 dma_addr_t msi_data;
f342d940 174 DECLARE_BITMAP(msi_irq_in_use, MAX_MSI_IRQS);
4b1ced84
JH
175};
176
f8aed6ec
KVA
177enum dw_pcie_as_type {
178 DW_PCIE_AS_UNKNOWN,
179 DW_PCIE_AS_MEM,
180 DW_PCIE_AS_IO,
181};
182
183struct dw_pcie_ep_ops {
184 void (*ep_init)(struct dw_pcie_ep *ep);
185 int (*raise_irq)(struct dw_pcie_ep *ep, enum pci_epc_irq_type type,
186 u8 interrupt_num);
187};
188
189struct dw_pcie_ep {
190 struct pci_epc *epc;
191 struct dw_pcie_ep_ops *ops;
192 phys_addr_t phys_base;
193 size_t addr_size;
a937fe08 194 size_t page_size;
f8aed6ec
KVA
195 u8 bar_to_atu[6];
196 phys_addr_t *outbound_addr;
197 unsigned long ib_window_map;
198 unsigned long ob_window_map;
199 u32 num_ib_windows;
200 u32 num_ob_windows;
2fd0c9d9
NC
201 void __iomem *msi_mem;
202 phys_addr_t msi_mem_phys;
f8aed6ec
KVA
203};
204
442ec4c0 205struct dw_pcie_ops {
a660083e 206 u64 (*cpu_addr_fixup)(u64 cpu_addr);
a509d7d9
KVA
207 u32 (*read_dbi)(struct dw_pcie *pcie, void __iomem *base, u32 reg,
208 size_t size);
209 void (*write_dbi)(struct dw_pcie *pcie, void __iomem *base, u32 reg,
210 size_t size, u32 val);
442ec4c0 211 int (*link_up)(struct dw_pcie *pcie);
f8aed6ec
KVA
212 int (*start_link)(struct dw_pcie *pcie);
213 void (*stop_link)(struct dw_pcie *pcie);
4b1ced84
JH
214};
215
442ec4c0
KVA
216struct dw_pcie {
217 struct device *dev;
218 void __iomem *dbi_base;
f8aed6ec 219 void __iomem *dbi_base2;
442ec4c0
KVA
220 u32 num_viewport;
221 u8 iatu_unroll_enabled;
222 struct pcie_port pp;
f8aed6ec 223 struct dw_pcie_ep ep;
442ec4c0
KVA
224 const struct dw_pcie_ops *ops;
225};
226
227#define to_dw_pcie_from_pp(port) container_of((port), struct dw_pcie, pp)
228
f8aed6ec
KVA
229#define to_dw_pcie_from_ep(endpoint) \
230 container_of((endpoint), struct dw_pcie, ep)
231
19ce01cc
KVA
232int dw_pcie_read(void __iomem *addr, int size, u32 *val);
233int dw_pcie_write(void __iomem *addr, int size, u32 val);
18edf451 234
a509d7d9
KVA
235u32 __dw_pcie_read_dbi(struct dw_pcie *pci, void __iomem *base, u32 reg,
236 size_t size);
237void __dw_pcie_write_dbi(struct dw_pcie *pci, void __iomem *base, u32 reg,
238 size_t size, u32 val);
442ec4c0
KVA
239int dw_pcie_link_up(struct dw_pcie *pci);
240int dw_pcie_wait_for_link(struct dw_pcie *pci);
feb85d9b
KVA
241void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index,
242 int type, u64 cpu_addr, u64 pci_addr,
243 u32 size);
f8aed6ec
KVA
244int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, int index, int bar,
245 u64 cpu_addr, enum dw_pcie_as_type as_type);
246void dw_pcie_disable_atu(struct dw_pcie *pci, int index,
247 enum dw_pcie_region_type type);
feb85d9b 248void dw_pcie_setup(struct dw_pcie *pci);
a0560209 249
b50b2db2
KVA
250static inline void dw_pcie_writel_dbi(struct dw_pcie *pci, u32 reg, u32 val)
251{
a509d7d9 252 __dw_pcie_write_dbi(pci, pci->dbi_base, reg, 0x4, val);
b50b2db2
KVA
253}
254
255static inline u32 dw_pcie_readl_dbi(struct dw_pcie *pci, u32 reg)
256{
a509d7d9 257 return __dw_pcie_read_dbi(pci, pci->dbi_base, reg, 0x4);
b50b2db2
KVA
258}
259
f8aed6ec
KVA
260static inline void dw_pcie_writew_dbi(struct dw_pcie *pci, u32 reg, u16 val)
261{
262 __dw_pcie_write_dbi(pci, pci->dbi_base, reg, 0x2, val);
263}
264
265static inline u16 dw_pcie_readw_dbi(struct dw_pcie *pci, u32 reg)
266{
267 return __dw_pcie_read_dbi(pci, pci->dbi_base, reg, 0x2);
268}
269
270static inline void dw_pcie_writeb_dbi(struct dw_pcie *pci, u32 reg, u8 val)
271{
272 __dw_pcie_write_dbi(pci, pci->dbi_base, reg, 0x1, val);
273}
274
275static inline u8 dw_pcie_readb_dbi(struct dw_pcie *pci, u32 reg)
276{
277 return __dw_pcie_read_dbi(pci, pci->dbi_base, reg, 0x1);
278}
279
280static inline void dw_pcie_writel_dbi2(struct dw_pcie *pci, u32 reg, u32 val)
281{
282 __dw_pcie_write_dbi(pci, pci->dbi_base2, reg, 0x4, val);
283}
284
285static inline u32 dw_pcie_readl_dbi2(struct dw_pcie *pci, u32 reg)
286{
287 return __dw_pcie_read_dbi(pci, pci->dbi_base2, reg, 0x4);
288}
289
e44abfed
HZ
290static inline void dw_pcie_dbi_ro_wr_en(struct dw_pcie *pci)
291{
292 u32 reg;
293 u32 val;
294
295 reg = PCIE_MISC_CONTROL_1_OFF;
296 val = dw_pcie_readl_dbi(pci, reg);
297 val |= PCIE_DBI_RO_WR_EN;
298 dw_pcie_writel_dbi(pci, reg, val);
299}
300
301static inline void dw_pcie_dbi_ro_wr_dis(struct dw_pcie *pci)
302{
303 u32 reg;
304 u32 val;
305
306 reg = PCIE_MISC_CONTROL_1_OFF;
307 val = dw_pcie_readl_dbi(pci, reg);
308 val &= ~PCIE_DBI_RO_WR_EN;
309 dw_pcie_writel_dbi(pci, reg, val);
310}
311
a0560209
KVA
312#ifdef CONFIG_PCIE_DW_HOST
313irqreturn_t dw_handle_msi_irq(struct pcie_port *pp);
314void dw_pcie_msi_init(struct pcie_port *pp);
315void dw_pcie_setup_rc(struct pcie_port *pp);
316int dw_pcie_host_init(struct pcie_port *pp);
317#else
318static inline irqreturn_t dw_handle_msi_irq(struct pcie_port *pp)
319{
320 return IRQ_NONE;
321}
322
323static inline void dw_pcie_msi_init(struct pcie_port *pp)
324{
325}
326
327static inline void dw_pcie_setup_rc(struct pcie_port *pp)
328{
329}
330
331static inline int dw_pcie_host_init(struct pcie_port *pp)
332{
333 return 0;
334}
335#endif
f8aed6ec
KVA
336
337#ifdef CONFIG_PCIE_DW_EP
338void dw_pcie_ep_linkup(struct dw_pcie_ep *ep);
339int dw_pcie_ep_init(struct dw_pcie_ep *ep);
340void dw_pcie_ep_exit(struct dw_pcie_ep *ep);
9e718119 341void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar);
f8aed6ec
KVA
342#else
343static inline void dw_pcie_ep_linkup(struct dw_pcie_ep *ep)
344{
345}
346
347static inline int dw_pcie_ep_init(struct dw_pcie_ep *ep)
348{
349 return 0;
350}
351
352static inline void dw_pcie_ep_exit(struct dw_pcie_ep *ep)
353{
354}
9e718119
NC
355
356static inline void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar)
357{
358}
f8aed6ec 359#endif
18edf451 360#endif /* _PCIE_DESIGNWARE_H */