aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafał Miłecki <zajec5@gmail.com>2015-03-14 12:55:54 -0400
committerRalf Baechle <ralf@linux-mips.org>2015-03-24 10:15:33 -0400
commit9a6a2b96dfd8b01336f8519a5be7fb353cfa62fb (patch)
treeac833136f3f54e258ba26eadd1641dd1bf9b5261
parentbc465aa9d045feb0e13b4a8f32cc33c1943f62d6 (diff)
MIPS: BCM47XX: Support SPROM prefixes for PCI devices
Support parsing SPROMs with prefixes defined like devpath1=pci/1/1 Signed-off-by: Rafał Miłecki <zajec5@gmail.com> Cc: linux-mips@linux-mips.org Cc: Hauke Mehrtens <hauke@hauke-m.de> Patchwork: https://patchwork.linux-mips.org/patch/9552/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r--arch/mips/bcm47xx/sprom.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/arch/mips/bcm47xx/sprom.c b/arch/mips/bcm47xx/sprom.c
index 2eff7fe99c6b..eff920560689 100644
--- a/arch/mips/bcm47xx/sprom.c
+++ b/arch/mips/bcm47xx/sprom.c
@@ -836,6 +836,38 @@ static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out)
836#endif 836#endif
837 837
838#if defined(CONFIG_BCM47XX_BCMA) 838#if defined(CONFIG_BCM47XX_BCMA)
839/*
840 * Having many NVRAM entries for PCI devices led to repeating prefixes like
841 * pci/1/1/ all the time and wasting flash space. So at some point Broadcom
842 * decided to introduce prefixes like 0: 1: 2: etc.
843 * If we find e.g. devpath0=pci/2/1 or devpath0=pci/2/1/ we should use 0:
844 * instead of pci/2/1/.
845 */
846static void bcm47xx_sprom_apply_prefix_alias(char *prefix, size_t prefix_size)
847{
848 size_t prefix_len = strlen(prefix);
849 size_t short_len = prefix_len - 1;
850 char nvram_var[10];
851 char buf[20];
852 int i;
853
854 /* Passed prefix has to end with a slash */
855 if (prefix_len <= 0 || prefix[prefix_len - 1] != '/')
856 return;
857
858 for (i = 0; i < 3; i++) {
859 if (snprintf(nvram_var, sizeof(nvram_var), "devpath%d", i) <= 0)
860 continue;
861 if (bcm47xx_nvram_getenv(nvram_var, buf, sizeof(buf)) < 0)
862 continue;
863 if (!strcmp(buf, prefix) ||
864 (short_len && strlen(buf) == short_len && !strncmp(buf, prefix, short_len))) {
865 snprintf(prefix, prefix_size, "%d:", i);
866 return;
867 }
868 }
869}
870
839static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out) 871static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
840{ 872{
841 char prefix[10]; 873 char prefix[10];
@@ -847,6 +879,7 @@ static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
847 snprintf(prefix, sizeof(prefix), "pci/%u/%u/", 879 snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
848 bus->host_pci->bus->number + 1, 880 bus->host_pci->bus->number + 1,
849 PCI_SLOT(bus->host_pci->devfn)); 881 PCI_SLOT(bus->host_pci->devfn));
882 bcm47xx_sprom_apply_prefix_alias(prefix, sizeof(prefix));
850 bcm47xx_fill_sprom(out, prefix, false); 883 bcm47xx_fill_sprom(out, prefix, false);
851 return 0; 884 return 0;
852 case BCMA_HOSTTYPE_SOC: 885 case BCMA_HOSTTYPE_SOC: