sync code with last fixes and improvements from OpenBSD

This commit is contained in:
purplerain 2023-07-27 09:35:44 +00:00
parent 58df21ce75
commit f960599e67
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
399 changed files with 7016 additions and 6902 deletions

View file

@ -1,4 +1,4 @@
# $OpenBSD: GENERIC,v 1.276 2023/07/19 20:27:20 kettenis Exp $
# $OpenBSD: GENERIC,v 1.277 2023/07/22 22:43:53 patrick Exp $
#
# GENERIC machine description file
#
@ -346,6 +346,7 @@ qcpon* at qcpmic?
qcpwm* at qcpmic?
qcrng* at fdt?
qcrtc* at qcpmic?
qcsdam* at qcpmic?
# Sunxi SoCs
sxipio* at fdt? early 1 # GPIO pins for leds & PHYs

View file

@ -1,4 +1,4 @@
# $OpenBSD: RAMDISK,v 1.208 2023/07/19 20:27:20 kettenis Exp $
# $OpenBSD: RAMDISK,v 1.209 2023/07/22 22:43:53 patrick Exp $
machine arm64
maxusers 4
@ -269,6 +269,7 @@ qcpon* at qcpmic?
qcpwm* at qcpmic?
qcrng* at fdt?
qcrtc* at qcpmic?
qcsdam* at qcpmic?
# Sunxi SoCs
sxipio* at fdt? early 1 # GPIO pins for leds & PHYs

View file

