Skip to content

Commit

Permalink
Import patches from soren
Browse files Browse the repository at this point in the history
  • Loading branch information
monwarez committed Feb 9, 2023
1 parent 01efaef commit 58961e8
Show file tree
Hide file tree
Showing 13 changed files with 2,224 additions and 6 deletions.
1 change: 1 addition & 0 deletions sys/arm64/conf/GENERIC
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ device neta # Marvell Armada 370/38x/XP/3700 NIC
device re # RealTek 8139C+/8169/8169S/8110S
device smc # SMSC LAN91C111
device vnic # Cavium ThunderX NIC
device eqos

# Etherswitch devices
device etherswitch # Enable etherswitch support
Expand Down
1 change: 1 addition & 0 deletions sys/conf/files
Original file line number Diff line number Diff line change
Expand Up @@ -2453,6 +2453,7 @@ dev/mii/icsphy.c optional miibus | icsphy
dev/mii/ip1000phy.c optional miibus | ip1000phy
dev/mii/jmphy.c optional miibus | jmphy
dev/mii/lxtphy.c optional miibus | lxtphy
dev/mii/mcommphy.c optional miibus | mcommphy
dev/mii/micphy.c optional miibus fdt | micphy fdt
dev/mii/mii.c optional miibus | mii
dev/mii/mii_bitbang.c optional miibus | mii_bitbang
Expand Down
8 changes: 7 additions & 1 deletion sys/conf/files.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ dev/acpica/acpi_if.m optional acpi
dev/acpica/acpi_pci_link.c optional acpi pci
dev/acpica/acpi_pcib.c optional acpi pci
dev/acpica/acpi_pxm.c optional acpi
dev/acpica/acpi_subr.c optional acpi

dev/ahci/ahci_generic.c optional ahci

cddl/dev/dtrace/aarch64/dtrace_asm.S optional dtrace compile-with "${DTRACE_S}"
Expand All @@ -168,6 +170,9 @@ dev/cpufreq/cpufreq_dt.c optional cpufreq fdt
dev/dwc/if_dwc.c optional fdt dwc_rk soc_rockchip_rk3328 | fdt dwc_rk soc_rockchip_rk3399 | fdt dwc_socfpga soc_intel_stratix10
dev/dwc/if_dwc_if.m optional fdt dwc_rk soc_rockchip_rk3328 | fdt dwc_rk soc_rockchip_rk3399 | fdt dwc_socfpga soc_intel_stratix10

dev/eqos/eqos.c optional eqos
dev/eqos/eqos_acpi.c optional eqos acpi

dev/gpio/pl061.c optional pl061 gpio
dev/gpio/pl061_acpi.c optional pl061 gpio acpi
dev/gpio/pl061_fdt.c optional pl061 gpio fdt
Expand Down Expand Up @@ -238,7 +243,8 @@ dev/ipmi/ipmi_smic.c optional ipmi

dev/mbox/mbox_if.m optional soc_brcm_bcm2837

dev/mmc/host/dwmmc.c optional dwmmc fdt
dev/mmc/host/dwmmc.c optional dwmmc fdt | acpi
dev/mmc/host/dwmmc_acpi.c optional dwmmc acpi
dev/mmc/host/dwmmc_altera.c optional dwmmc dwmmc_altera fdt
dev/mmc/host/dwmmc_hisi.c optional dwmmc dwmmc_hisi fdt
dev/mmc/host/dwmmc_rockchip.c optional dwmmc rk_dwmmc fdt
Expand Down
140 changes: 140 additions & 0 deletions sys/dev/acpica/acpi_subr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*-
* Copyright (c) 2022 Soren Schmidt <sos@deepcore.dk>
* All rights reserved.
*
* 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 distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/malloc.h>

#include <contrib/dev/acpica/include/acpi.h>

#include <dev/acpica/acpivar.h>

#include "acpi_subr.h"

static MALLOC_DEFINE(M_ACPISUBR, "acpisubr", "ACPI subrutines");

static const uint8_t dsd_uuid[] = {
0x14, 0xd8, 0xff, 0xda, 0xba, 0x6e, 0x8c, 0x4d,
0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01,
};


