031-01-MIPS-BCM47XX-Support-SPROM-prefixes-for-PCI-devices.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. From 9a6a2b96dfd8b01336f8519a5be7fb353cfa62fb Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  3. Date: Sat, 14 Mar 2015 17:55:54 +0100
  4. Subject: [PATCH] MIPS: BCM47XX: Support SPROM prefixes for PCI devices
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Support parsing SPROMs with prefixes defined like devpath1=pci/1/1
  9. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  10. Cc: linux-mips@linux-mips.org
  11. Cc: Hauke Mehrtens <hauke@hauke-m.de>
  12. Patchwork: https://patchwork.linux-mips.org/patch/9552/
  13. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  14. ---
  15. arch/mips/bcm47xx/sprom.c | 33 +++++++++++++++++++++++++++++++++
  16. 1 file changed, 33 insertions(+)
  17. --- a/arch/mips/bcm47xx/sprom.c
  18. +++ b/arch/mips/bcm47xx/sprom.c
  19. @@ -836,6 +836,38 @@ static int bcm47xx_get_sprom_ssb(struct
  20. #endif
  21. #if defined(CONFIG_BCM47XX_BCMA)
  22. +/*
  23. + * Having many NVRAM entries for PCI devices led to repeating prefixes like
  24. + * pci/1/1/ all the time and wasting flash space. So at some point Broadcom
  25. + * decided to introduce prefixes like 0: 1: 2: etc.
  26. + * If we find e.g. devpath0=pci/2/1 or devpath0=pci/2/1/ we should use 0:
  27. + * instead of pci/2/1/.
  28. + */
  29. +static void bcm47xx_sprom_apply_prefix_alias(char *prefix, size_t prefix_size)
  30. +{
  31. + size_t prefix_len = strlen(prefix);
  32. + size_t short_len = prefix_len - 1;
  33. + char nvram_var[10];
  34. + char buf[20];
  35. + int i;
  36. +
  37. + /* Passed prefix has to end with a slash */
  38. + if (prefix_len <= 0 || prefix[prefix_len - 1] != '/')
  39. + return;
  40. +
  41. + for (i = 0; i < 3; i++) {
  42. + if (snprintf(nvram_var, sizeof(nvram_var), "devpath%d", i) <= 0)
  43. + continue;
  44. + if (bcm47xx_nvram_getenv(nvram_var, buf, sizeof(buf)) < 0)
  45. + continue;
  46. + if (!strcmp(buf, prefix) ||
  47. + (short_len && strlen(buf) == short_len && !strncmp(buf, prefix, short_len))) {
  48. + snprintf(prefix, prefix_size, "%d:", i);
  49. + return;
  50. + }
  51. + }
  52. +}
  53. +
  54. static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
  55. {
  56. char prefix[10];
  57. @@ -847,6 +879,7 @@ static int bcm47xx_get_sprom_bcma(struct
  58. snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
  59. bus->host_pci->bus->number + 1,
  60. PCI_SLOT(bus->host_pci->devfn));
  61. + bcm47xx_sprom_apply_prefix_alias(prefix, sizeof(prefix));
  62. bcm47xx_fill_sprom(out, prefix, false);
  63. return 0;
  64. case BCMA_HOSTTYPE_SOC: