0012-mips-ath79-swizzle-PCI-address-for-ar71xx.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. From 0c139cb15774f3c41a0cf6620727e676c874834a Mon Sep 17 00:00:00 2001
  2. From: Phil Sutter <phil@nwl.cc>
  3. Date: Tue, 13 May 2014 00:28:24 +0200
  4. Subject: [PATCH] mips: ath79: swizzle PCI address for ar71xx
  5. ---
  6. arch/mips/ath79/pci.c | 42 ++++++++++++++++++++++++++
  7. arch/mips/include/asm/mach-ath79/mangle-port.h | 37 +++++++++++++++++++++++
  8. 2 files changed, 79 insertions(+)
  9. create mode 100644 arch/mips/include/asm/mach-ath79/mangle-port.h
  10. diff --git a/arch/mips/ath79/pci.c b/arch/mips/ath79/pci.c
  11. index 730c0b0..47be58c 100644
  12. --- a/arch/mips/ath79/pci.c
  13. +++ b/arch/mips/ath79/pci.c
  14. @@ -13,6 +13,7 @@
  15. */
  16. #include <linux/init.h>
  17. +#include <linux/export.h>
  18. #include <linux/pci.h>
  19. #include <linux/resource.h>
  20. #include <linux/platform_device.h>
  21. @@ -25,6 +26,9 @@ static int (*ath79_pci_plat_dev_init)(struct pci_dev *dev);
  22. static const struct ath79_pci_irq *ath79_pci_irq_map __initdata;
  23. static unsigned ath79_pci_nr_irqs __initdata;
  24. +static unsigned long (*__ath79_pci_swizzle_b)(unsigned long port);
  25. +static unsigned long (*__ath79_pci_swizzle_w)(unsigned long port);
  26. +
  27. static const struct ath79_pci_irq ar71xx_pci_irq_map[] __initconst = {
  28. {
  29. .slot = 17,
  30. @@ -212,12 +216,50 @@ ath79_register_pci_ar724x(int id,
  31. return pdev;
  32. }
  33. +static inline bool ar71xx_is_pci_addr(unsigned long port)
  34. +{
  35. + unsigned long phys = CPHYSADDR(port);
  36. +
  37. + return (phys >= AR71XX_PCI_MEM_BASE &&
  38. + phys < AR71XX_PCI_MEM_BASE + AR71XX_PCI_MEM_SIZE);
  39. +}
  40. +
  41. +static unsigned long ar71xx_pci_swizzle_b(unsigned long port)
  42. +{
  43. + return ar71xx_is_pci_addr(port) ? port ^ 3 : port;
  44. +}
  45. +
  46. +static unsigned long ar71xx_pci_swizzle_w(unsigned long port)
  47. +{
  48. + return ar71xx_is_pci_addr(port) ? port ^ 2 : port;
  49. +}
  50. +
  51. +unsigned long ath79_pci_swizzle_b(unsigned long port)
  52. +{
  53. + if (__ath79_pci_swizzle_b)
  54. + return __ath79_pci_swizzle_b(port);
  55. +
  56. + return port;
  57. +}
  58. +EXPORT_SYMBOL(ath79_pci_swizzle_b);
  59. +
  60. +unsigned long ath79_pci_swizzle_w(unsigned long port)
  61. +{
  62. + if (__ath79_pci_swizzle_w)
  63. + return __ath79_pci_swizzle_w(port);
  64. +
  65. + return port;
  66. +}
  67. +EXPORT_SYMBOL(ath79_pci_swizzle_w);
  68. +
  69. int __init ath79_register_pci(void)
  70. {
  71. struct platform_device *pdev = NULL;
  72. if (soc_is_ar71xx()) {
  73. pdev = ath79_register_pci_ar71xx();
  74. + __ath79_pci_swizzle_b = ar71xx_pci_swizzle_b;
  75. + __ath79_pci_swizzle_w = ar71xx_pci_swizzle_w;
  76. } else if (soc_is_ar724x()) {
  77. pdev = ath79_register_pci_ar724x(-1,
  78. AR724X_PCI_CFG_BASE,
  79. diff --git a/arch/mips/include/asm/mach-ath79/mangle-port.h b/arch/mips/include/asm/mach-ath79/mangle-port.h
  80. new file mode 100644
  81. index 0000000..ffd4e20
  82. --- /dev/null
  83. +++ b/arch/mips/include/asm/mach-ath79/mangle-port.h
  84. @@ -0,0 +1,37 @@
  85. +/*
  86. + * Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
  87. + *
  88. + * This file was derived from: inlude/asm-mips/mach-generic/mangle-port.h
  89. + * Copyright (C) 2003, 2004 Ralf Baechle
  90. + *
  91. + * This program is free software; you can redistribute it and/or modify it
  92. + * under the terms of the GNU General Public License version 2 as published
  93. + * by the Free Software Foundation.
  94. + */
  95. +
  96. +#ifndef __ASM_MACH_ATH79_MANGLE_PORT_H
  97. +#define __ASM_MACH_ATH79_MANGLE_PORT_H
  98. +
  99. +#ifdef CONFIG_PCI
  100. +extern unsigned long (ath79_pci_swizzle_b)(unsigned long port);
  101. +extern unsigned long (ath79_pci_swizzle_w)(unsigned long port);
  102. +#else
  103. +#define ath79_pci_swizzle_b(port) (port)
  104. +#define ath79_pci_swizzle_w(port) (port)
  105. +#endif
  106. +
  107. +#define __swizzle_addr_b(port) ath79_pci_swizzle_b(port)
  108. +#define __swizzle_addr_w(port) ath79_pci_swizzle_w(port)
  109. +#define __swizzle_addr_l(port) (port)
  110. +#define __swizzle_addr_q(port) (port)
  111. +
  112. +# define ioswabb(a, x) (x)
  113. +# define __mem_ioswabb(a, x) (x)
  114. +# define ioswabw(a, x) (x)
  115. +# define __mem_ioswabw(a, x) cpu_to_le16(x)
  116. +# define ioswabl(a, x) (x)
  117. +# define __mem_ioswabl(a, x) cpu_to_le32(x)
  118. +# define ioswabq(a, x) (x)
  119. +# define __mem_ioswabq(a, x) cpu_to_le64(x)
  120. +
  121. +#endif /* __ASM_MACH_ATH79_MANGLE_PORT_H */
  122. --
  123. 1.8.5.3