1 /*
2  * Copyright (C) 2013 Google Inc.
3  * Copyright (C) 2014 Sage Electronics Engineering, LLC.
4  * Copyright (C) 2016 Bin Meng <bmeng.cn@gmail.com>
5  *
6  * Modified from coreboot src/soc/intel/baytrail/include/soc/irq_helper.h
7  *
8  * SPDX-License-Identifier:	GPL-2.0+
9  */
10 
11 /*
12  * This file intentionally gets included multiple times, to set pic and apic
13  * modes, so should not have guard statements added.
14  */
15 
16 /*
17  * This file will use irqroute.asl and irqroute.h to generate the ACPI IRQ
18  * routing for the platform being compiled.
19  *
20  * This method uses #defines in irqroute.h along with the macros contained
21  * in this file to generate an IRQ routing for each PCI device in the system.
22  */
23 
24 #undef PCI_DEV_PIRQ_ROUTES
25 #undef PCI_DEV_PIRQ_ROUTE
26 #undef ACPI_DEV_IRQ
27 #undef PCIE_BRIDGE_DEV
28 #undef RP_IRQ_ROUTES
29 #undef ROOTPORT_METHODS
30 #undef ROOTPORT_IRQ_ROUTES
31 #undef RP_METHOD
32 
33 #if defined(PIC_MODE)
34 
35 #define ACPI_DEV_IRQ(dev_, pin_, pin_name_) \
36 	Package() { ## dev_ ## ffff, pin_, \_SB.PCI0.LPCB.LNK ## pin_name_, 0 }
37 
38 #define RP_IRQ_ROUTES(prefix_, func_, a_, b_, c_, d_) \
39 Name(prefix_ ## func_ ## P, Package() \
40 { \
41 	ACPI_DEV_IRQ(0x0000, 0, a_), \
42 	ACPI_DEV_IRQ(0x0000, 1, b_), \
43 	ACPI_DEV_IRQ(0x0000, 2, c_), \
44 	ACPI_DEV_IRQ(0x0000, 3, d_), \
45 })
46 
47 /* define as blank so ROOTPORT_METHODS only gets inserted once */
48 #define ROOTPORT_METHODS(prefix_, dev_)
49 
50 #else /* defined(PIC_MODE) */
51 
52 #define ACPI_DEV_IRQ(dev_, pin_, pin_name_) \
53 	Package() { ## dev_ ## ffff, pin_, 0, PIRQ ## pin_name_ ## _APIC_IRQ }
54 
55 #define RP_IRQ_ROUTES(prefix_, func_, a_, b_, c_, d_) \
56 Name(prefix_ ## func_ ## A, Package() \
57 { \
58 	ACPI_DEV_IRQ(0x0000, 0, a_), \
59 	ACPI_DEV_IRQ(0x0000, 1, b_), \
60 	ACPI_DEV_IRQ(0x0000, 2, c_), \
61 	ACPI_DEV_IRQ(0x0000, 3, d_), \
62 })
63 
64 #define ROOTPORT_METHODS(prefix_, dev_) \
65 	RP_METHOD(prefix_, dev_, 0) \
66 	RP_METHOD(prefix_, dev_, 1) \
67 	RP_METHOD(prefix_, dev_, 2) \
68 	RP_METHOD(prefix_, dev_, 3) \
69 	RP_METHOD(prefix_, dev_, 4) \
70 	RP_METHOD(prefix_, dev_, 5) \
71 	RP_METHOD(prefix_, dev_, 6) \
72 	RP_METHOD(prefix_, dev_, 7)
73 
74 #endif /* defined(PIC_MODE) */
75 
76 #define PCI_DEV_PIRQ_ROUTE(dev_, a_, b_, c_, d_) \
77 	ACPI_DEV_IRQ(dev_, 0, a_), \
78 	ACPI_DEV_IRQ(dev_, 1, b_), \
79 	ACPI_DEV_IRQ(dev_, 2, c_), \
80 	ACPI_DEV_IRQ(dev_, 3, d_)
81 
82 #define PCIE_BRIDGE_DEV(prefix_, dev_, a_, b_, c_, d_) \
83 	ROOTPORT_IRQ_ROUTES(prefix_, a_, b_, c_, d_) \
84 	ROOTPORT_METHODS(prefix_, dev_)
85 
86 #define ROOTPORT_IRQ_ROUTES(prefix_, a_, b_, c_, d_) \
87 	RP_IRQ_ROUTES(prefix_, 0, a_, b_, c_, d_) \
88 	RP_IRQ_ROUTES(prefix_, 1, b_, c_, d_, a_) \
89 	RP_IRQ_ROUTES(prefix_, 2, c_, d_, a_, b_) \
90 	RP_IRQ_ROUTES(prefix_, 3, d_, a_, b_, c_) \
91 	RP_IRQ_ROUTES(prefix_, 4, a_, b_, c_, d_) \
92 	RP_IRQ_ROUTES(prefix_, 5, b_, c_, d_, a_) \
93 	RP_IRQ_ROUTES(prefix_, 6, c_, d_, a_, b_) \
94 	RP_IRQ_ROUTES(prefix_, 7, d_, a_, b_, c_)
95 
96 #define RP_METHOD(prefix_, dev_, func_)\
97 Device (prefix_ ## 0 ## func_) \
98 { \
99 	Name(_ADR, dev_ ## 000 ## func_) \
100 	Name(_PRW, Package() { 0, 0 }) \
101 	Method(_PRT) { \
102 		If (PICM) { \
103 			Return (prefix_ ## func_ ## A) \
104 		} Else { \
105 			Return (prefix_ ## func_ ## P) \
106 		} \
107 	} \
108 }
109 
110 /* SoC specific PIRQ route configuration */
111 #include <asm/arch/acpi/irqroute.h>
112