@ -1,4 +1,4 @@
/* $OpenBSD: agtimer.c,v 1.22 2023/02/04 19:19:36 cheloha Exp $ */
/* $OpenBSD: agtimer.c,v 1.23 2023/07/25 18:16:19 cheloha Exp $ */
/*
* Copyright (c) 2011 Dale Rahn <drahn@openbsd.org>
* Copyright (c) 2013 Patrick Wildt <patrick@blueri.se>
@ -354,7 +354,6 @@ agtimer_delay(u_int usecs)
void
agtimer_setstatclockrate(int newhz)
{
clockintr_setstatclockrate(newhz);
}
void

View file

@ -1,4 +1,4 @@
/* $OpenBSD: apldart.c,v 1.16 2022/07/21 18:24:24 kettenis Exp $ */
/* $OpenBSD: apldart.c,v 1.17 2023/07/23 11:47:20 kettenis Exp $ */
/*
* Copyright (c) 2021 Mark Kettenis <kettenis@openbsd.org>
*
@ -28,6 +28,7 @@
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_misc.h>
#include <dev/ofw/ofw_power.h>
#include <dev/ofw/fdt.h>
/*
@ -161,6 +162,8 @@ struct apldart_softc {
struct machine_bus_dma_tag sc_bus_dmat;
struct iommu_device sc_id;
int sc_do_suspend;
};
struct apldart_map_state {
@ -187,9 +190,11 @@ void apldart_dmamem_free(bus_dma_tag_t, struct apldart_dmamem *);
int apldart_match(struct device *, void *, void *);
void apldart_attach(struct device *, struct device *, void *);
int apldart_activate(struct device *, int);
const struct cfattach apldart_ca = {
sizeof (struct apldart_softc), apldart_match, apldart_attach
sizeof (struct apldart_softc), apldart_match, apldart_attach, NULL,
apldart_activate
};
struct cfdriver apldart_cd = {
@ -255,8 +260,10 @@ apldart_attach(struct device *parent, struct device *self, void *aux)
}
sc->sc_dmat = faa->fa_dmat;
sc->sc_node = faa->fa_node;
power_domain_enable(sc->sc_node);
if (OF_is_compatible(sc->sc_node, "apple,t8110-dart")) {
params4 = HREAD4(sc, DART_T8110_PARAMS4);
sc->sc_nsid = params4 & DART_T8110_PARAMS4_NSID_MASK;
@ -321,6 +328,11 @@ apldart_attach(struct device *parent, struct device *self, void *aux)
}
}
/*
* We have full control over this DART, so do suspend it.
*/
sc->sc_do_suspend = 1;
/*
* Use bypass mode if supported. This avoids an issue with
* the USB3 controllers which need mappings entered into two
@ -433,6 +445,83 @@ apldart_attach(struct device *parent, struct device *self, void *aux)
iommu_device_register(&sc->sc_id);
}
void
apldart_suspend(struct apldart_softc *sc)
{
if (!sc->sc_do_suspend)
return;
power_domain_disable(sc->sc_node);
}
void
apldart_resume(struct apldart_softc *sc)
{
paddr_t pa;
int ntte, nl1, nl2;
uint32_t params2;
int sid, idx;
if (!sc->sc_do_suspend)
return;
power_domain_enable(sc->sc_node);
params2 = HREAD4(sc, DART_PARAMS2);
if (params2 & DART_PARAMS2_BYPASS_SUPPORT) {
for (sid = 0; sid < sc->sc_nsid; sid++)
HWRITE4(sc, DART_TCR(sc, sid), sc->sc_tcr_bypass);
return;
}
ntte = howmany(sc->sc_dvaend, DART_PAGE_SIZE);
nl2 = howmany(ntte, DART_PAGE_SIZE / sizeof(uint64_t));
nl1 = howmany(nl2, DART_PAGE_SIZE / sizeof(uint64_t));
/* Install page tables. */
for (sid = 0; sid < sc->sc_nsid; sid++) {
pa = APLDART_DMA_DVA(sc->sc_l1);
for (idx = 0; idx < nl1; idx++) {
HWRITE4(sc, DART_TTBR(sc, sid, idx),
(pa >> DART_TTBR_SHIFT) | sc->sc_ttbr_valid);
pa += DART_PAGE_SIZE;
}
}
sc->sc_flush_tlb(sc);
/* Enable all streams. */
for (idx = 0; idx < howmany(sc->sc_nsid, 32); idx++)
HWRITE4(sc, DART_SID_ENABLE(sc, idx), ~0);
/* Enable translations. */
for (sid = 0; sid < sc->sc_nsid; sid++)
HWRITE4(sc, DART_TCR(sc, sid), sc->sc_tcr_translate_enable);
if (OF_is_compatible(sc->sc_node, "apple,t8110-dart")) {
HWRITE4(sc, DART_T8110_ERROR, HREAD4(sc, DART_T8110_ERROR));
HWRITE4(sc, DART_T8110_ERROR_MASK, 0);
} else {
HWRITE4(sc, DART_T8020_ERROR, HREAD4(sc, DART_T8020_ERROR));
}
}
int
apldart_activate(struct device *self, int act)
{
struct apldart_softc *sc = (struct apldart_softc *)self;
switch (act) {
case DVACT_SUSPEND:
apldart_suspend(sc);
break;
case DVACT_RESUME:
apldart_resume(sc);
break;
}
return 0;
}
bus_dma_tag_t
apldart_map(void *cookie, uint32_t *cells, bus_dma_tag_t dmat)
{

View file

@ -1,4 +1,4 @@
/* $OpenBSD: apldma.c,v 1.5 2022/11/26 21:35:22 kettenis Exp $ */
/* $OpenBSD: apldma.c,v 1.6 2023/07/26 11:09:24 kettenis Exp $ */
/*
* Copyright (c) 2022 Mark Kettenis <kettenis@openbsd.org>
*
@ -110,9 +110,11 @@ struct apldma_softc *apldma_sc;
int apldma_match(struct device *, void *, void *);
void apldma_attach(struct device *, struct device *, void *);
int apldma_activate(struct device *, int);
const struct cfattach apldma_ca = {
sizeof (struct apldma_softc), apldma_match, apldma_attach
sizeof (struct apldma_softc), apldma_match, apldma_attach, NULL,
apldma_activate
};
struct cfdriver apldma_cd = {
@ -197,6 +199,23 @@ unmap:
bus_space_unmap(sc->sc_iot, sc->sc_ioh, faa->fa_reg[0].size);
}
int
apldma_activate(struct device *self, int act)
{
struct apldma_softc *sc = (struct apldma_softc *)self;
switch (act) {
case DVACT_SUSPEND:
power_domain_disable(sc->sc_node);
break;
case DVACT_RESUME:
power_domain_enable(sc->sc_node);
break;
}
return 0;
}
void
apldma_fill_descriptors(struct apldma_channel *ac)
{

View file

@ -1,4 +1,4 @@
/* $OpenBSD: aplmbox.c,v 1.5 2022/12/21 22:30:42 kettenis Exp $ */
/* $OpenBSD: aplmbox.c,v 1.6 2023/07/23 11:17:49 kettenis Exp $ */
/*
* Copyright (c) 2021 Mark Kettenis <kettenis@openbsd.org>
*
@ -25,6 +25,7 @@
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_misc.h>
#include <dev/ofw/ofw_power.h>
#include <dev/ofw/fdt.h>
#include <arm64/dev/aplmbox.h>
@ -111,6 +112,8 @@ aplmbox_attach(struct device *parent, struct device *self, void *aux)
printf("\n");
power_domain_enable(faa->fa_node);
sc->sc_md.md_node = faa->fa_node;
sc->sc_md.md_cookie = sc;
sc->sc_md.md_channel = aplmbox_channel;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: aplmca.c,v 1.6 2023/02/03 13:20:21 kettenis Exp $ */
/* $OpenBSD: aplmca.c,v 1.7 2023/07/26 11:09:24 kettenis Exp $ */
/*
* Copyright (c) 2022 Mark Kettenis <kettenis@openbsd.org>
*
@ -152,9 +152,11 @@ const struct audio_hw_if aplmca_hw_if = {
int aplmca_match(struct device *, void *, void *);
void aplmca_attach(struct device *, struct device *, void *);
int aplmca_activate(struct device *, int);
const struct cfattach aplmca_ca = {
sizeof (struct aplmca_softc), aplmca_match, aplmca_attach
sizeof (struct aplmca_softc), aplmca_match, aplmca_attach, NULL,
aplmca_activate
};
struct cfdriver aplmca_cd = {
@ -223,6 +225,32 @@ aplmca_attach(struct device *parent, struct device *self, void *aux)
}
}
int
aplmca_activate(struct device *self, int act)
{
struct aplmca_softc *sc = (struct aplmca_softc *)self;
int i;
switch (act) {
case DVACT_SUSPEND:
for (i = 0; i < sc->sc_nclusters; i++) {
if (sc->sc_ad[i].ad_ac)
power_domain_disable_idx(sc->sc_node, i + 1);
}
power_domain_disable_idx(sc->sc_node, 0);
break;
case DVACT_RESUME:
power_domain_enable_idx(sc->sc_node, 0);
for (i = 0; i < sc->sc_nclusters; i++) {
if (sc->sc_ad[i].ad_ac)
power_domain_enable_idx(sc->sc_node, i + 1);
}
break;
}
return 0;
}
int
aplmca_dai_init(struct aplmca_softc *sc, int port)
{

View file

@ -1,4 +1,4 @@
/* $OpenBSD: aplpinctrl.c,v 1.7 2023/03/23 11:40:42 jsg Exp $ */
/* $OpenBSD: aplpinctrl.c,v 1.8 2023/07/23 11:17:50 kettenis Exp $ */
/*
* Copyright (c) 2021 Mark Kettenis <kettenis@openbsd.org>
*
@ -28,6 +28,7 @@
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_gpio.h>
#include <dev/ofw/ofw_pinctrl.h>
#include <dev/ofw/ofw_power.h>
#include <dev/ofw/fdt.h>
#define APPLE_PIN(pinmux) ((pinmux) & 0xffff)
@ -136,6 +137,8 @@ aplpinctrl_attach(struct device *parent, struct device *self, void *aux)
return;
}
power_domain_enable(faa->fa_node);
pinctrl_register(faa->fa_node, aplpinctrl_pinctrl, sc);
OF_getpropintarray(faa->fa_node, "gpio-ranges",

View file

@ -1,4 +1,4 @@
/* $OpenBSD: aplspi.c,v 1.4 2022/04/06 18:59:26 naddy Exp $ */
/* $OpenBSD: aplspi.c,v 1.5 2023/07/23 11:17:50 kettenis Exp $ */
/*
* Copyright (c) 2021 Mark Kettenis <kettenis@openbsd.org>
*
@ -30,6 +30,7 @@
#include <dev/ofw/ofw_clock.h>
#include <dev/ofw/ofw_gpio.h>
#include <dev/ofw/ofw_pinctrl.h>
#include <dev/ofw/ofw_power.h>
#include <dev/ofw/fdt.h>
#define SPI_CLKCFG 0x00
@ -147,6 +148,7 @@ aplspi_attach(struct device *parent, struct device *self, void *aux)
sc->sc_pfreq = clock_get_frequency(sc->sc_node, NULL);
power_domain_enable(sc->sc_node);
pinctrl_byname(sc->sc_node, "default");
/* Configure CS# pin for manual control. */

View file

@ -1,4 +1,4 @@
/* $OpenBSD: cpu.h,v 1.37 2023/07/13 08:33:36 kettenis Exp $ */
/* $OpenBSD: cpu.h,v 1.38 2023/07/25 18:16:20 cheloha Exp $ */
/*
* Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com>
*
@ -172,6 +172,7 @@ struct cpu_info {
#ifdef GPROF
struct gmonparam *ci_gmon;
struct clockintr *ci_gmonclock;
#endif
struct clockintr_queue ci_queue;
char ci_panicbuf[512];