Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
b7eba2f
Documentation
arch
alpha
arc
arm
arm64
avr32
blackfin
c6x
cris
frv
hexagon
ia64
m32r
m68k
metag
microblaze
mips
mn10300
nios2
openrisc
parisc
powerpc
boot
configs
crypto
include
kernel
kvm
lib
math-emu
mm
net
oprofile
perf
platforms
sysdev
ge
qe_lib
xics
6xx-suspend.S
Kconfig
Makefile
axonram.c
cpm1.c
cpm2.c
cpm2_pic.c
cpm2_pic.h
cpm_common.c
dart.h
dart_iommu.c
dcr-low.S
dcr.c
ehv_pic.c
fsl_85xx_cache_ctlr.h
fsl_85xx_cache_sram.c
fsl_85xx_l2ctlr.c
fsl_gtm.c
fsl_lbc.c
fsl_mpic_err.c
fsl_mpic_timer_wakeup.c
fsl_msi.c
fsl_msi.h
fsl_pci.c
fsl_pci.h
fsl_pmc.c
fsl_rio.c
fsl_rio.h
fsl_rmu.c
fsl_soc.c
fsl_soc.h
grackle.c
i8259.c
indirect_pci.c
ipic.c
ipic.h
micropatch.c
mmio_nvram.c
mpc5xxx_clocks.c
mpc8xx_pic.c
mpc8xx_pic.h
mpic.c
mpic.h
mpic_msgr.c
mpic_msi.c
mpic_timer.c
mpic_u3msi.c
msi_bitmap.c
mv64x60.h
mv64x60_dev.c
mv64x60_pci.c
mv64x60_pic.c
mv64x60_udbg.c
of_rtc.c
pmi.c
ppc4xx_cpm.c
ppc4xx_gpio.c
ppc4xx_hsta_msi.c
ppc4xx_msi.c
ppc4xx_ocm.c
ppc4xx_pci.c
ppc4xx_pci.h
ppc4xx_soc.c
rtc_cmos_setup.c
scom.c
simple_gpio.c
simple_gpio.h
tsi108_dev.c
tsi108_pci.c
udbg_memcons.c
uic.c
xilinx_intc.c
xilinx_pci.c
xmon
Kconfig
Kconfig.debug
Makefile
relocs_check.sh
s390
score
sh
sparc
tile
um
unicore32
x86
xtensa
.gitignore
Kconfig
block
crypto
drivers
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
arch
/
powerpc
/
sysdev
/
ppc4xx_msi.c
Blame
Blame
Latest commit
History
History
285 lines (241 loc) · 7.18 KB
Breadcrumbs
linux
/
arch
/
powerpc
/
sysdev
/
ppc4xx_msi.c
Top
File metadata and controls
Code
Blame
285 lines (241 loc) · 7.18 KB
Raw
/* * Adding PCI-E MSI support for PPC4XX SoCs. * * Copyright (c) 2010, Applied Micro Circuits Corporation * Authors: Tirumala R Marri <tmarri@apm.com> * Feng Kan <fkan@apm.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ #include <linux/irq.h> #include <linux/pci.h> #include <linux/msi.h> #include <linux/of_platform.h> #include <linux/interrupt.h> #include <linux/export.h> #include <linux/kernel.h> #include <asm/prom.h> #include <asm/hw_irq.h> #include <asm/ppc-pci.h> #include <asm/dcr.h> #include <asm/dcr-regs.h> #include <asm/msi_bitmap.h> #define PEIH_TERMADH 0x00 #define PEIH_TERMADL 0x08 #define PEIH_MSIED 0x10 #define PEIH_MSIMK 0x18 #define PEIH_MSIASS 0x20 #define PEIH_FLUSH0 0x30 #define PEIH_FLUSH1 0x38 #define PEIH_CNTRST 0x48 static int msi_irqs; struct ppc4xx_msi { u32 msi_addr_lo; u32 msi_addr_hi; void __iomem *msi_regs; int *msi_virqs; struct msi_bitmap bitmap; struct device_node *msi_dev; }; static struct ppc4xx_msi ppc4xx_msi; static int ppc4xx_msi_init_allocator(struct platform_device *dev, struct ppc4xx_msi *msi_data) { int err; err = msi_bitmap_alloc(&msi_data->bitmap, msi_irqs, dev->dev.of_node); if (err) return err; err = msi_bitmap_reserve_dt_hwirqs(&msi_data->bitmap); if (err < 0) { msi_bitmap_free(&msi_data->bitmap); return err; } return 0; } static int ppc4xx_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) { int int_no = -ENOMEM; unsigned int virq; struct msi_msg msg; struct msi_desc *entry; struct ppc4xx_msi *msi_data = &ppc4xx_msi; dev_dbg(&dev->dev, "PCIE-MSI:%s called. vec %x type %d\n", __func__, nvec, type); if (type == PCI_CAP_ID_MSIX) pr_debug("ppc4xx msi: MSI-X untested, trying anyway.\n"); msi_data->msi_virqs = kmalloc((msi_irqs) * sizeof(int), GFP_KERNEL); if (!msi_data->msi_virqs) return -ENOMEM; list_for_each_entry(entry, &dev->msi_list, list) { int_no = msi_bitmap_alloc_hwirqs(&msi_data->bitmap, 1); if (int_no >= 0) break; if (int_no < 0) { pr_debug("%s: fail allocating msi interrupt\n", __func__); } virq = irq_of_parse_and_map(msi_data->msi_dev, int_no); if (virq == NO_IRQ) { dev_err(&dev->dev, "%s: fail mapping irq\n", __func__); msi_bitmap_free_hwirqs(&msi_data->bitmap, int_no, 1); return -ENOSPC; } dev_dbg(&dev->dev, "%s: virq = %d\n", __func__, virq); /* Setup msi address space */ msg.address_hi = msi_data->msi_addr_hi; msg.address_lo = msi_data->msi_addr_lo; irq_set_msi_desc(virq, entry); msg.data = int_no; pci_write_msi_msg(virq, &msg); } return 0; } void ppc4xx_teardown_msi_irqs(struct pci_dev *dev) { struct msi_desc *entry; struct ppc4xx_msi *msi_data = &ppc4xx_msi; dev_dbg(&dev->dev, "PCIE-MSI: tearing down msi irqs\n"); list_for_each_entry(entry, &dev->msi_list, list) { if (entry->irq == NO_IRQ) continue; irq_set_msi_desc(entry->irq, NULL); msi_bitmap_free_hwirqs(&msi_data->bitmap, virq_to_hw(entry->irq), 1); irq_dispose_mapping(entry->irq); } } static int ppc4xx_setup_pcieh_hw(struct platform_device *dev, struct resource res, struct ppc4xx_msi *msi) { const u32 *msi_data; const u32 *msi_mask; const u32 *sdr_addr; dma_addr_t msi_phys; void *msi_virt; sdr_addr = of_get_property(dev->dev.of_node, "sdr-base", NULL); if (!sdr_addr) return -1; mtdcri(SDR0, *sdr_addr, upper_32_bits(res.start)); /*HIGH addr */ mtdcri(SDR0, *sdr_addr + 1, lower_32_bits(res.start)); /* Low addr */ msi->msi_dev = of_find_node_by_name(NULL, "ppc4xx-msi"); if (!msi->msi_dev) return -ENODEV; msi->msi_regs = of_iomap(msi->msi_dev, 0); if (!msi->msi_regs) { dev_err(&dev->dev, "of_iomap problem failed\n"); return -ENOMEM; } dev_dbg(&dev->dev, "PCIE-MSI: msi register mapped 0x%x 0x%x\n", (u32) (msi->msi_regs + PEIH_TERMADH), (u32) (msi->msi_regs)); msi_virt = dma_alloc_coherent(&dev->dev, 64, &msi_phys, GFP_KERNEL); if (!msi_virt) return -ENOMEM; msi->msi_addr_hi = upper_32_bits(msi_phys); msi->msi_addr_lo = lower_32_bits(msi_phys & 0xffffffff); dev_dbg(&dev->dev, "PCIE-MSI: msi address high 0x%x, low 0x%x\n", msi->msi_addr_hi, msi->msi_addr_lo); /* Progam the Interrupt handler Termination addr registers */ out_be32(msi->msi_regs + PEIH_TERMADH, msi->msi_addr_hi); out_be32(msi->msi_regs + PEIH_TERMADL, msi->msi_addr_lo); msi_data = of_get_property(dev->dev.of_node, "msi-data", NULL); if (!msi_data) return -1; msi_mask = of_get_property(dev->dev.of_node, "msi-mask", NULL); if (!msi_mask) return -1; /* Program MSI Expected data and Mask bits */ out_be32(msi->msi_regs + PEIH_MSIED, *msi_data); out_be32(msi->msi_regs + PEIH_MSIMK, *msi_mask); dma_free_coherent(&dev->dev, 64, msi_virt, msi_phys); return 0; } static int ppc4xx_of_msi_remove(struct platform_device *dev) { struct ppc4xx_msi *msi = dev->dev.platform_data; int i; int virq; for (i = 0; i < msi_irqs; i++) { virq = msi->msi_virqs[i]; if (virq != NO_IRQ) irq_dispose_mapping(virq); } if (msi->bitmap.bitmap) msi_bitmap_free(&msi->bitmap); iounmap(msi->msi_regs); of_node_put(msi->msi_dev); kfree(msi); return 0; } static int ppc4xx_msi_probe(struct platform_device *dev) { struct ppc4xx_msi *msi; struct resource res; int err = 0; struct pci_controller *phb; dev_dbg(&dev->dev, "PCIE-MSI: Setting up MSI support...\n"); msi = kzalloc(sizeof(struct ppc4xx_msi), GFP_KERNEL); if (!msi) { dev_err(&dev->dev, "No memory for MSI structure\n"); return -ENOMEM; } dev->dev.platform_data = msi; /* Get MSI ranges */ err = of_address_to_resource(dev->dev.of_node, 0, &res); if (err) { dev_err(&dev->dev, "%s resource error!\n", dev->dev.of_node->full_name); goto error_out; } msi_irqs = of_irq_count(dev->dev.of_node); if (!msi_irqs) return -ENODEV; if (ppc4xx_setup_pcieh_hw(dev, res, msi)) goto error_out; err = ppc4xx_msi_init_allocator(dev, msi); if (err) { dev_err(&dev->dev, "Error allocating MSI bitmap\n"); goto error_out; } ppc4xx_msi = *msi; list_for_each_entry(phb, &hose_list, list_node) { phb->controller_ops.setup_msi_irqs = ppc4xx_setup_msi_irqs; phb->controller_ops.teardown_msi_irqs = ppc4xx_teardown_msi_irqs; } return err; error_out: ppc4xx_of_msi_remove(dev); return err; } static const struct of_device_id ppc4xx_msi_ids[] = { { .compatible = "amcc,ppc4xx-msi", }, {} }; static struct platform_driver ppc4xx_msi_driver = { .probe = ppc4xx_msi_probe, .remove = ppc4xx_of_msi_remove, .driver = { .name = "ppc4xx-msi", .of_match_table = ppc4xx_msi_ids, }, }; static __init int ppc4xx_msi_init(void) { return platform_driver_register(&ppc4xx_msi_driver); } subsys_initcall(ppc4xx_msi_init);
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
You can’t perform that action at this time.