Re: svn commit: r330575 - in head/sys: conf dev/acpica dev/pci

2018-03-07 Thread John Baldwin
On Wednesday, March 07, 2018 10:47:27 AM Andrew Turner wrote:
> Author: andrew
> Date: Wed Mar  7 10:47:27 2018
> New Revision: 330575
> URL: https://svnweb.freebsd.org/changeset/base/330575
> 
> Log:
>   Add an acpi attachment to the pci_host_generic driver and have the ACPI
>   bus provide it with its needed memory resources.
>   
>   This allows us to use PCIe on the ThunderX2 and, with a previous version
>   of the patch, on the SoftIron 3000 with ACPI.
>   
>   Obtained from:  ABT Systems Ltd
>   Sponsored by:   The FreeBSD Foundation
>   Sponsored by:   DARPA, AFRL
>   Sponsored by:   Cavium (Hardware)
>   Differential Revision:  https://reviews.freebsd.org/D8767
> 
> Added:
>   head/sys/dev/pci/pci_host_generic_acpi.c   (contents, props changed)
> Modified:
>   head/sys/conf/files.arm64
>   head/sys/dev/acpica/acpi.c
> 
> Modified: head/sys/conf/files.arm64
> ==
> --- head/sys/conf/files.arm64 Wed Mar  7 09:58:36 2018(r330574)
> +++ head/sys/conf/files.arm64 Wed Mar  7 10:47:27 2018(r330575)
> @@ -171,6 +171,8 @@ crypto/blowfish/bf_enc.c  optionalcrypto | ipsec 
> | ips
>  crypto/des/des_enc.c optionalcrypto | ipsec | ipsec_support 
> | netsmb
>  dev/acpica/acpi_bus_if.m optionalacpi
>  dev/acpica/acpi_if.m optionalacpi
> +dev/acpica/acpi_pci_link.c   optionalacpi pci
> +dev/acpica/acpi_pcib.c   optionalacpi pci
>  dev/ahci/ahci_generic.c  optionalahci
>  dev/axgbe/if_axgbe.c optionalaxgbe
>  dev/axgbe/xgbe-desc.coptionalaxgbe
> @@ -191,6 +193,7 @@ dev/neta/if_mvneta.c  optionalneta 
> mdio mii
>  dev/ofw/ofw_cpu.coptionalfdt
>  dev/ofw/ofwpci.c optionalfdt pci
>  dev/pci/pci_host_generic.c   optionalpci
> +dev/pci/pci_host_generic_acpi.c  optionalpci acpi
>  dev/pci/pci_host_generic_fdt.c   optionalpci fdt
>  dev/psci/psci.c  optionalpsci
>  dev/psci/psci_arm64.Soptionalpsci
> 
> Modified: head/sys/dev/acpica/acpi.c
> ==
> --- head/sys/dev/acpica/acpi.cWed Mar  7 09:58:36 2018
> (r330574)
> +++ head/sys/dev/acpica/acpi.cWed Mar  7 10:47:27 2018
> (r330575)
> @@ -1883,6 +1883,29 @@ acpi_enable_pcie(void)
>   alloc++;
>   }
>  }
> +#elif defined(__aarch64__)
> +static void
> +acpi_enable_pcie(device_t child, int segment)
> +{
> + ACPI_TABLE_HEADER *hdr;
> + ACPI_MCFG_ALLOCATION *alloc, *end;
> + ACPI_STATUS status;
> +
> + status = AcpiGetTable(ACPI_SIG_MCFG, 1, );
> + if (ACPI_FAILURE(status))
> + return;
> +
> + end = (ACPI_MCFG_ALLOCATION *)((char *)hdr + hdr->Length);
> + alloc = (ACPI_MCFG_ALLOCATION *)((ACPI_TABLE_MCFG *)hdr + 1);
> + while (alloc < end) {
> + if (alloc->PciSegment == segment) {
> + bus_set_resource(child, SYS_RES_MEMORY, 0,
> + alloc->Address, 0x1000);
> + return;
> + }
> + alloc++;
> + }
> +}
>  #endif
>  
>  /*
> @@ -1974,6 +1997,9 @@ acpi_probe_child(ACPI_HANDLE handle, UINT32 level, voi
>  {
>  ACPI_DEVICE_INFO *devinfo;
>  struct acpi_device   *ad;
> +#ifdef __aarch64__
> +int segment;
> +#endif
>  struct acpi_prw_data prw;
>  ACPI_OBJECT_TYPE type;
>  ACPI_HANDLE h;
> @@ -2076,6 +2102,13 @@ acpi_probe_child(ACPI_HANDLE handle, UINT32 level, voi
>   ad->ad_cls_class = strtoul(devinfo->ClassCode.String,
>   NULL, 16);
>   }
> +#ifdef __aarch64__
> + if ((devinfo->Flags & ACPI_PCI_ROOT_BRIDGE) != 0) {
> + if (ACPI_SUCCESS(acpi_GetInteger(handle, "_SEG", 
> ))) {
> + acpi_enable_pcie(child, segment);
> + }
> + }
> +#endif
>   AcpiOsFree(devinfo);
>   }
>   break;

This logic probably belongs in the attach routine of the pcib driver rather
than in MD #ifdef's in acpi.c.  I still think we should be using 
acpi_pcib_acpi.c
on arm64.  IIRC all that is required is using a layer of indirection for PCI
config access (using the existing pcib_if.m methods in the parent of acpi0 would
work for this).

-- 
John Baldwin
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r330575 - in head/sys: conf dev/acpica dev/pci

2018-03-07 Thread Andrew Turner
Author: andrew
Date: Wed Mar  7 10:47:27 2018
New Revision: 330575
URL: https://svnweb.freebsd.org/changeset/base/330575

Log:
  Add an acpi attachment to the pci_host_generic driver and have the ACPI
  bus provide it with its needed memory resources.
  
  This allows us to use PCIe on the ThunderX2 and, with a previous version
  of the patch, on the SoftIron 3000 with ACPI.
  
  Obtained from:ABT Systems Ltd
  Sponsored by: The FreeBSD Foundation
  Sponsored by: DARPA, AFRL
  Sponsored by: Cavium (Hardware)
  Differential Revision:https://reviews.freebsd.org/D8767

Added:
  head/sys/dev/pci/pci_host_generic_acpi.c   (contents, props changed)
Modified:
  head/sys/conf/files.arm64
  head/sys/dev/acpica/acpi.c

Modified: head/sys/conf/files.arm64
==
--- head/sys/conf/files.arm64   Wed Mar  7 09:58:36 2018(r330574)
+++ head/sys/conf/files.arm64   Wed Mar  7 10:47:27 2018(r330575)
@@ -171,6 +171,8 @@ crypto/blowfish/bf_enc.coptionalcrypto | ipsec 
| ips
 crypto/des/des_enc.c   optionalcrypto | ipsec | ipsec_support 
| netsmb
 dev/acpica/acpi_bus_if.m   optionalacpi
 dev/acpica/acpi_if.m   optionalacpi
+dev/acpica/acpi_pci_link.c optionalacpi pci
+dev/acpica/acpi_pcib.c optionalacpi pci
 dev/ahci/ahci_generic.coptionalahci
 dev/axgbe/if_axgbe.c   optionalaxgbe
 dev/axgbe/xgbe-desc.c  optionalaxgbe
@@ -191,6 +193,7 @@ dev/neta/if_mvneta.coptionalneta 
mdio mii
 dev/ofw/ofw_cpu.c  optionalfdt
 dev/ofw/ofwpci.c   optionalfdt pci
 dev/pci/pci_host_generic.c optionalpci
+dev/pci/pci_host_generic_acpi.coptionalpci acpi
 dev/pci/pci_host_generic_fdt.c optionalpci fdt
 dev/psci/psci.coptionalpsci
 dev/psci/psci_arm64.S  optionalpsci

Modified: head/sys/dev/acpica/acpi.c
==
--- head/sys/dev/acpica/acpi.c  Wed Mar  7 09:58:36 2018(r330574)
+++ head/sys/dev/acpica/acpi.c  Wed Mar  7 10:47:27 2018(r330575)
@@ -1883,6 +1883,29 @@ acpi_enable_pcie(void)
alloc++;
}
 }
+#elif defined(__aarch64__)
+static void
+acpi_enable_pcie(device_t child, int segment)
+{
+   ACPI_TABLE_HEADER *hdr;
+   ACPI_MCFG_ALLOCATION *alloc, *end;
+   ACPI_STATUS status;
+
+   status = AcpiGetTable(ACPI_SIG_MCFG, 1, );
+   if (ACPI_FAILURE(status))
+   return;
+
+   end = (ACPI_MCFG_ALLOCATION *)((char *)hdr + hdr->Length);
+   alloc = (ACPI_MCFG_ALLOCATION *)((ACPI_TABLE_MCFG *)hdr + 1);
+   while (alloc < end) {
+   if (alloc->PciSegment == segment) {
+   bus_set_resource(child, SYS_RES_MEMORY, 0,
+   alloc->Address, 0x1000);
+   return;
+   }
+   alloc++;
+   }
+}
 #endif
 
 /*
@@ -1974,6 +1997,9 @@ acpi_probe_child(ACPI_HANDLE handle, UINT32 level, voi
 {
 ACPI_DEVICE_INFO *devinfo;
 struct acpi_device *ad;
+#ifdef __aarch64__
+int segment;
+#endif
 struct acpi_prw_data prw;
 ACPI_OBJECT_TYPE type;
 ACPI_HANDLE h;
@@ -2076,6 +2102,13 @@ acpi_probe_child(ACPI_HANDLE handle, UINT32 level, voi
ad->ad_cls_class = strtoul(devinfo->ClassCode.String,
NULL, 16);
}
+#ifdef __aarch64__
+   if ((devinfo->Flags & ACPI_PCI_ROOT_BRIDGE) != 0) {
+   if (ACPI_SUCCESS(acpi_GetInteger(handle, "_SEG", 
))) {
+   acpi_enable_pcie(child, segment);
+   }
+   }
+#endif
AcpiOsFree(devinfo);
}
break;

Added: head/sys/dev/pci/pci_host_generic_acpi.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/sys/dev/pci/pci_host_generic_acpi.cWed Mar  7 10:47:27 2018
(r330575)
@@ -0,0 +1,329 @@
+/*-
+ * Copyright (c) 2015 Ruslan Bukin 
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Semihalf under
+ * the sponsorship of the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the