ACPI_STATUS
acpi_dsd_property(ACPI_HANDLE handle, const char *property, ACPI_BUFFER *buf, ACPI_OBJECT_TYPE type, ACPI_OBJECT **ret)
{
ACPI_OBJECT *prop, *obj, *pobj;
ACPI_STATUS status;
int i;

status = AcpiEvaluateObjectTyped(handle, "_DSD", NULL, buf, ACPI_TYPE_PACKAGE);
if (ACPI_FAILURE(status))
return status;

prop = NULL;
obj = (ACPI_OBJECT *)buf->Pointer;
for (i = 0; i < (obj->Package.Count - 1); i += 2) {
if (obj->Package.Elements[i].Buffer.Length == ACPI_UUID_LENGTH &&
!bcmp(dsd_uuid, obj->Package.Elements[i].Buffer.Pointer, ACPI_UUID_LENGTH)) {
prop = &obj->Package.Elements[i + 1];
break;
}
}
if (!prop)
return AE_NOT_FOUND;

for (i = 0; i < prop->Package.Count; i++) {
pobj = &prop->Package.Elements[i];
if (pobj->Type != ACPI_TYPE_PACKAGE || pobj->Package.Count != 2)
continue;
if (pobj->Package.Elements[0].Type != ACPI_TYPE_STRING)
continue;
if (strcmp(pobj->Package.Elements[0].String.Pointer, property))
continue;

if (pobj->Package.Elements[1].Type == type) {
*ret = &pobj->Package.Elements[1];
return AE_OK;
}
else
return AE_TYPE;
break;
}
return AE_NOT_FOUND;
}

const struct acpi_compat_data *
acpi_dsd_search_compatible(device_t dev, const struct acpi_compat_data *compat)
{
const struct acpi_compat_data *pcompat = NULL;
ACPI_HANDLE handle = acpi_get_handle(dev);
ACPI_OBJECT *obj;
ACPI_BUFFER buf;
ACPI_STATUS status;
int i;

buf.Pointer = NULL;
buf.Length = ACPI_ALLOCATE_BUFFER;

/* single string _DSD */
status = acpi_dsd_property(handle, "compatible", &buf, ACPI_TYPE_STRING, &obj);
if (ACPI_SUCCESS(status)) {
for (pcompat = compat; pcompat->acd_str; pcompat++)
if (!strcmp(obj->String.Pointer, pcompat->acd_str))
break;
goto done;
}

if (buf.Pointer)
AcpiOsFree(buf.Pointer);
buf.Pointer = NULL;
buf.Length = ACPI_ALLOCATE_BUFFER;

/* Package of strings _DSD */
status = acpi_dsd_property(handle, "compatible", &buf, ACPI_TYPE_PACKAGE, &obj);
if (ACPI_FAILURE(status)) {
goto done;
}
if (!obj->Package.Count) {
goto done;
}
for (i = 0; i < obj->Package.Count; i++) {
if (obj->Package.Elements[i].Type != ACPI_TYPE_STRING)
continue;
for (pcompat = compat; pcompat->acd_str; pcompat++)
if (!strcmp(obj->Package.Elements[i].String.Pointer, pcompat->acd_str))
break;
if (pcompat->acd_str)
break;
}
done:
if (buf.Pointer)
AcpiOsFree(buf.Pointer);
return pcompat;
}
37 changes: 37 additions & 0 deletions sys/dev/acpica/acpi_subr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*-
* Copyright (c) 2022 Soren Schmidt <sos@deepcore.dk>
* All rights reserved.
*
* 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 distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

struct acpi_compat_data {
const char *acd_str;
uintptr_t acd_data;
};

ACPI_STATUS acpi_dsd_property(ACPI_HANDLE handle, const char *property, ACPI_BUFFER *buf, ACPI_OBJECT_TYPE type, ACPI_OBJECT **ret);

const struct acpi_compat_data *acpi_dsd_search_compatible(device_t, const struct acpi_compat_data *);

0 comments on commit 58961e8

Please sign in to comment.