sync with OpenBSD -current

This commit is contained in:
purplerain 2024-03-21 01:27:27 +00:00
parent caadbe0d20
commit ffd019c293
Signed by: purplerain
GPG Key ID: F42C07F07E2E35B7
50 changed files with 617 additions and 577 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: conf_mod.c,v 1.28 2023/07/20 15:05:30 tb Exp $ */ /* $OpenBSD: conf_mod.c,v 1.36 2024/03/20 22:11:07 tb Exp $ */
/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL /* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
* project 2001. * project 2001.
*/ */
@ -86,7 +86,7 @@ struct conf_module_st {
*/ */
struct conf_imodule_st { struct conf_imodule_st {
CONF_MODULE *pmod; CONF_MODULE *mod;
char *name; char *name;
char *value; char *value;
unsigned long flags; unsigned long flags;
@ -96,14 +96,15 @@ struct conf_imodule_st {
static STACK_OF(CONF_MODULE) *supported_modules = NULL; static STACK_OF(CONF_MODULE) *supported_modules = NULL;
static STACK_OF(CONF_IMODULE) *initialized_modules = NULL; static STACK_OF(CONF_IMODULE) *initialized_modules = NULL;
static void module_free(CONF_MODULE *md); static void module_free(CONF_MODULE *mod);
static void imodule_free(CONF_IMODULE *imod);
static void module_finish(CONF_IMODULE *imod); static void module_finish(CONF_IMODULE *imod);
static int module_run(const CONF *cnf, char *name, char *value, static int module_run(const CONF *cnf, char *name, char *value,
unsigned long flags); unsigned long flags);
static CONF_MODULE *module_add(const char *name, conf_init_func *ifunc, static int module_add(const char *name, conf_init_func *ifunc,
conf_finish_func *ffunc); conf_finish_func *ffunc);
static CONF_MODULE *module_find(char *name); static CONF_MODULE *module_find(char *name);
static int module_init(CONF_MODULE *pmod, char *name, char *value, static int module_init(CONF_MODULE *mod, char *name, char *value,
const CONF *cnf); const CONF *cnf);
/* Main function: load modules from a CONF structure */ /* Main function: load modules from a CONF structure */
@ -188,10 +189,10 @@ err:
static int static int
module_run(const CONF *cnf, char *name, char *value, unsigned long flags) module_run(const CONF *cnf, char *name, char *value, unsigned long flags)
{ {
CONF_MODULE *md; CONF_MODULE *mod;
int ret; int ret;
if ((md = module_find(name)) == NULL) { if ((mod = module_find(name)) == NULL) {
if (!(flags & CONF_MFLAGS_SILENT)) { if (!(flags & CONF_MFLAGS_SILENT)) {
CONFerror(CONF_R_UNKNOWN_MODULE_NAME); CONFerror(CONF_R_UNKNOWN_MODULE_NAME);
ERR_asprintf_error_data("module=%s", name); ERR_asprintf_error_data("module=%s", name);
@ -199,7 +200,7 @@ module_run(const CONF *cnf, char *name, char *value, unsigned long flags)
return -1; return -1;
} }
ret = module_init(md, name, value, cnf); ret = module_init(mod, name, value, cnf);
if (ret <= 0) { if (ret <= 0) {
if (!(flags & CONF_MFLAGS_SILENT)) { if (!(flags & CONF_MFLAGS_SILENT)) {
@ -213,33 +214,37 @@ module_run(const CONF *cnf, char *name, char *value, unsigned long flags)
return ret; return ret;
} }
/* add module to list */ static int
static CONF_MODULE *
module_add(const char *name, conf_init_func *ifunc, conf_finish_func *ffunc) module_add(const char *name, conf_init_func *ifunc, conf_finish_func *ffunc)
{ {
CONF_MODULE *tmod = NULL; CONF_MODULE *mod = NULL;
int ret = 0;
if (name == NULL) if (name == NULL)
return NULL; goto err;
if (supported_modules == NULL) if (supported_modules == NULL)
supported_modules = sk_CONF_MODULE_new_null(); supported_modules = sk_CONF_MODULE_new_null();
if (supported_modules == NULL) if (supported_modules == NULL)
return NULL; goto err;
tmod = malloc(sizeof(CONF_MODULE));
if (tmod == NULL)
return NULL;
tmod->name = strdup(name); if ((mod = calloc(1, sizeof(*mod))) == NULL)
tmod->init = ifunc; goto err;
tmod->finish = ffunc; if ((mod->name = strdup(name)) == NULL)
tmod->links = 0; goto err;
mod->init = ifunc;
mod->finish = ffunc;
if (!sk_CONF_MODULE_push(supported_modules, tmod)) { if (!sk_CONF_MODULE_push(supported_modules, mod))
free(tmod); goto err;
return NULL; mod = NULL;
}
return tmod; ret = 1;
err:
module_free(mod);
return ret;
} }
/* Find a module from the list. We allow module names of the /* Find a module from the list. We allow module names of the
@ -250,7 +255,7 @@ module_add(const char *name, conf_init_func *ifunc, conf_finish_func *ffunc)
static CONF_MODULE * static CONF_MODULE *
module_find(char *name) module_find(char *name)
{ {
CONF_MODULE *tmod; CONF_MODULE *mod;
int i, nchar; int i, nchar;
char *p; char *p;
@ -262,9 +267,9 @@ module_find(char *name)
nchar = strlen(name); nchar = strlen(name);
for (i = 0; i < sk_CONF_MODULE_num(supported_modules); i++) { for (i = 0; i < sk_CONF_MODULE_num(supported_modules); i++) {
tmod = sk_CONF_MODULE_value(supported_modules, i); mod = sk_CONF_MODULE_value(supported_modules, i);
if (!strncmp(tmod->name, name, nchar)) if (!strncmp(mod->name, name, nchar))
return tmod; return mod;
} }
return NULL; return NULL;
@ -272,7 +277,7 @@ module_find(char *name)
/* initialize a module */ /* initialize a module */
static int static int
module_init(CONF_MODULE *pmod, char *name, char *value, const CONF *cnf) module_init(CONF_MODULE *mod, char *name, char *value, const CONF *cnf)
{ {
int ret = 1; int ret = 1;
int init_called = 0; int init_called = 0;
@ -283,7 +288,7 @@ module_init(CONF_MODULE *pmod, char *name, char *value, const CONF *cnf)
if (!imod) if (!imod)
goto err; goto err;
imod->pmod = pmod; imod->mod = mod;
imod->name = name ? strdup(name) : NULL; imod->name = name ? strdup(name) : NULL;
imod->value = value ? strdup(value) : NULL; imod->value = value ? strdup(value) : NULL;
imod->usr_data = NULL; imod->usr_data = NULL;
@ -292,8 +297,8 @@ module_init(CONF_MODULE *pmod, char *name, char *value, const CONF *cnf)
goto memerr; goto memerr;
/* Try to initialize module */ /* Try to initialize module */
if (pmod->init) { if (mod->init) {
ret = pmod->init(imod, cnf); ret = mod->init(imod, cnf);
init_called = 1; init_called = 1;
/* Error occurred, exit */ /* Error occurred, exit */
if (ret <= 0) if (ret <= 0)
@ -313,14 +318,14 @@ module_init(CONF_MODULE *pmod, char *name, char *value, const CONF *cnf)
goto err; goto err;
} }
pmod->links++; mod->links++;
return ret; return ret;
err: err:
/* We've started the module so we'd better finish it */ /* We've started the module so we'd better finish it */
if (pmod->finish && init_called) if (mod->finish && init_called)
pmod->finish(imod); mod->finish(imod);
memerr: memerr:
if (imod) { if (imod) {
@ -341,18 +346,18 @@ void
CONF_modules_unload(int all) CONF_modules_unload(int all)
{ {
int i; int i;
CONF_MODULE *md; CONF_MODULE *mod;
CONF_modules_finish(); CONF_modules_finish();
/* unload modules in reverse order */ /* unload modules in reverse order */
for (i = sk_CONF_MODULE_num(supported_modules) - 1; i >= 0; i--) { for (i = sk_CONF_MODULE_num(supported_modules) - 1; i >= 0; i--) {
md = sk_CONF_MODULE_value(supported_modules, i); mod = sk_CONF_MODULE_value(supported_modules, i);
if (!all) if (!all)
continue; continue;
/* Since we're working in reverse this is OK */ /* Since we're working in reverse this is OK */
(void)sk_CONF_MODULE_delete(supported_modules, i); (void)sk_CONF_MODULE_delete(supported_modules, i);
module_free(md); module_free(mod);
} }
if (sk_CONF_MODULE_num(supported_modules) == 0) { if (sk_CONF_MODULE_num(supported_modules) == 0) {
sk_CONF_MODULE_free(supported_modules); sk_CONF_MODULE_free(supported_modules);
@ -362,10 +367,24 @@ CONF_modules_unload(int all)
/* unload a single module */ /* unload a single module */
static void static void
module_free(CONF_MODULE *md) module_free(CONF_MODULE *mod)
{ {
free(md->name); if (mod == NULL)
free(md); return;
free(mod->name);
free(mod);
}
static void
imodule_free(CONF_IMODULE *imod)
{
if (imod == NULL)
return;
free(imod->name);
free(imod->value);
free(imod);
} }
/* finish and free up all modules instances */ /* finish and free up all modules instances */
@ -388,12 +407,11 @@ CONF_modules_finish(void)
static void static void
module_finish(CONF_IMODULE *imod) module_finish(CONF_IMODULE *imod)
{ {
if (imod->pmod->finish) if (imod->mod->finish)
imod->pmod->finish(imod); imod->mod->finish(imod);
imod->pmod->links--; imod->mod->links--;
free(imod->name);
free(imod->value); imodule_free(imod);
free(imod);
} }
/* Add a static module to OpenSSL */ /* Add a static module to OpenSSL */
@ -401,7 +419,7 @@ module_finish(CONF_IMODULE *imod)
int int
CONF_module_add(const char *name, conf_init_func *ifunc, conf_finish_func *ffunc) CONF_module_add(const char *name, conf_init_func *ifunc, conf_finish_func *ffunc)
{ {
return module_add(name, ifunc, ffunc) != NULL; return module_add(name, ifunc, ffunc);
} }
void void
@ -414,57 +432,57 @@ CONF_modules_free(void)
/* Utility functions */ /* Utility functions */
const char * const char *
CONF_imodule_get_name(const CONF_IMODULE *md) CONF_imodule_get_name(const CONF_IMODULE *imod)
{ {
return md->name; return imod->name;
} }
const char * const char *
CONF_imodule_get_value(const CONF_IMODULE *md) CONF_imodule_get_value(const CONF_IMODULE *imod)
{ {
return md->value; return imod->value;
} }
void * void *
CONF_imodule_get_usr_data(const CONF_IMODULE *md) CONF_imodule_get_usr_data(const CONF_IMODULE *imod)
{ {
return md->usr_data; return imod->usr_data;
} }
void void
CONF_imodule_set_usr_data(CONF_IMODULE *md, void *usr_data) CONF_imodule_set_usr_data(CONF_IMODULE *imod, void *usr_data)
{ {
md->usr_data = usr_data; imod->usr_data = usr_data;
} }
CONF_MODULE * CONF_MODULE *
CONF_imodule_get_module(const CONF_IMODULE *md) CONF_imodule_get_module(const CONF_IMODULE *imod)
{ {
return md->pmod; return imod->mod;
} }
unsigned long unsigned long
CONF_imodule_get_flags(const CONF_IMODULE *md) CONF_imodule_get_flags(const CONF_IMODULE *imod)
{ {
return md->flags; return imod->flags;
} }
void void
CONF_imodule_set_flags(CONF_IMODULE *md, unsigned long flags) CONF_imodule_set_flags(CONF_IMODULE *imod, unsigned long flags)
{ {
md->flags = flags; imod->flags = flags;
} }
void * void *
CONF_module_get_usr_data(CONF_MODULE *pmod) CONF_module_get_usr_data(CONF_MODULE *mod)
{ {
return pmod->usr_data; return mod->usr_data;
} }
void void
CONF_module_set_usr_data(CONF_MODULE *pmod, void *usr_data) CONF_module_set_usr_data(CONF_MODULE *mod, void *usr_data)
{ {
pmod->usr_data = usr_data; mod->usr_data = usr_data;
} }
/* Return default config file name */ /* Return default config file name */

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.3 2022/01/07 09:07:00 tb Exp $ # $OpenBSD: Makefile,v 1.4 2024/03/20 10:38:05 jsing Exp $
PROG= dtlstest PROG= dtlstest
LDADD= ${SSL_INT} -lcrypto LDADD= ${SSL_INT} -lcrypto
@ -11,10 +11,11 @@ CFLAGS+= -I${.CURDIR}/../../../../lib/libssl
REGRESS_TARGETS= \ REGRESS_TARGETS= \
regress-dtlstest regress-dtlstest
# XXX(jsing): use CA root and chain
regress-dtlstest: ${PROG} regress-dtlstest: ${PROG}
./dtlstest \ ./dtlstest \
${.CURDIR}/../../libssl/certs/server.pem \ ${.CURDIR}/../../libssl/certs/server1-rsa.pem \
${.CURDIR}/../../libssl/certs/server.pem \ ${.CURDIR}/../../libssl/certs/server1-rsa.pem \
${.CURDIR}/../../libssl/certs/ca.pem ${.CURDIR}/../../libssl/certs/ca-int-rsa.pem
.include <bsd.regress.mk> .include <bsd.regress.mk>

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.2 2022/10/02 16:40:56 jsing Exp $ # $OpenBSD: Makefile,v 1.3 2024/03/20 10:38:05 jsing Exp $
PROG= quictest PROG= quictest
LDADD= -lssl -lcrypto LDADD= -lssl -lcrypto
@ -12,8 +12,8 @@ REGRESS_TARGETS= \
regress-quictest: ${PROG} regress-quictest: ${PROG}
./quictest \ ./quictest \
${.CURDIR}/../../libssl/certs/server.pem \ ${.CURDIR}/../../libssl/certs/server1-rsa.pem \
${.CURDIR}/../../libssl/certs/server.pem \ ${.CURDIR}/../../libssl/certs/server1-rsa-chain.pem \
${.CURDIR}/../../libssl/certs/ca.pem ${.CURDIR}/../../libssl/certs/ca-root-rsa.pem
.include <bsd.regress.mk> .include <bsd.regress.mk>

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.2 2020/05/11 18:18:21 jsing Exp $ # $OpenBSD: Makefile,v 1.3 2024/03/20 10:38:05 jsing Exp $
PROG= servertest PROG= servertest
LDADD= ${SSL_INT} -lcrypto LDADD= ${SSL_INT} -lcrypto
@ -11,8 +11,8 @@ REGRESS_TARGETS= \
regress-servertest: ${PROG} regress-servertest: ${PROG}
./servertest \ ./servertest \
${.CURDIR}/../../libssl/certs/server.pem \ ${.CURDIR}/../../libssl/certs/server1-rsa.pem \
${.CURDIR}/../../libssl/certs/server.pem \ ${.CURDIR}/../../libssl/certs/server1-rsa-chain.pem \
${.CURDIR}/../../libssl/certs/ca.pem ${.CURDIR}/../../libssl/certs/ca-root-rsa.pem
.include <bsd.regress.mk> .include <bsd.regress.mk>

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.1 2024/01/19 08:29:08 jsing Exp $ # $OpenBSD: Makefile,v 1.2 2024/03/20 10:38:05 jsing Exp $
PROG= shutdowntest PROG= shutdowntest
LDADD= -lssl -lcrypto LDADD= -lssl -lcrypto
@ -11,8 +11,8 @@ REGRESS_TARGETS= \
regress-shutdowntest: ${PROG} regress-shutdowntest: ${PROG}
./shutdowntest \ ./shutdowntest \
${.CURDIR}/../../libssl/certs/server.pem \ ${.CURDIR}/../../libssl/certs/server1-rsa.pem \
${.CURDIR}/../../libssl/certs/server.pem \ ${.CURDIR}/../../libssl/certs/server1-rsa-chain.pem \
${.CURDIR}/../../libssl/certs/ca.pem ${.CURDIR}/../../libssl/certs/ca-root-rsa.pem
.include <bsd.regress.mk> .include <bsd.regress.mk>

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.1 2021/10/23 14:34:10 jsing Exp $ # $OpenBSD: Makefile,v 1.2 2024/03/20 10:38:05 jsing Exp $
PROG= tlstest PROG= tlstest
LDADD= -lssl -lcrypto LDADD= -lssl -lcrypto
@ -11,8 +11,8 @@ REGRESS_TARGETS= \
regress-tlstest: ${PROG} regress-tlstest: ${PROG}
./tlstest \ ./tlstest \
${.CURDIR}/../../libssl/certs/server.pem \ ${.CURDIR}/../../libssl/certs/server1-rsa.pem \
${.CURDIR}/../../libssl/certs/server.pem \ ${.CURDIR}/../../libssl/certs/server1-rsa-chain.pem \
${.CURDIR}/../../libssl/certs/ca.pem ${.CURDIR}/../../libssl/certs/ca-root-rsa.pem
.include <bsd.regress.mk> .include <bsd.regress.mk>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ssl_get_shared_ciphers.c,v 1.11 2022/02/05 18:19:39 tb Exp $ */ /* $OpenBSD: ssl_get_shared_ciphers.c,v 1.12 2024/03/20 10:38:05 jsing Exp $ */
/* /*
* Copyright (c) 2021 Theo Buehler <tb@openbsd.org> * Copyright (c) 2021 Theo Buehler <tb@openbsd.org>
* *
@ -462,7 +462,7 @@ main(int argc, char **argv)
size_t i; size_t i;
int failed = 0; int failed = 0;
if (asprintf(&server_cert, "%s/server.pem", CERTSDIR) == -1) { if (asprintf(&server_cert, "%s/server1-rsa.pem", CERTSDIR) == -1) {
fprintf(stderr, "asprintf server_cert failed\n"); fprintf(stderr, "asprintf server_cert failed\n");
failed = 1; failed = 1;
goto err; goto err;

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.1 2018/02/08 10:06:52 jsing Exp $ # $OpenBSD: Makefile,v 1.2 2024/03/20 10:38:05 jsing Exp $
PROG= keypairtest PROG= keypairtest
LDADD= -lcrypto -lssl ${TLS_INT} LDADD= -lcrypto -lssl ${TLS_INT}
@ -13,8 +13,8 @@ REGRESS_TARGETS= \
regress-keypairtest: ${PROG} regress-keypairtest: ${PROG}
./keypairtest \ ./keypairtest \
${.CURDIR}/../../libssl/certs/ca.pem \ ${.CURDIR}/../../libssl/certs/ca-root-rsa.pem \
${.CURDIR}/../../libssl/certs/server.pem \ ${.CURDIR}/../../libssl/certs/server1-rsa.pem \
${.CURDIR}/../../libssl/certs/server.pem ${.CURDIR}/../../libssl/certs/server1-rsa.pem
.include <bsd.regress.mk> .include <bsd.regress.mk>

View File

@ -1,4 +1,4 @@
/* $OpenBSD: keypairtest.c,v 1.6 2022/02/08 18:05:57 tb Exp $ */ /* $OpenBSD: keypairtest.c,v 1.7 2024/03/20 10:38:05 jsing Exp $ */
/* /*
* Copyright (c) 2018 Joel Sing <jsing@openbsd.org> * Copyright (c) 2018 Joel Sing <jsing@openbsd.org>
* *
@ -29,7 +29,7 @@
#include <tls_internal.h> #include <tls_internal.h>
#define PUBKEY_HASH \ #define PUBKEY_HASH \
"SHA256:858d0f94beb0a08eb4f13871ba57bf0a2e081287d0efbaeb3bbac59dd8f1a8e5" "SHA256:f03c535d374614e7356c0a4e6fd37fe94297b60ed86212adcba40e8e0b07bc9f"
char *cert_file, *key_file, *ocsp_staple_file; char *cert_file, *key_file, *ocsp_staple_file;

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.2 2017/05/06 21:56:43 jsing Exp $ # $OpenBSD: Makefile,v 1.3 2024/03/20 10:38:05 jsing Exp $
PROG= tlstest PROG= tlstest
LDADD= -lcrypto -lssl -ltls LDADD= -lcrypto -lssl -ltls
@ -12,8 +12,8 @@ REGRESS_TARGETS= \
regress-tlstest: ${PROG} regress-tlstest: ${PROG}
./tlstest \ ./tlstest \
${.CURDIR}/../../libssl/certs/ca.pem \ ${.CURDIR}/../../libssl/certs/ca-root-rsa.pem \
${.CURDIR}/../../libssl/certs/server.pem \ ${.CURDIR}/../../libssl/certs/server1-rsa-chain.pem \
${.CURDIR}/../../libssl/certs/server.pem ${.CURDIR}/../../libssl/certs/server1-rsa.pem
.include <bsd.regress.mk> .include <bsd.regress.mk>

View File

@ -1,4 +1,4 @@
/* $Id: test-aspa.c,v 1.6 2023/09/25 11:09:30 tb Exp $ */ /* $Id: test-aspa.c,v 1.7 2024/03/20 04:39:10 job Exp $ */
/* /*
* Copyright (c) 2022 Job Snijders <job@fastly.com> * Copyright (c) 2022 Job Snijders <job@fastly.com>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@ -33,7 +33,7 @@
int outformats; int outformats;
int verbose; int verbose;
int filemode; int filemode = 1;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])

View File

@ -1,4 +1,4 @@
/* $Id: test-gbr.c,v 1.16 2023/09/25 11:09:30 tb Exp $ */ /* $Id: test-gbr.c,v 1.17 2024/03/20 04:39:10 job Exp $ */
/* /*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
* *
@ -32,7 +32,7 @@
int outformats; int outformats;
int verbose; int verbose;
int filemode; int filemode = 1;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])

View File

@ -1,4 +1,4 @@
/* $Id: test-mft.c,v 1.27 2023/09/25 11:09:30 tb Exp $ */ /* $Id: test-mft.c,v 1.28 2024/03/20 04:39:10 job Exp $ */
/* /*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
* *
@ -35,7 +35,7 @@
int outformats; int outformats;
int verbose; int verbose;
int filemode; int filemode = 1;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])

View File

@ -1,4 +1,4 @@
/* $Id: test-roa.c,v 1.24 2023/09/25 11:09:30 tb Exp $ */ /* $Id: test-roa.c,v 1.25 2024/03/20 04:39:10 job Exp $ */
/* /*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
* *
@ -32,7 +32,7 @@
int outformats; int outformats;
int verbose; int verbose;
int filemode; int filemode = 1;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])

View File

@ -1,4 +1,4 @@
/* $Id: test-spl.c,v 1.1 2024/02/22 12:51:50 job Exp $ */ /* $Id: test-spl.c,v 1.2 2024/03/20 04:39:10 job Exp $ */
/* /*
* Copyright (c) 2024 Job Snijders <job@fastly.com> * Copyright (c) 2024 Job Snijders <job@fastly.com>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@ -33,7 +33,7 @@
int outformats; int outformats;
int verbose; int verbose;
int filemode; int filemode = 1;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])

View File

@ -1,4 +1,4 @@
/* $Id: test-tak.c,v 1.6 2023/09/25 11:09:30 tb Exp $ */ /* $Id: test-tak.c,v 1.7 2024/03/20 04:39:10 job Exp $ */
/* /*
* Copyright (c) 2022 Job Snijders <job@fastly.com> * Copyright (c) 2022 Job Snijders <job@fastly.com>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@ -33,7 +33,7 @@
int outformats; int outformats;
int verbose; int verbose;
int filemode; int filemode = 1;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])

View File

@ -1,4 +1,4 @@
/* $OpenBSD: drm_linux.c,v 1.109 2024/01/21 13:36:40 kettenis Exp $ */ /* $OpenBSD: drm_linux.c,v 1.111 2024/03/20 02:42:17 jsg Exp $ */
/* /*
* Copyright (c) 2013 Jonathan Gray <jsg@openbsd.org> * Copyright (c) 2013 Jonathan Gray <jsg@openbsd.org>
* Copyright (c) 2015, 2016 Mark Kettenis <kettenis@openbsd.org> * Copyright (c) 2015, 2016 Mark Kettenis <kettenis@openbsd.org>
@ -673,6 +673,28 @@ vmap(struct vm_page **pages, unsigned int npages, unsigned long flags,
return (void *)va; return (void *)va;
} }
void *
vmap_pfn(unsigned long *pfns, unsigned int npfn, pgprot_t prot)
{
vaddr_t va;
paddr_t pa;
int i;
va = (vaddr_t)km_alloc(PAGE_SIZE * npfn, &kv_any, &kp_none,
&kd_nowait);
if (va == 0)
return NULL;
for (i = 0; i < npfn; i++) {
pa = round_page(pfns[i]) | prot;
pmap_enter(pmap_kernel(), va + (i * PAGE_SIZE), pa,
PROT_READ | PROT_WRITE,
PROT_READ | PROT_WRITE | PMAP_WIRED);
pmap_update(pmap_kernel());
}
return (void *)va;
}
void void
vunmap(void *addr, size_t size) vunmap(void *addr, size_t size)
{ {
@ -1302,7 +1324,8 @@ vga_disable_bridge(struct pci_attach_args *pa)
void void
vga_get_uninterruptible(struct pci_dev *pdev, int rsrc) vga_get_uninterruptible(struct pci_dev *pdev, int rsrc)
{ {
KASSERT(pdev->pci->sc_bridgetag == NULL); if (pdev->pci->sc_bridgetag != NULL)
return;
pci_enumerate_bus(pdev->pci, vga_disable_bridge, NULL); pci_enumerate_bus(pdev->pci, vga_disable_bridge, NULL);
} }

View File

@ -11,9 +11,6 @@
#include <drm/drm_syncobj.h> #include <drm/drm_syncobj.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/agpvar.h>
#include "display/intel_frontbuffer.h" #include "display/intel_frontbuffer.h"
#include "gem/i915_gem_ioctls.h" #include "gem/i915_gem_ioctls.h"
@ -294,10 +291,6 @@ struct i915_execbuffer {
bool has_llc : 1; bool has_llc : 1;
bool has_fence : 1; bool has_fence : 1;
bool needs_unfenced : 1; bool needs_unfenced : 1;
struct agp_map *map;
bus_space_tag_t iot;
bus_space_handle_t ioh;
} reloc_cache; } reloc_cache;
u64 invalid_flags; /** Set of execobj.flags that are invalid */ u64 invalid_flags; /** Set of execobj.flags that are invalid */
@ -1133,9 +1126,6 @@ static void reloc_cache_init(struct reloc_cache *cache,
cache->has_fence = cache->graphics_ver < 4; cache->has_fence = cache->graphics_ver < 4;
cache->needs_unfenced = INTEL_INFO(i915)->unfenced_needs_alignment; cache->needs_unfenced = INTEL_INFO(i915)->unfenced_needs_alignment;
cache->node.flags = 0; cache->node.flags = 0;
cache->map = i915->agph;
cache->iot = i915->bst;
} }
static inline void *unmask_page(unsigned long p) static inline void *unmask_page(unsigned long p)
@ -1168,11 +1158,7 @@ static void reloc_cache_unmap(struct reloc_cache *cache)
if (cache->vaddr & KMAP) if (cache->vaddr & KMAP)
kunmap_atomic(vaddr); kunmap_atomic(vaddr);
else else
#ifdef __linux__
io_mapping_unmap_atomic((void __iomem *)vaddr); io_mapping_unmap_atomic((void __iomem *)vaddr);
#else
agp_unmap_atomic(cache->map, cache->ioh);
#endif
} }
static void reloc_cache_remap(struct reloc_cache *cache, static void reloc_cache_remap(struct reloc_cache *cache,
@ -1197,14 +1183,8 @@ static void reloc_cache_remap(struct reloc_cache *cache,
if (!drm_mm_node_allocated(&cache->node)) if (!drm_mm_node_allocated(&cache->node))
offset += cache->page << PAGE_SHIFT; offset += cache->page << PAGE_SHIFT;
#ifdef __linux__
cache->vaddr = (unsigned long) cache->vaddr = (unsigned long)
io_mapping_map_atomic_wc(&ggtt->iomap, offset); io_mapping_map_atomic_wc(&ggtt->iomap, offset);
#else
agp_map_atomic(cache->map, offset, &cache->ioh);
cache->vaddr = (unsigned long)
bus_space_vaddr(cache->iot, cache->ioh);
#endif
} }
} }
@ -1228,11 +1208,7 @@ static void reloc_cache_reset(struct reloc_cache *cache, struct i915_execbuffer
struct i915_ggtt *ggtt = cache_to_ggtt(cache); struct i915_ggtt *ggtt = cache_to_ggtt(cache);
intel_gt_flush_ggtt_writes(ggtt->vm.gt); intel_gt_flush_ggtt_writes(ggtt->vm.gt);
#ifdef __linux__
io_mapping_unmap_atomic((void __iomem *)vaddr); io_mapping_unmap_atomic((void __iomem *)vaddr);
#else
agp_unmap_atomic(cache->map, cache->ioh);
#endif
if (drm_mm_node_allocated(&cache->node)) { if (drm_mm_node_allocated(&cache->node)) {
ggtt->vm.clear_range(&ggtt->vm, ggtt->vm.clear_range(&ggtt->vm,
@ -1299,11 +1275,7 @@ static void *reloc_iomap(struct i915_vma *batch,
if (cache->vaddr) { if (cache->vaddr) {
intel_gt_flush_ggtt_writes(ggtt->vm.gt); intel_gt_flush_ggtt_writes(ggtt->vm.gt);
#ifdef __linux__
io_mapping_unmap_atomic((void __force __iomem *) unmask_page(cache->vaddr)); io_mapping_unmap_atomic((void __force __iomem *) unmask_page(cache->vaddr));
#else
agp_unmap_atomic(cache->map, cache->ioh);
#endif
} else { } else {
struct i915_vma *vma = ERR_PTR(-ENODEV); struct i915_vma *vma = ERR_PTR(-ENODEV);
int err; int err;
@ -1365,13 +1337,8 @@ static void *reloc_iomap(struct i915_vma *batch,
offset += page << PAGE_SHIFT; offset += page << PAGE_SHIFT;
} }
#ifdef __linux__
vaddr = (void __force *)io_mapping_map_atomic_wc(&ggtt->iomap, vaddr = (void __force *)io_mapping_map_atomic_wc(&ggtt->iomap,
offset); offset);
#else
agp_map_atomic(cache->map, offset, &cache->ioh);
vaddr = bus_space_vaddr(cache->iot, cache->ioh);
#endif
cache->page = page; cache->page = page;
cache->vaddr = (unsigned long)vaddr; cache->vaddr = (unsigned long)vaddr;

View File

@ -15,9 +15,6 @@ i915_gem_object_lmem_io_map(struct drm_i915_gem_object *obj,
unsigned long n, unsigned long n,
unsigned long size) unsigned long size)
{ {
STUB();
return NULL;
#ifdef notyet
resource_size_t offset; resource_size_t offset;
GEM_BUG_ON(!i915_gem_object_is_contiguous(obj)); GEM_BUG_ON(!i915_gem_object_is_contiguous(obj));
@ -26,7 +23,6 @@ i915_gem_object_lmem_io_map(struct drm_i915_gem_object *obj,
offset -= obj->mm.region->region.start; offset -= obj->mm.region->region.start;
return io_mapping_map_wc(&obj->mm.region->iomap, offset, size); return io_mapping_map_wc(&obj->mm.region->iomap, offset, size);
#endif
} }
/** /**

View File

@ -521,8 +521,6 @@ i915_gem_object_read_from_page_kmap(struct drm_i915_gem_object *obj, u64 offset,
static void static void
i915_gem_object_read_from_page_iomap(struct drm_i915_gem_object *obj, u64 offset, void *dst, int size) i915_gem_object_read_from_page_iomap(struct drm_i915_gem_object *obj, u64 offset, void *dst, int size)
{ {
STUB();
#ifdef notyet
pgoff_t idx = offset >> PAGE_SHIFT; pgoff_t idx = offset >> PAGE_SHIFT;
dma_addr_t dma = i915_gem_object_get_dma_address(obj, idx); dma_addr_t dma = i915_gem_object_get_dma_address(obj, idx);
void __iomem *src_map; void __iomem *src_map;
@ -537,7 +535,6 @@ i915_gem_object_read_from_page_iomap(struct drm_i915_gem_object *obj, u64 offset
memcpy_fromio(dst, src_ptr, size); memcpy_fromio(dst, src_ptr, size);
io_mapping_unmap(src_map); io_mapping_unmap(src_map);
#endif
} }
static bool object_has_mappable_iomem(struct drm_i915_gem_object *obj) static bool object_has_mappable_iomem(struct drm_i915_gem_object *obj)

View File

@ -329,9 +329,6 @@ static void *i915_gem_object_map_page(struct drm_i915_gem_object *obj,
static void *i915_gem_object_map_pfn(struct drm_i915_gem_object *obj, static void *i915_gem_object_map_pfn(struct drm_i915_gem_object *obj,
enum i915_map_type type) enum i915_map_type type)
{ {
STUB();
return NULL;
#ifdef notyet
resource_size_t iomap = obj->mm.region->iomap.base - resource_size_t iomap = obj->mm.region->iomap.base -
obj->mm.region->region.start; obj->mm.region->region.start;
unsigned long n_pfn = obj->base.size >> PAGE_SHIFT; unsigned long n_pfn = obj->base.size >> PAGE_SHIFT;
@ -357,76 +354,6 @@ static void *i915_gem_object_map_pfn(struct drm_i915_gem_object *obj,
kvfree(pfns); kvfree(pfns);
return vaddr ?: ERR_PTR(-ENOMEM); return vaddr ?: ERR_PTR(-ENOMEM);
#endif
}
static void *i915_gem_object_map(struct drm_i915_gem_object *obj,
enum i915_map_type type)
{
unsigned long n_pages = obj->base.size >> PAGE_SHIFT;
struct sg_table *sgt = obj->mm.pages;
struct vm_page *stack_pages[32];
struct vm_page **pages = stack_pages;
struct vm_struct *area;
pgprot_t pgprot;
void *addr;
if (!i915_gem_object_has_struct_page(obj) && type != I915_MAP_WC)
return NULL;
#if 0
/* A single page can always be kmapped */
if (n_pages == 1 && type == I915_MAP_WB)
return kmap(sg_page(sgt->sgl));
#endif
if (n_pages > ARRAY_SIZE(stack_pages)) {
/* Too big for stack -- allocate temporary array instead */
pages = kvmalloc_array(n_pages, sizeof(*pages), GFP_KERNEL);
if (!pages)
return NULL;
}
switch (type) {
default:
MISSING_CASE(type);
/* fallthrough - to use PAGE_KERNEL anyway */
case I915_MAP_WB:
pgprot = PAGE_KERNEL;
break;
case I915_MAP_WC:
pgprot = pgprot_writecombine(PAGE_KERNEL_IO);
break;
}
if (i915_gem_object_has_struct_page(obj)) {
struct sgt_iter iter;
struct vm_page *page;
unsigned long i = 0;
for_each_sgt_page(page, iter, sgt)
pages[i++] = page;
} else {
STUB();
#ifdef notyet
resource_size_t iomap;
struct sgt_iter iter;
pte_t **ptes = mem;
dma_addr_t addr;
iomap = obj->mm.region->iomap.base;
iomap -= obj->mm.region->region.start;
for_each_sgt_daddr(addr, iter, sgt)
**ptes++ = iomap_pte(iomap, addr, pgprot);
#endif
}
addr = vmap(pages, n_pages, 0, pgprot);
if (pages != stack_pages)
kvfree(pages);
return addr;
} }
/* get, pin, and map the pages of the object into kernel space */ /* get, pin, and map the pages of the object into kernel space */

View File

@ -821,19 +821,41 @@ static int init_stolen_lmem(struct intel_memory_region *mem)
return 0; return 0;
} }
STUB(); #ifdef __linux__
return -ENOSYS;
#ifdef notyet
if (mem->io_size && if (mem->io_size &&
!io_mapping_init_wc(&mem->iomap, mem->io_start, mem->io_size)) !io_mapping_init_wc(&mem->iomap, mem->io_start, mem->io_size))
goto err_cleanup; goto err_cleanup;
#else
if (mem->io_size) {
paddr_t start, end;
struct vm_page *pgs;
int i;
bus_space_handle_t bsh;
start = atop(mem->io_start);
end = start + atop(mem->io_size);
uvm_page_physload(start, end, start, end, PHYSLOAD_DEVICE);
pgs = PHYS_TO_VM_PAGE(mem->io_start);
for (i = 0; i < atop(mem->io_size); i++)
atomic_setbits_int(&(pgs[i].pg_flags), PG_PMAP_WC);
if (bus_space_map(i915->bst, mem->io_start, mem->io_size,
BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE, &bsh))
panic("can't map stolen lmem");
mem->iomap.base = mem->io_start;
mem->iomap.size = mem->io_size;
mem->iomap.iomem = bus_space_vaddr(i915->bst, bsh);
}
#endif
drm_dbg(&i915->drm, "Stolen Local memory IO start: %pa\n", drm_dbg(&i915->drm, "Stolen Local memory IO start: %pa\n",
&mem->io_start); &mem->io_start);
drm_dbg(&i915->drm, "Stolen Local DSM base: %pa\n", &mem->region.start); drm_dbg(&i915->drm, "Stolen Local DSM base: %pa\n", &mem->region.start);
return 0; return 0;
#ifdef __linux__
err_cleanup: err_cleanup:
i915_gem_cleanup_stolen(mem->i915); i915_gem_cleanup_stolen(mem->i915);
return err; return err;

View File

@ -715,9 +715,6 @@ static int i915_ttm_io_mem_reserve(struct ttm_device *bdev, struct ttm_resource
static unsigned long i915_ttm_io_mem_pfn(struct ttm_buffer_object *bo, static unsigned long i915_ttm_io_mem_pfn(struct ttm_buffer_object *bo,
unsigned long page_offset) unsigned long page_offset)
{ {
STUB();
return 0;
#ifdef notyet
struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo); struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
struct scatterlist *sg; struct scatterlist *sg;
unsigned long base; unsigned long base;
@ -730,7 +727,6 @@ static unsigned long i915_ttm_io_mem_pfn(struct ttm_buffer_object *bo,
sg = i915_gem_object_page_iter_get_sg(obj, &obj->ttm.get_io_page, page_offset, &ofs); sg = i915_gem_object_page_iter_get_sg(obj, &obj->ttm.get_io_page, page_offset, &ofs);
return ((base + sg_dma_address(sg)) >> PAGE_SHIFT) + ofs; return ((base + sg_dma_address(sg)) >> PAGE_SHIFT) + ofs;
#endif
} }
static int i915_ttm_access_memory(struct ttm_buffer_object *bo, static int i915_ttm_access_memory(struct ttm_buffer_object *bo,

View File

@ -272,6 +272,7 @@ struct i915_ttm_memcpy_arg {
bool clear; bool clear;
struct i915_refct_sgt *src_rsgt; struct i915_refct_sgt *src_rsgt;
struct i915_refct_sgt *dst_rsgt; struct i915_refct_sgt *dst_rsgt;
bus_space_tag_t memt;
}; };
/** /**
@ -304,11 +305,8 @@ struct i915_ttm_memcpy_work {
static void i915_ttm_move_memcpy(struct i915_ttm_memcpy_arg *arg) static void i915_ttm_move_memcpy(struct i915_ttm_memcpy_arg *arg)
{ {
STUB();
#ifdef notyet
ttm_move_memcpy(arg->clear, arg->num_pages, ttm_move_memcpy(arg->clear, arg->num_pages,
arg->dst_iter, arg->src_iter); arg->dst_iter, arg->src_iter, arg->memt);
#endif
} }
static void i915_ttm_memcpy_init(struct i915_ttm_memcpy_arg *arg, static void i915_ttm_memcpy_init(struct i915_ttm_memcpy_arg *arg,
@ -317,8 +315,6 @@ static void i915_ttm_memcpy_init(struct i915_ttm_memcpy_arg *arg,
struct ttm_tt *dst_ttm, struct ttm_tt *dst_ttm,
struct i915_refct_sgt *dst_rsgt) struct i915_refct_sgt *dst_rsgt)
{ {
STUB();
#ifdef notyet
struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo); struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
struct intel_memory_region *dst_reg, *src_reg; struct intel_memory_region *dst_reg, *src_reg;
@ -342,7 +338,8 @@ static void i915_ttm_memcpy_init(struct i915_ttm_memcpy_arg *arg,
arg->dst_rsgt = i915_refct_sgt_get(dst_rsgt); arg->dst_rsgt = i915_refct_sgt_get(dst_rsgt);
arg->src_rsgt = clear ? NULL : arg->src_rsgt = clear ? NULL :
i915_ttm_resource_get_st(obj, bo->resource); i915_ttm_resource_get_st(obj, bo->resource);
#endif
arg->memt = bo->bdev->memt;
} }
static void i915_ttm_memcpy_release(struct i915_ttm_memcpy_arg *arg) static void i915_ttm_memcpy_release(struct i915_ttm_memcpy_arg *arg)

View File

@ -28,9 +28,6 @@
#include "intel_gtt.h" #include "intel_gtt.h"
#include "gen8_ppgtt.h" #include "gen8_ppgtt.h"
#include <dev/pci/pcivar.h>
#include <dev/pci/agpvar.h>
static void i915_ggtt_color_adjust(const struct drm_mm_node *node, static void i915_ggtt_color_adjust(const struct drm_mm_node *node,
unsigned long color, unsigned long color,
u64 *start, u64 *start,
@ -53,7 +50,6 @@ static void i915_ggtt_color_adjust(const struct drm_mm_node *node,
static int ggtt_init_hw(struct i915_ggtt *ggtt) static int ggtt_init_hw(struct i915_ggtt *ggtt)
{ {
struct drm_i915_private *i915 = ggtt->vm.i915; struct drm_i915_private *i915 = ggtt->vm.i915;
int i;
i915_address_space_init(&ggtt->vm, VM_CLASS_GGTT); i915_address_space_init(&ggtt->vm, VM_CLASS_GGTT);
@ -77,6 +73,9 @@ static int ggtt_init_hw(struct i915_ggtt *ggtt)
ggtt->mtrr = arch_phys_wc_add(ggtt->gmadr.start, ggtt->mtrr = arch_phys_wc_add(ggtt->gmadr.start,
ggtt->mappable_end); ggtt->mappable_end);
#else #else
bus_space_handle_t bsh;
int i;
/* XXX would be a lot nicer to get agp info before now */ /* XXX would be a lot nicer to get agp info before now */
uvm_page_physload(atop(ggtt->gmadr.start), uvm_page_physload(atop(ggtt->gmadr.start),
atop(ggtt->gmadr.start + ggtt->mappable_end), atop(ggtt->gmadr.start + ggtt->mappable_end),
@ -94,11 +93,13 @@ static int ggtt_init_hw(struct i915_ggtt *ggtt)
for (i = 0; i < atop(ggtt->mappable_end); i++) for (i = 0; i < atop(ggtt->mappable_end); i++)
atomic_setbits_int(&(i915->pgs[i].pg_flags), atomic_setbits_int(&(i915->pgs[i].pg_flags),
PG_PMAP_WC); PG_PMAP_WC);
if (agp_init_map(i915->bst, ggtt->gmadr.start, if (bus_space_map(i915->bst, ggtt->gmadr.start,
ggtt->mappable_end, ggtt->mappable_end,
BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE, BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE, &bsh))
&i915->agph))
panic("can't map aperture"); panic("can't map aperture");
ggtt->iomap.base = ggtt->gmadr.start;
ggtt->iomap.size = ggtt->mappable_end;
ggtt->iomap.iomem = bus_space_vaddr(i915->bst, bsh);
#endif #endif
} }

View File

@ -358,9 +358,7 @@ struct i915_address_space {
struct i915_ggtt { struct i915_ggtt {
struct i915_address_space vm; struct i915_address_space vm;
#ifdef notyet
struct io_mapping iomap; /* Mapping to our CPU mappable region */ struct io_mapping iomap; /* Mapping to our CPU mappable region */
#endif
struct resource gmadr; /* GMADR resource */ struct resource gmadr; /* GMADR resource */
resource_size_t mappable_end; /* End offset that we can CPU map */ resource_size_t mappable_end; /* End offset that we can CPU map */

View File

@ -153,15 +153,36 @@ region_lmem_release(struct intel_memory_region *mem)
static int static int
region_lmem_init(struct intel_memory_region *mem) region_lmem_init(struct intel_memory_region *mem)
{ {
STUB();
return -ENOSYS;
#ifdef notyet
int ret; int ret;
#ifdef __linux__
if (!io_mapping_init_wc(&mem->iomap, if (!io_mapping_init_wc(&mem->iomap,
mem->io_start, mem->io_start,
mem->io_size)) mem->io_size))
return -EIO; return -EIO;
#else
struct drm_i915_private *i915 = mem->i915;
paddr_t start, end;
struct vm_page *pgs;
int i;
bus_space_handle_t bsh;
start = atop(mem->io_start);
end = start + atop(mem->io_size);
uvm_page_physload(start, end, start, end, PHYSLOAD_DEVICE);
pgs = PHYS_TO_VM_PAGE(mem->io_start);
for (i = 0; i < atop(mem->io_size); i++)
atomic_setbits_int(&(pgs[i].pg_flags), PG_PMAP_WC);
if (bus_space_map(i915->bst, mem->io_start, mem->io_size,
BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE, &bsh))
panic("can't map lmem");
mem->iomap.base = mem->io_start;
mem->iomap.size = mem->io_size;
mem->iomap.iomem = bus_space_vaddr(i915->bst, bsh);
#endif
ret = intel_region_ttm_init(mem); ret = intel_region_ttm_init(mem);
if (ret) if (ret)
@ -170,10 +191,11 @@ region_lmem_init(struct intel_memory_region *mem)
return 0; return 0;
out_no_buddy: out_no_buddy:
#ifdef __linux__
io_mapping_fini(&mem->iomap); io_mapping_fini(&mem->iomap);
#endif
return ret; return ret;
#endif
} }
static const struct intel_memory_region_ops intel_region_lmem_ops = { static const struct intel_memory_region_ops intel_region_lmem_ops = {

View File

@ -190,8 +190,6 @@ xehp_load_dss_mask(struct intel_uncore *uncore,
int numregs, int numregs,
...) ...)
{ {
STUB();
#ifdef notyet
va_list argp; va_list argp;
u32 fuse_val[I915_MAX_SS_FUSE_REGS] = {}; u32 fuse_val[I915_MAX_SS_FUSE_REGS] = {};
int i; int i;
@ -205,7 +203,6 @@ xehp_load_dss_mask(struct intel_uncore *uncore,
va_end(argp); va_end(argp);
bitmap_from_arr32(ssmask->xehp, fuse_val, numregs * 32); bitmap_from_arr32(ssmask->xehp, fuse_val, numregs * 32);
#endif
} }
static void xehp_sseu_info_init(struct intel_gt *gt) static void xehp_sseu_info_init(struct intel_gt *gt)

View File

@ -248,6 +248,12 @@ static int i915_driver_early_probe(struct drm_i915_private *dev_priv)
if (ret < 0) if (ret < 0)
goto err_workqueues; goto err_workqueues;
#ifdef __OpenBSD__
dev_priv->bdev.iot = dev_priv->iot;
dev_priv->bdev.memt = dev_priv->bst;
dev_priv->bdev.dmat = dev_priv->dmat;
#endif
ret = intel_region_ttm_device_init(dev_priv); ret = intel_region_ttm_device_init(dev_priv);
if (ret) if (ret)
goto err_ttm; goto err_ttm;
@ -2254,6 +2260,7 @@ inteldrm_attach(struct device *parent, struct device *self, void *aux)
dev_priv->pc = pa->pa_pc; dev_priv->pc = pa->pa_pc;
dev_priv->tag = pa->pa_tag; dev_priv->tag = pa->pa_tag;
dev_priv->iot = pa->pa_iot;
dev_priv->dmat = pa->pa_dmat; dev_priv->dmat = pa->pa_dmat;
dev_priv->bst = pa->pa_memt; dev_priv->bst = pa->pa_memt;
dev_priv->memex = pa->pa_memex; dev_priv->memex = pa->pa_memex;

View File

@ -215,8 +215,8 @@ struct inteldrm_softc {
#ifdef __OpenBSD__ #ifdef __OpenBSD__
struct device sc_dev; struct device sc_dev;
bus_dma_tag_t dmat; bus_dma_tag_t dmat;
bus_space_tag_t iot;
bus_space_tag_t bst; bus_space_tag_t bst;
struct agp_map *agph;
bus_space_handle_t opregion_ioh; bus_space_handle_t opregion_ioh;
bus_space_handle_t opregion_rvda_ioh; bus_space_handle_t opregion_rvda_ioh;
bus_size_t opregion_rvda_size; bus_size_t opregion_rvda_size;

View File

@ -39,8 +39,6 @@
#include <drm/drm_cache.h> #include <drm/drm_cache.h>
#include <drm/drm_vma_manager.h> #include <drm/drm_vma_manager.h>
#include <dev/pci/agpvar.h>
#include "display/intel_display.h" #include "display/intel_display.h"
#include "display/intel_frontbuffer.h" #include "display/intel_frontbuffer.h"
@ -279,7 +277,6 @@ err_unlock:
return ret; return ret;
} }
#ifdef __linux__
static inline bool static inline bool
gtt_user_read(struct io_mapping *mapping, gtt_user_read(struct io_mapping *mapping,
loff_t base, int offset, loff_t base, int offset,
@ -303,34 +300,6 @@ gtt_user_read(struct io_mapping *mapping,
} }
return unwritten; return unwritten;
} }
#else
static inline bool
gtt_user_read(struct drm_i915_private *dev_priv,
loff_t base, int offset,
char __user *user_data, int length)
{
bus_space_handle_t bsh;
void __iomem *vaddr;
unsigned long unwritten;
/* We can use the cpu mem copy function because this is X86. */
agp_map_atomic(dev_priv->agph, base, &bsh);
vaddr = bus_space_vaddr(dev_priv->bst, bsh);
unwritten = __copy_to_user_inatomic(user_data,
(void __force *)vaddr + offset,
length);
agp_unmap_atomic(dev_priv->agph, bsh);
if (unwritten) {
agp_map_subregion(dev_priv->agph, base, PAGE_SIZE, &bsh);
vaddr = bus_space_vaddr(dev_priv->bst, bsh);
unwritten = copy_to_user(user_data,
(void __force *)vaddr + offset,
length);
agp_unmap_subregion(dev_priv->agph, bsh, PAGE_SIZE);
}
return unwritten;
}
#endif
static struct i915_vma *i915_gem_gtt_prepare(struct drm_i915_gem_object *obj, static struct i915_vma *i915_gem_gtt_prepare(struct drm_i915_gem_object *obj,
struct drm_mm_node *node, struct drm_mm_node *node,
@ -460,7 +429,7 @@ i915_gem_gtt_pread(struct drm_i915_gem_object *obj,
page_base += offset & LINUX_PAGE_MASK; page_base += offset & LINUX_PAGE_MASK;
} }
if (gtt_user_read(i915, page_base, page_offset, if (gtt_user_read(&ggtt->iomap, page_base, page_offset,
user_data, page_length)) { user_data, page_length)) {
ret = -EFAULT; ret = -EFAULT;
break; break;
@ -542,7 +511,7 @@ out:
/* This is the fast write path which cannot handle /* This is the fast write path which cannot handle
* page faults in the source data * page faults in the source data
*/ */
#ifdef __linux__
static inline bool static inline bool
ggtt_write(struct io_mapping *mapping, ggtt_write(struct io_mapping *mapping,
loff_t base, int offset, loff_t base, int offset,
@ -565,33 +534,6 @@ ggtt_write(struct io_mapping *mapping,
return unwritten; return unwritten;
} }
#else
static inline bool
ggtt_write(struct drm_i915_private *dev_priv,
loff_t base, int offset,
char __user *user_data, int length)
{
bus_space_handle_t bsh;
void __iomem *vaddr;
unsigned long unwritten;
/* We can use the cpu mem copy function because this is X86. */
agp_map_atomic(dev_priv->agph, base, &bsh);
vaddr = bus_space_vaddr(dev_priv->bst, bsh);
unwritten = __copy_from_user_inatomic_nocache((void __force *)vaddr + offset,
user_data, length);
agp_unmap_atomic(dev_priv->agph, bsh);
if (unwritten) {
agp_map_subregion(dev_priv->agph, base, PAGE_SIZE, &bsh);
vaddr = bus_space_vaddr(dev_priv->bst, bsh);
unwritten = copy_from_user((void __force *)vaddr + offset,
user_data, length);
agp_unmap_subregion(dev_priv->agph, bsh, PAGE_SIZE);
}
return unwritten;
}
#endif
/** /**
* i915_gem_gtt_pwrite_fast - This is the fast pwrite path, where we copy the data directly from the * i915_gem_gtt_pwrite_fast - This is the fast pwrite path, where we copy the data directly from the
@ -674,7 +616,7 @@ i915_gem_gtt_pwrite_fast(struct drm_i915_gem_object *obj,
* If the object is non-shmem backed, we retry again with the * If the object is non-shmem backed, we retry again with the
* path that handles page fault. * path that handles page fault.
*/ */
if (ggtt_write(i915, page_base, page_offset, if (ggtt_write(&ggtt->iomap, page_base, page_offset,
user_data, page_length)) { user_data, page_length)) {
ret = -EFAULT; ret = -EFAULT;
break; break;

View File

@ -43,8 +43,6 @@
#include "i915_vma.h" #include "i915_vma.h"
#include "i915_vma_resource.h" #include "i915_vma_resource.h"
#include <dev/pci/agpvar.h>
static inline void assert_vma_held_evict(const struct i915_vma *vma) static inline void assert_vma_held_evict(const struct i915_vma *vma)
{ {
/* /*
@ -582,22 +580,9 @@ void __iomem *i915_vma_pin_iomap(struct i915_vma *vma)
ptr = i915_gem_object_lmem_io_map(vma->obj, 0, ptr = i915_gem_object_lmem_io_map(vma->obj, 0,
vma->obj->base.size); vma->obj->base.size);
} else if (i915_vma_is_map_and_fenceable(vma)) { } else if (i915_vma_is_map_and_fenceable(vma)) {
#ifdef __linux__
ptr = io_mapping_map_wc(&i915_vm_to_ggtt(vma->vm)->iomap, ptr = io_mapping_map_wc(&i915_vm_to_ggtt(vma->vm)->iomap,
i915_vma_offset(vma), i915_vma_offset(vma),
i915_vma_size(vma)); i915_vma_size(vma));
#else
{
struct drm_i915_private *dev_priv = vma->vm->i915;
err = agp_map_subregion(dev_priv->agph, i915_vma_offset(vma),
i915_vma_size(vma), &vma->bsh);
if (err) {
err = -err;
goto err;
}
ptr = bus_space_vaddr(dev_priv->bst, vma->bsh);
}
#endif
} else { } else {
ptr = (void __iomem *) ptr = (void __iomem *)
i915_gem_object_pin_map(vma->obj, I915_MAP_WC); i915_gem_object_pin_map(vma->obj, I915_MAP_WC);
@ -616,10 +601,8 @@ void __iomem *i915_vma_pin_iomap(struct i915_vma *vma)
if (unlikely(cmpxchg(&vma->iomap, NULL, ptr))) { if (unlikely(cmpxchg(&vma->iomap, NULL, ptr))) {
if (page_unmask_bits(ptr)) if (page_unmask_bits(ptr))
__i915_gem_object_release_map(vma->obj); __i915_gem_object_release_map(vma->obj);
#ifdef __linux__
else else
io_mapping_unmap(ptr); io_mapping_unmap(ptr);
#endif
ptr = vma->iomap; ptr = vma->iomap;
} }
} }
@ -1879,14 +1862,8 @@ static void __i915_vma_iounmap(struct i915_vma *vma)
if (page_unmask_bits(vma->iomap)) if (page_unmask_bits(vma->iomap))
__i915_gem_object_release_map(vma->obj); __i915_gem_object_release_map(vma->obj);
else { else
#ifdef __linux__
io_mapping_unmap(vma->iomap); io_mapping_unmap(vma->iomap);
#else
struct drm_i915_private *dev_priv = vma->vm->i915;
agp_unmap_subregion(dev_priv->agph, vma->bsh, vma->node.size);
#endif
}
vma->iomap = NULL; vma->iomap = NULL;
} }

View File

@ -70,9 +70,7 @@ struct intel_memory_region {
const struct intel_memory_region_ops *ops; const struct intel_memory_region_ops *ops;
#ifdef notyet
struct io_mapping iomap; struct io_mapping iomap;
#endif
struct resource region; struct resource region;
resource_size_t io_start; resource_size_t io_start;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bitmap.h,v 1.6 2024/01/06 09:33:08 kettenis Exp $ */ /* $OpenBSD: bitmap.h,v 1.8 2024/03/20 22:52:44 bluhm Exp $ */
/* /*
* Copyright (c) 2013, 2014, 2015 Mark Kettenis * Copyright (c) 2013, 2014, 2015 Mark Kettenis
* *
@ -97,11 +97,28 @@ bitmap_complement(void *d, void *s, u_int n)
dst[b >> 5] = ~src[b >> 5]; dst[b >> 5] = ~src[b >> 5];
} }
static inline bool
bitmap_intersects(const void *s1, const void *s2, u_int n)
{
const u_int *b1 = s1;
const u_int *b2 = s2;
u_int b;
for (b = 0; b < n; b += 32)
if (b1[b >> 5] & b2[b >> 5])
return true;
if ((n % 32) != 0)
if ((b1[n >> 5] & b2[b >> 5]) & (0xffffffff >> (32 - (n % 32))))
return true;
return false;
}
static inline void static inline void
bitmap_copy(void *d, void *s, u_int n) bitmap_copy(void *d, const void *s, u_int n)
{ {
u_int *dst = d; u_int *dst = d;
u_int *src = s; const u_int *src = s;
u_int b; u_int b;
for (b = 0; b < n; b += 32) for (b = 0; b < n; b += 32)
@ -109,7 +126,7 @@ bitmap_copy(void *d, void *s, u_int n)
} }
static inline void static inline void
bitmap_to_arr32(void *d, unsigned long *src, u_int n) bitmap_to_arr32(void *d, const unsigned long *src, u_int n)
{ {
u_int *dst = d; u_int *dst = d;
u_int b; u_int b;
@ -128,6 +145,27 @@ bitmap_to_arr32(void *d, unsigned long *src, u_int n)
dst[n >> 5] &= (0xffffffff >> (32 - (n % 32))); dst[n >> 5] &= (0xffffffff >> (32 - (n % 32)));
} }
static inline void
bitmap_from_arr32(unsigned long *dst, const void *s, u_int n)
{
const u_int *src = s;
u_int b;
#ifdef __LP64__
for (b = 0; b < n; b += 32) {
dst[b >> 6] = src[b >> 5];
b += 32;
if (b < n)
dst[b >> 6] |= ((unsigned long)src[b >> 5]) << 32;
}
if ((n % 64) != 0)
dst[n >> 6] &= (0xffffffffffffffffUL >> (64 - (n % 64)));
#else
bitmap_copy(dst, s, n);
if ((n % 32) != 0)
dst[n >> 5] &= (0xffffffff >> (32 - (n % 32)));
#endif
}
static inline int static inline int
bitmap_weight(const void *p, u_int n) bitmap_weight(const void *p, u_int n)

View File

@ -3,4 +3,45 @@
#ifndef _LINUX_IO_MAPPING_H #ifndef _LINUX_IO_MAPPING_H
#define _LINUX_IO_MAPPING_H #define _LINUX_IO_MAPPING_H
#include <linux/types.h>
struct io_mapping {
resource_size_t base;
unsigned long size;
void *iomem;
};
static inline void *
io_mapping_map_wc(struct io_mapping *map, unsigned long off, unsigned long size)
{
return ((uint8_t *)map->iomem + off);
}
static inline void
io_mapping_unmap(void *va)
{
}
static inline void *
io_mapping_map_local_wc(struct io_mapping *map, unsigned long off)
{
return ((uint8_t *)map->iomem + off);
}
static inline void
io_mapping_unmap_local(void *va)
{
}
static inline void *
io_mapping_map_atomic_wc(struct io_mapping *map, unsigned long off)
{
return ((uint8_t *)map->iomem + off);
}
static inline void
io_mapping_unmap_atomic(void *va)
{
}
#endif #endif

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vmalloc.h,v 1.6 2024/01/16 23:38:13 jsg Exp $ */ /* $OpenBSD: vmalloc.h,v 1.7 2024/03/20 02:42:17 jsg Exp $ */
/* /*
* Copyright (c) 2013, 2014, 2015 Mark Kettenis * Copyright (c) 2013, 2014, 2015 Mark Kettenis
* *
@ -25,6 +25,7 @@
#include <linux/types.h> /* for pgprot_t */ #include <linux/types.h> /* for pgprot_t */
void *vmap(struct vm_page **, unsigned int, unsigned long, pgprot_t); void *vmap(struct vm_page **, unsigned int, unsigned long, pgprot_t);
void *vmap_pfn(unsigned long *, unsigned int, pgprot_t);
void vunmap(void *, size_t); void vunmap(void *, size_t);
static inline void * static inline void *

View File

@ -564,32 +564,16 @@ retry:
goto retry; goto retry;
} }
#ifdef __linux__
addr = io_mapping_map_local_wc(iter_io->iomap, iter_io->cache.offs + addr = io_mapping_map_local_wc(iter_io->iomap, iter_io->cache.offs +
(((resource_size_t)i - iter_io->cache.i) (((resource_size_t)i - iter_io->cache.i)
<< PAGE_SHIFT)); << PAGE_SHIFT));
#else
if (bus_space_map(bst, iter_io->cache.offs +
(((resource_size_t)i - iter_io->cache.i) << PAGE_SHIFT),
PAGE_SIZE, BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_PREFETCHABLE,
&dmap->bsh)) {
printf("%s bus_space_map failed\n", __func__);
addr = 0;
} else {
addr = bus_space_vaddr(bst, dmap->bsh);
}
#endif
iosys_map_set_vaddr_iomem(dmap, addr); iosys_map_set_vaddr_iomem(dmap, addr);
} }
static void ttm_kmap_iter_iomap_unmap_local(struct ttm_kmap_iter *iter, static void ttm_kmap_iter_iomap_unmap_local(struct ttm_kmap_iter *iter,
struct iosys_map *map, bus_space_tag_t bst) struct iosys_map *map, bus_space_tag_t bst)
{ {
#ifdef notyet
io_mapping_unmap_local(map->vaddr_iomem); io_mapping_unmap_local(map->vaddr_iomem);
#else
bus_space_unmap(bst, map->bsh, PAGE_SIZE);
#endif
} }
static const struct ttm_kmap_iter_ops ttm_kmap_iter_io_ops = { static const struct ttm_kmap_iter_ops ttm_kmap_iter_io_ops = {

View File

@ -151,6 +151,9 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm,
ttm->swap_storage = NULL; ttm->swap_storage = NULL;
ttm->sg = bo->sg; ttm->sg = bo->sg;
ttm->caching = caching; ttm->caching = caching;
ttm->dmat = bo->bdev->dmat;
ttm->map = NULL;
ttm->segs = NULL;
} }
int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo, int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
@ -184,7 +187,9 @@ void ttm_tt_fini(struct ttm_tt *ttm)
ttm->dma_address = NULL; ttm->dma_address = NULL;
ttm->orders = NULL; ttm->orders = NULL;
if (ttm->map)
bus_dmamap_destroy(ttm->dmat, ttm->map); bus_dmamap_destroy(ttm->dmat, ttm->map);
if (ttm->segs)
km_free(ttm->segs, round_page(ttm->num_pages * km_free(ttm->segs, round_page(ttm->num_pages *
sizeof(bus_dma_segment_t)), &kv_any, &kp_zero); sizeof(bus_dma_segment_t)), &kv_any, &kp_zero);
} }
@ -210,8 +215,6 @@ int ttm_sg_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
ttm->segs = km_alloc(round_page(ttm->num_pages * ttm->segs = km_alloc(round_page(ttm->num_pages *
sizeof(bus_dma_segment_t)), &kv_any, &kp_zero, &kd_waitok); sizeof(bus_dma_segment_t)), &kv_any, &kp_zero, &kd_waitok);
ttm->dmat = bo->bdev->dmat;
if (bo->bdev->pool.use_dma32 == false) if (bo->bdev->pool.use_dma32 == false)
flags |= BUS_DMA_64BIT; flags |= BUS_DMA_64BIT;
if (bus_dmamap_create(ttm->dmat, ttm->num_pages << PAGE_SHIFT, if (bus_dmamap_create(ttm->dmat, ttm->num_pages << PAGE_SHIFT,

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: aucat.1,v 1.119 2023/01/10 20:48:34 ratchov Exp $ .\" $OpenBSD: aucat.1,v 1.120 2024/03/20 08:42:11 ratchov Exp $
.\" .\"
.\" Copyright (c) 2006 Alexandre Ratchov <alex@caoua.org> .\" Copyright (c) 2006 Alexandre Ratchov <alex@caoua.org>
.\" .\"
@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: January 10 2023 $ .Dd $Mdocdate: March 20 2024 $
.Dt AUCAT 1 .Dt AUCAT 1
.Os .Os
.Sh NAME .Sh NAME
@ -24,13 +24,13 @@
.Nm aucat .Nm aucat
.Op Fl dn .Op Fl dn
.Op Fl b Ar size .Op Fl b Ar size
.Op Fl c Ar min : Ns Ar max .Op Fl c Ar channels
.Op Fl e Ar enc .Op Fl e Ar enc
.Op Fl f Ar device .Op Fl f Ar device
.Op Fl g Ar position .Op Fl g Ar position
.Op Fl h Ar fmt .Op Fl h Ar fmt
.Op Fl i Ar file .Op Fl i Ar file
.Op Fl j Ar flag .Op Fl m Ar min : Ns Ar max Ns / Ns Ar min : Ns Ar max
.Op Fl o Ar file .Op Fl o Ar file
.Op Fl p Ar position .Op Fl p Ar position
.Op Fl q Ar port .Op Fl q Ar port
@ -78,11 +78,9 @@ The options are as follows:
.It Fl b Ar size .It Fl b Ar size
The buffer size of the audio device in frames. The buffer size of the audio device in frames.
Default is 7680. Default is 7680.
.It Fl c Ar min : Ns Ar max .It Fl c Ar channels
The range of audio file channel numbers. The audio file channels count.
The default is The default is 2, i.e. stereo.
.Cm 0:1 ,
i.e. stereo.
.It Fl d .It Fl d
Increase log verbosity. Increase log verbosity.
.It Fl e Ar enc .It Fl e Ar enc
@ -146,21 +144,9 @@ Play this audio file.
If the option argument is If the option argument is
.Sq - .Sq -
then standard input will be used. then standard input will be used.
.It Fl j Ar flag .It Fl m Ar min : Ns Ar max Ns / Ns Ar min : Ns Ar max
Control whether source channels are joined or expanded if Map the given range of source channels into the given range of
they don't match the destination number of channels. destination channels.
If the flag is
.Cm off ,
then each source channel is routed to a single destination channel,
possibly discarding channels.
If the flag is
.Cm on ,
then a single source may be sent to multiple destinations
and multiple sources may be mixed into a single destination.
For instance, this feature could be used to convert
a stereo file into a mono file mixing left and right channels together.
The default is
.Cm off .
.It Fl n .It Fl n
Off-line mode. Off-line mode.
Read input files and store the result in the output files, Read input files and store the result in the output files,
@ -198,7 +184,7 @@ The default is 127, i.e. no attenuation.
.Pp .Pp
On the command line, On the command line,
per-file parameters per-file parameters
.Pq Fl cehjrv .Pq Fl cehmrv
must precede the file definition must precede the file definition
.Pq Fl io . .Pq Fl io .
.Pp .Pp
@ -282,13 +268,13 @@ Record channels 2 and 3 into one stereo file and
channels 6 and 7 into another stereo file using a 44.1kHz sampling channels 6 and 7 into another stereo file using a 44.1kHz sampling
rate for both: rate for both:
.Bd -literal -offset indent .Bd -literal -offset indent
$ aucat -r 44100 -c 2:3 -o file1.wav -c 6:7 -o file2.wav $ aucat -r 44100 -m 2:3/0:1 -o file1.wav -m 6:7/0:1 -o file2.wav
.Ed .Ed
.Pp .Pp
Split a stereo file into two mono files: Split a stereo file into two mono files:
.Bd -literal -offset indent .Bd -literal -offset indent
$ aucat -n -i stereo.wav -c 0:0 -o left.wav \e $ aucat -n -i stereo.wav -c 1 -m 0:0/0:0 -o left.wav \e
-c 1:1 -o right.wav -m 1:1/0:0 -o right.wav
.Ed .Ed
.Sh SEE ALSO .Sh SEE ALSO
.Xr cdio 1 , .Xr cdio 1 ,

View File

@ -75,14 +75,14 @@ struct slot {
int volctl; /* volume in the 0..127 range */ int volctl; /* volume in the 0..127 range */
struct abuf buf; /* file i/o buffer */ struct abuf buf; /* file i/o buffer */
int bpf; /* bytes per frame */ int bpf; /* bytes per frame */
int cmin, cmax; /* file channel range */ int imin, imax, omin, omax; /* channel mapping ranges */
struct cmap cmap; /* channel mapper state */ struct cmap cmap; /* channel mapper state */
struct resamp resamp; /* resampler state */ struct resamp resamp; /* resampler state */
struct conv conv; /* format encoder state */ struct conv conv; /* format encoder state */
int join; /* channel join factor */ int join; /* channel join factor */
int expand; /* channel expand factor */ int expand; /* channel expand factor */
void *resampbuf, *convbuf; /* conversion tmp buffers */ void *resampbuf, *convbuf; /* conversion tmp buffers */
int dup; /* mono-to-stereo and alike */ int dup; /* compat with legacy -j option */
int round; /* slot-side block size */ int round; /* slot-side block size */
int mode; /* MODE_{PLAY,REC} */ int mode; /* MODE_{PLAY,REC} */
#define SLOT_CFG 0 /* buffers not allocated yet */ #define SLOT_CFG 0 /* buffers not allocated yet */
@ -136,9 +136,9 @@ const unsigned int voice_len[] = { 3, 3, 3, 3, 2, 2, 3 };
const unsigned int common_len[] = { 0, 2, 3, 2, 0, 0, 1, 1 }; const unsigned int common_len[] = { 0, 2, 3, 2, 0, 0, 1, 1 };
char usagestr[] = "usage: aucat [-dn] [-b size] " char usagestr[] = "usage: aucat [-dn] [-b size] "
"[-c min:max] [-e enc] [-f device] [-g position]\n\t" "[-c channels] [-e enc] [-f device] [-g position]\n\t"
"[-h fmt] [-i file] [-j flag] [-o file] [-p position] [-q port]\n\t" "[-h fmt] [-i file] [-m min:max/min:max] [-o file] [-p position]\n\t"
"[-r rate] [-v volume]\n"; "[-q port] [-r rate] [-v volume]\n";
static void * static void *
allocbuf(int nfr, int nch) allocbuf(int nfr, int nch)
@ -218,19 +218,22 @@ slot_fill(struct slot *s)
static int static int
slot_new(char *path, int mode, struct aparams *par, int hdr, slot_new(char *path, int mode, struct aparams *par, int hdr,
int cmin, int cmax, int rate, int dup, int vol, long long pos) int imin, int imax, int omin, int omax, int nch,
int rate, int dup, int vol, long long pos)
{ {
struct slot *s, **ps; struct slot *s, **ps;
s = xmalloc(sizeof(struct slot)); s = xmalloc(sizeof(struct slot));
if (!afile_open(&s->afile, path, hdr, if (!afile_open(&s->afile, path, hdr,
mode == SIO_PLAY ? AFILE_FREAD : AFILE_FWRITE, mode == SIO_PLAY ? AFILE_FREAD : AFILE_FWRITE,
par, rate, cmax - cmin + 1)) { par, rate, nch)) {
xfree(s); xfree(s);
return 0; return 0;
} }
s->cmin = cmin; s->imin = (imin != -1) ? imin : 0;
s->cmax = cmin + s->afile.nch - 1; s->imax = (imax != -1) ? imax : s->imin + s->afile.nch - 1;
s->omin = (omin != -1) ? omin : 0;
s->omax = (omax != -1) ? omax : s->omin + s->afile.nch - 1;
s->dup = dup; s->dup = dup;
s->vol = MIDI_TO_ADATA(vol); s->vol = MIDI_TO_ADATA(vol);
s->mode = mode; s->mode = mode;
@ -240,11 +243,17 @@ slot_new(char *path, int mode, struct aparams *par, int hdr,
slot_log(s); slot_log(s);
log_puts(": "); log_puts(": ");
log_puts(s->mode == SIO_PLAY ? "play" : "rec"); log_puts(s->mode == SIO_PLAY ? "play" : "rec");
log_puts(", chan ");
log_putu(s->cmin);
log_puts(":");
log_putu(s->cmax);
log_puts(", "); log_puts(", ");
log_putu(s->afile.nch);
log_puts("ch (");
log_putu(s->imin);
log_puts(":");
log_putu(s->imax);
log_puts("/");
log_putu(s->omin);
log_puts(":");
log_putu(s->omax);
log_puts("), ");
log_putu(s->afile.rate); log_putu(s->afile.rate);
log_puts("Hz, "); log_puts("Hz, ");
switch (s->afile.fmt) { switch (s->afile.fmt) {
@ -283,7 +292,7 @@ slot_new(char *path, int mode, struct aparams *par, int hdr,
static void static void
slot_init(struct slot *s) slot_init(struct slot *s)
{ {
unsigned int slot_nch, bufsz; unsigned int inch, onch, bufsz;
#ifdef DEBUG #ifdef DEBUG
if (s->pstate != SLOT_CFG) { if (s->pstate != SLOT_CFG) {
@ -292,7 +301,7 @@ slot_init(struct slot *s)
panic(); panic();
} }
#endif #endif
s->bpf = s->afile.par.bps * (s->cmax - s->cmin + 1); s->bpf = s->afile.par.bps * s->afile.nch;
s->round = ((long long)dev_round * s->afile.rate + s->round = ((long long)dev_round * s->afile.rate +
dev_rate - 1) / dev_rate; dev_rate - 1) / dev_rate;
@ -310,54 +319,50 @@ slot_init(struct slot *s)
} }
#endif #endif
slot_nch = s->cmax - s->cmin + 1;
s->convbuf = NULL; s->convbuf = NULL;
s->resampbuf = NULL; s->resampbuf = NULL;
s->join = 1; s->join = 1;
s->expand = 1; s->expand = 1;
if (s->mode & SIO_PLAY) { inch = s->imax - s->imin + 1;
onch = s->omax - s->omin + 1;
if (s->dup) { if (s->dup) {
if (dev_pchan > slot_nch) /* compat with legacy -j option */
s->expand = dev_pchan / slot_nch; if (s->mode == SIO_PLAY)
else if (dev_pchan < slot_nch) onch = dev_pchan;
s->join = slot_nch / dev_pchan; else
inch = dev_rchan;
} }
if (onch > inch)
s->expand = onch / inch;
else if (onch < inch)
s->join = inch / onch;
if (s->mode & SIO_PLAY) {
cmap_init(&s->cmap, cmap_init(&s->cmap,
s->cmin, s->cmax, 0, s->afile.nch - 1, s->imin, s->imax,
s->cmin, s->cmax, 0, dev_pchan - 1, s->omin, s->omax);
0, dev_pchan - 1,
0, dev_pchan - 1);
if (s->afile.fmt != AFILE_FMT_PCM || if (s->afile.fmt != AFILE_FMT_PCM ||
!aparams_native(&s->afile.par)) { !aparams_native(&s->afile.par)) {
dec_init(&s->conv, &s->afile.par, slot_nch); dec_init(&s->conv, &s->afile.par, s->afile.nch);
s->convbuf = allocbuf(s->round, slot_nch); s->convbuf = allocbuf(s->round, s->afile.nch);
} }
if (s->afile.rate != dev_rate) { if (s->afile.rate != dev_rate) {
resamp_init(&s->resamp, s->afile.rate, dev_rate, resamp_init(&s->resamp, s->afile.rate, dev_rate,
slot_nch); s->afile.nch);
s->resampbuf = allocbuf(dev_round, slot_nch); s->resampbuf = allocbuf(dev_round, s->afile.nch);
} }
} }
if (s->mode & SIO_REC) { if (s->mode & SIO_REC) {
if (s->dup) {
if (dev_rchan > slot_nch)
s->join = dev_rchan / slot_nch;
else if (dev_rchan < slot_nch)
s->expand = slot_nch / dev_rchan;
}
cmap_init(&s->cmap, cmap_init(&s->cmap,
0, dev_rchan - 1, 0, dev_rchan - 1, s->imin, s->imax,
0, dev_rchan - 1, 0, s->afile.nch - 1, s->omin, s->omax);
s->cmin, s->cmax,
s->cmin, s->cmax);
if (s->afile.rate != dev_rate) { if (s->afile.rate != dev_rate) {
resamp_init(&s->resamp, dev_rate, s->afile.rate, resamp_init(&s->resamp, dev_rate, s->afile.rate,
slot_nch); s->afile.nch);
s->resampbuf = allocbuf(dev_round, slot_nch); s->resampbuf = allocbuf(dev_round, s->afile.nch);
} }
if (!aparams_native(&s->afile.par)) { if (!aparams_native(&s->afile.par)) {
enc_init(&s->conv, &s->afile.par, slot_nch); enc_init(&s->conv, &s->afile.par, s->afile.nch);
s->convbuf = allocbuf(s->round, slot_nch); s->convbuf = allocbuf(s->round, s->afile.nch);
} }
/* /*
@ -368,13 +373,13 @@ slot_init(struct slot *s)
*/ */
if (s->resampbuf) { if (s->resampbuf) {
memset(s->resampbuf, 0, memset(s->resampbuf, 0,
dev_round * slot_nch * sizeof(adata_t)); dev_round * s->afile.nch * sizeof(adata_t));
} else if (s->convbuf) { } else if (s->convbuf) {
memset(s->convbuf, 0, memset(s->convbuf, 0,
s->round * slot_nch * sizeof(adata_t)); s->round * s->afile.nch * sizeof(adata_t));
} else { } else {
memset(s->buf.data, 0, memset(s->buf.data, 0,
bufsz * slot_nch * sizeof(adata_t)); bufsz * s->afile.nch * sizeof(adata_t));
} }
} }
s->pstate = SLOT_INIT; s->pstate = SLOT_INIT;
@ -487,7 +492,7 @@ slot_getcnt(struct slot *s, int *icnt, int *ocnt)
static void static void
play_filt_resamp(struct slot *s, void *res_in, void *out, int icnt, int ocnt) play_filt_resamp(struct slot *s, void *res_in, void *out, int icnt, int ocnt)
{ {
int i, offs, vol, nch; int i, offs, vol, inch, onch;
void *in; void *in;
if (s->resampbuf) { if (s->resampbuf) {
@ -496,18 +501,24 @@ play_filt_resamp(struct slot *s, void *res_in, void *out, int icnt, int ocnt)
} else } else
in = res_in; in = res_in;
nch = s->cmap.nch; inch = s->imax - s->imin + 1;
onch = s->omax - s->omin + 1;
vol = s->vol / s->join; /* XXX */ vol = s->vol / s->join; /* XXX */
cmap_add(&s->cmap, in, out, vol, ocnt); cmap_add(&s->cmap, in, out, vol, ocnt);
offs = 0; offs = 0;
for (i = s->join - 1; i > 0; i--) { for (i = s->join - 1; i > 0; i--) {
offs += nch; offs += onch;
if (offs + s->cmap.nch > s->afile.nch)
break;
cmap_add(&s->cmap, (adata_t *)in + offs, out, vol, ocnt); cmap_add(&s->cmap, (adata_t *)in + offs, out, vol, ocnt);
} }
offs = 0; offs = 0;
for (i = s->expand - 1; i > 0; i--) { for (i = s->expand - 1; i > 0; i--) {
offs += nch; offs += inch;
if (offs + s->cmap.nch > dev_pchan)
break;
cmap_add(&s->cmap, in, (adata_t *)out + offs, vol, ocnt); cmap_add(&s->cmap, in, (adata_t *)out + offs, vol, ocnt);
} }
} }
@ -581,23 +592,28 @@ slot_mix_badd(struct slot *s, adata_t *odata)
static void static void
rec_filt_resamp(struct slot *s, void *in, void *res_out, int icnt, int ocnt) rec_filt_resamp(struct slot *s, void *in, void *res_out, int icnt, int ocnt)
{ {
int i, vol, offs, nch; int i, vol, offs, inch, onch;
void *out = res_out; void *out = res_out;
out = (s->resampbuf) ? s->resampbuf : res_out; out = (s->resampbuf) ? s->resampbuf : res_out;
nch = s->cmap.nch; inch = s->imax - s->imin + 1;
onch = s->omax - s->omin + 1;
vol = ADATA_UNIT / s->join; vol = ADATA_UNIT / s->join;
cmap_copy(&s->cmap, in, out, vol, icnt); cmap_copy(&s->cmap, in, out, vol, icnt);
offs = 0; offs = 0;
for (i = s->join - 1; i > 0; i--) { for (i = s->join - 1; i > 0; i--) {
offs += nch; offs += onch;
if (offs + s->cmap.nch > dev_rchan)
break;
cmap_add(&s->cmap, (adata_t *)in + offs, out, vol, icnt); cmap_add(&s->cmap, (adata_t *)in + offs, out, vol, icnt);
} }
offs = 0; offs = 0;
for (i = s->expand - 1; i > 0; i--) { for (i = s->expand - 1; i > 0; i--) {
offs += nch; offs += inch;
if (offs + s->cmap.nch > s->afile.nch)
break;
cmap_copy(&s->cmap, in, (adata_t *)out + offs, vol, icnt); cmap_copy(&s->cmap, in, (adata_t *)out + offs, vol, icnt);
} }
if (s->resampbuf) if (s->resampbuf)
@ -683,12 +699,12 @@ dev_open(char *dev, int mode, int bufsz, char *port)
if (s->afile.rate > rate) if (s->afile.rate > rate)
rate = s->afile.rate; rate = s->afile.rate;
if (s->mode == SIO_PLAY) { if (s->mode == SIO_PLAY) {
if (s->cmax > pmax) if (s->omax > pmax)
pmax = s->cmax; pmax = s->omax;
} }
if (s->mode == SIO_REC) { if (s->mode == SIO_REC) {
if (s->cmax > rmax) if (s->imax > rmax)
rmax = s->cmax; rmax = s->imax;
} }
} }
sio_initpar(&par); sio_initpar(&par);
@ -1078,8 +1094,10 @@ offline(void)
for (s = slot_list; s != NULL; s = s->next) { for (s = slot_list; s != NULL; s = s->next) {
if (s->afile.rate > rate) if (s->afile.rate > rate)
rate = s->afile.rate; rate = s->afile.rate;
if (s->cmax > cmax) if (s->imax > cmax)
cmax = s->cmax; cmax = s->imax;
if (s->omax > cmax)
cmax = s->omax;
} }
dev_sh = NULL; dev_sh = NULL;
dev_name = "offline"; dev_name = "offline";
@ -1323,26 +1341,78 @@ opt_hdr(char *s, int *hdr)
} }
static int static int
opt_ch(char *s, int *rcmin, int *rcmax) opt_map(char *str, int *rimin, int *rimax, int *romin, int *romax)
{ {
char *next, *end; char *s, *next;
long cmin, cmax; long imin, imax, omin, omax;
errno = 0; errno = 0;
cmin = strtol(s, &next, 10); s = str;
imin = strtol(s, &next, 10);
if (next == s || *next != ':') if (next == s || *next != ':')
goto failed; goto failed;
cmax = strtol(++next, &end, 10); s = next + 1;
if (end == next || *end != '\0') imax = strtol(s, &next, 10);
if (next == s || *next != '/')
goto failed;
s = next + 1;
omin = strtol(s, &next, 10);
if (next == s || *next != ':')
goto failed;
s = next + 1;
omax = strtol(s, &next, 10);
if (next == s || *next != '\0')
goto failed;
if (imin < 0 || imax < imin || imax >= NCHAN_MAX)
goto failed;
if (omin < 0 || omax < omin || omax >= NCHAN_MAX)
goto failed;
*rimin = imin;
*rimax = imax;
*romin = omin;
*romax = omax;
return 1;
failed:
log_puts(str);
log_puts(": channel mapping expected\n");
return 0;
}
static int
opt_nch(char *str, int *rnch, int *roff)
{
char *s, *next;
long nch, off, cmin, cmax;
errno = 0;
s = str;
nch = strtol(s, &next, 10);
if (next == s)
goto failed;
if (*next == ':') {
/* compat with legacy -c syntax */
s = next + 1;
cmin = nch;
cmax = strtol(s, &next, 10);
if (next == s)
goto failed; goto failed;
if (cmin < 0 || cmax < cmin || cmax >= NCHAN_MAX) if (cmin < 0 || cmax < cmin || cmax >= NCHAN_MAX)
goto failed; goto failed;
*rcmin = cmin; nch = cmax - cmin + 1;
*rcmax = cmax; off = cmin;
} else {
off = 0;
if (nch < 0 || nch >= NCHAN_MAX)
goto failed;
}
if (*next != '\0')
goto failed;
*rnch = nch;
*roff = off;
return 1; return 1;
failed: failed:
log_puts(s); log_puts(str);
log_puts(": channel range expected\n"); log_puts(": channel count expected\n");
return 0; return 0;
} }
@ -1381,7 +1451,7 @@ opt_pos(char *s, long long *pos)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int dup, cmin, cmax, rate, vol, bufsz, hdr, mode; int dup, imin, imax, omin, omax, nch, off, rate, vol, bufsz, hdr, mode;
char *port, *dev; char *port, *dev;
struct aparams par; struct aparams par;
int n_flag, c; int n_flag, c;
@ -1393,9 +1463,10 @@ main(int argc, char **argv)
vol = 127; vol = 127;
dup = 0; dup = 0;
bufsz = 0; bufsz = 0;
nch = 2;
off = 0;
rate = DEFAULT_RATE; rate = DEFAULT_RATE;
cmin = 0; imin = imax = omin = omax = -1;
cmax = 1;
par.bits = ADATA_BITS; par.bits = ADATA_BITS;
par.bps = APARAMS_BPS(par.bits); par.bps = APARAMS_BPS(par.bits);
par.le = ADATA_LE; par.le = ADATA_LE;
@ -1409,14 +1480,14 @@ main(int argc, char **argv)
pos = 0; pos = 0;
while ((c = getopt(argc, argv, while ((c = getopt(argc, argv,
"b:c:de:f:g:h:i:j:no:p:q:r:t:v:")) != -1) { "b:c:de:f:g:h:i:j:m:no:p:q:r:t:v:")) != -1) {
switch (c) { switch (c) {
case 'b': case 'b':
if (!opt_num(optarg, 1, RATE_MAX, &bufsz)) if (!opt_num(optarg, 1, RATE_MAX, &bufsz))
return 1; return 1;
break; break;
case 'c': case 'c':
if (!opt_ch(optarg, &cmin, &cmax)) if (!opt_nch(optarg, &nch, &off))
return 1; return 1;
break; break;
case 'd': case 'd':
@ -1438,22 +1509,41 @@ main(int argc, char **argv)
return 1; return 1;
break; break;
case 'i': case 'i':
if (off > 0) {
/* compat with legacy -c syntax */
omin = off;
omax = off + nch - 1;
}
if (!slot_new(optarg, SIO_PLAY, if (!slot_new(optarg, SIO_PLAY,
&par, hdr, cmin, cmax, rate, dup, vol, pos)) &par, hdr, imin, imax, omin, omax,
nch, rate, dup, vol, pos))
return 1; return 1;
mode |= SIO_PLAY; mode |= SIO_PLAY;
imin = imax = omin = omax = -1;
break; break;
case 'j': case 'j':
/* compat with legacy -j option */
if (!opt_onoff(optarg, &dup)) if (!opt_onoff(optarg, &dup))
return 1; return 1;
break; break;
case 'm':
if (!opt_map(optarg, &imin, &imax, &omin, &omax))
return 1;
break;
case 'n': case 'n':
n_flag = 1; n_flag = 1;
break; break;
case 'o': case 'o':
if (off > 0) {
/* compat with legacy -c syntax */
imin = off;
imax = off + nch - 1;
}
if (!slot_new(optarg, SIO_REC, if (!slot_new(optarg, SIO_REC,
&par, hdr, cmin, cmax, rate, dup, 0, pos)) &par, hdr, imin, imax, omin, omax,
nch, rate, dup, 0, pos))
return 1; return 1;
imin = imax = omin = omax = -1;
mode |= SIO_REC; mode |= SIO_REC;
break; break;
case 'p': case 'p':

View File

@ -1,4 +1,4 @@
/* $OpenBSD: dsp.c,v 1.18 2022/12/26 19:16:00 jmc Exp $ */ /* $OpenBSD: dsp.c,v 1.19 2024/03/20 08:42:11 ratchov Exp $ */
/* /*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
* *
@ -992,33 +992,35 @@ cmap_init(struct cmap *p,
int imin, int imax, int isubmin, int isubmax, int imin, int imax, int isubmin, int isubmax,
int omin, int omax, int osubmin, int osubmax) int omin, int omax, int osubmin, int osubmax)
{ {
int cmin, cmax; int inch, onch, nch;
cmin = -NCHAN_MAX; /*
if (osubmin > cmin) * Ignore channels outside of the available sets
cmin = osubmin; */
if (omin > cmin) if (isubmin < imin)
cmin = omin; isubmin = imin;
if (isubmin > cmin) if (isubmax > imax)
cmin = isubmin; isubmax = imax;
if (imin > cmin) if (osubmin < omin)
cmin = imin; osubmin = omin;
if (osubmax > omax)
osubmax = omax;
cmax = NCHAN_MAX; /*
if (osubmax < cmax) * Shrink the input or the output subset to make both subsets of
cmax = osubmax; * the same size
if (omax < cmax) */
cmax = omax; inch = isubmax - isubmin + 1;
if (isubmax < cmax) onch = osubmax - osubmin + 1;
cmax = isubmax; nch = (inch < onch) ? inch : onch;
if (imax < cmax) isubmax = isubmin + nch - 1;
cmax = imax; osubmax = osubmin + nch - 1;
p->ostart = cmin - omin; p->ostart = osubmin - omin;
p->onext = omax - cmax; p->onext = omax - osubmax;
p->istart = cmin - imin; p->istart = isubmin - imin;
p->inext = imax - cmax; p->inext = imax - isubmax;
p->nch = cmax - cmin + 1; p->nch = nch;
#ifdef DEBUG #ifdef DEBUG
if (log_level >= 3) { if (log_level >= 3) {
log_puts("cmap: nch = "); log_puts("cmap: nch = ");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: sender.c,v 1.32 2024/02/27 11:28:30 claudio Exp $ */ /* $OpenBSD: sender.c,v 1.33 2024/03/20 09:26:42 claudio Exp $ */
/* /*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
* *
@ -588,7 +588,8 @@ rsync_sender(struct sess *sess, int fdin,
&up, &wbuf, &wbufsz, &wbufmax, fl)) { &up, &wbuf, &wbufsz, &wbufmax, fl)) {
ERRX1("send_up_fsm"); ERRX1("send_up_fsm");
goto out; goto out;
} else if (phase > 1) }
if (phase > 1)
break; break;
} }
@ -664,7 +665,8 @@ rsync_sender(struct sess *sess, int fdin,
if (!io_read_int(sess, fdin, &idx)) { if (!io_read_int(sess, fdin, &idx)) {
ERRX1("io_read_int"); ERRX1("io_read_int");
goto out; goto out;
} else if (idx != -1) { }
if (idx != -1) {
ERRX("read incorrect update complete ack"); ERRX("read incorrect update complete ack");
goto out; goto out;
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: parse.y,v 1.456 2024/03/18 14:54:52 claudio Exp $ */ /* $OpenBSD: parse.y,v 1.457 2024/03/20 09:35:46 claudio Exp $ */
/* /*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -1894,7 +1894,7 @@ peeropts : REMOTEAS as4number {
uint16_t afi; uint16_t afi;
if ($3 == SAFI_NONE) { if ($3 == SAFI_NONE) {
for (aid = 0; aid < AID_MAX; aid++) { for (aid = AID_MIN; aid < AID_MAX; aid++) {
if (aid2afi(aid, &afi, &safi) == -1 || if (aid2afi(aid, &afi, &safi) == -1 ||
afi != $2) afi != $2)
continue; continue;
@ -1927,11 +1927,11 @@ peeropts : REMOTEAS as4number {
int8_t *ap = curpeer->conf.capabilities.add_path; int8_t *ap = curpeer->conf.capabilities.add_path;
uint8_t i; uint8_t i;
for (i = 0; i < AID_MAX; i++) for (i = AID_MIN; i < AID_MAX; i++)
if ($4) if ($4)
*ap++ |= CAPA_AP_RECV; ap[i] |= CAPA_AP_RECV;
else else
*ap++ &= ~CAPA_AP_RECV; ap[i] &= ~CAPA_AP_RECV;
} }
| ANNOUNCE ADDPATH SEND STRING addpathextra addpathmax { | ANNOUNCE ADDPATH SEND STRING addpathextra addpathmax {
int8_t *ap = curpeer->conf.capabilities.add_path; int8_t *ap = curpeer->conf.capabilities.add_path;
@ -1945,9 +1945,7 @@ peeropts : REMOTEAS as4number {
"for 'add-path send no'"); "for 'add-path send no'");
YYERROR; YYERROR;
} }
for (i = 0; i < AID_MAX; i++) mode = ADDPATH_EVAL_NONE;
*ap++ &= ~CAPA_AP_SEND;
break;
} else if (!strcmp($4, "all")) { } else if (!strcmp($4, "all")) {
free($4); free($4);
if ($5 != 0 || $6 != 0) { if ($5 != 0 || $6 != 0) {
@ -1971,8 +1969,12 @@ peeropts : REMOTEAS as4number {
free($4); free($4);
YYERROR; YYERROR;
} }
for (i = 0; i < AID_MAX; i++) for (i = AID_MIN; i < AID_MAX; i++) {
*ap++ |= CAPA_AP_SEND; if (mode != ADDPATH_EVAL_NONE)
ap[i] |= CAPA_AP_SEND;
else
ap[i] &= ~CAPA_AP_SEND;
}
curpeer->conf.eval.mode = mode; curpeer->conf.eval.mode = mode;
curpeer->conf.eval.extrapaths = $5; curpeer->conf.eval.extrapaths = $5;
curpeer->conf.eval.maxpaths = $6; curpeer->conf.eval.maxpaths = $6;
@ -4611,7 +4613,6 @@ struct peer *
alloc_peer(void) alloc_peer(void)
{ {
struct peer *p; struct peer *p;
uint8_t i;
if ((p = calloc(1, sizeof(struct peer))) == NULL) if ((p = calloc(1, sizeof(struct peer))) == NULL)
fatal("new_peer"); fatal("new_peer");
@ -4622,8 +4623,6 @@ alloc_peer(void)
p->conf.distance = 1; p->conf.distance = 1;
p->conf.export_type = EXPORT_UNSET; p->conf.export_type = EXPORT_UNSET;
p->conf.announce_capa = 1; p->conf.announce_capa = 1;
for (i = 0; i < AID_MAX; i++)
p->conf.capabilities.mp[i] = 0;
p->conf.capabilities.refresh = 1; p->conf.capabilities.refresh = 1;
p->conf.capabilities.grestart.restart = 1; p->conf.capabilities.grestart.restart = 1;
p->conf.capabilities.as4byte = 1; p->conf.capabilities.as4byte = 1;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: printconf.c,v 1.169 2024/01/10 13:31:09 claudio Exp $ */ /* $OpenBSD: printconf.c,v 1.170 2024/03/20 09:35:46 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -920,7 +920,7 @@ print_announce(struct peer_config *p, const char *c)
if (p->announce_capa == 0) if (p->announce_capa == 0)
printf("%s\tannounce capabilities no\n", c); printf("%s\tannounce capabilities no\n", c);
for (aid = 0; aid < AID_MAX; aid++) for (aid = AID_MIN; aid < AID_MAX; aid++)
if (p->capabilities.mp[aid]) if (p->capabilities.mp[aid])
printf("%s\tannounce %s\n", c, aid2str(aid)); printf("%s\tannounce %s\n", c, aid2str(aid));

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rde.c,v 1.623 2024/02/22 06:45:22 miod Exp $ */ /* $OpenBSD: rde.c,v 1.624 2024/03/20 09:35:46 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -442,7 +442,7 @@ rde_dispatch_imsg_session(struct imsgbuf *imsgbuf)
log_warnx("%s: wrong imsg len", __func__); log_warnx("%s: wrong imsg len", __func__);
break; break;
} }
if (aid >= AID_MAX) { if (aid < AID_MIN || aid >= AID_MAX) {
log_warnx("%s: bad AID", __func__); log_warnx("%s: bad AID", __func__);
break; break;
} }
@ -1328,7 +1328,7 @@ rde_dispatch_imsg_peer(struct rde_peer *peer, void *bula)
log_warnx("route refresh: wrong imsg len"); log_warnx("route refresh: wrong imsg len");
break; break;
} }
if (rr.aid >= AID_MAX) { if (rr.aid < AID_MIN || rr.aid >= AID_MAX) {
log_peer_warnx(&peer->conf, log_peer_warnx(&peer->conf,
"route refresh: bad AID %d", rr.aid); "route refresh: bad AID %d", rr.aid);
break; break;
@ -3326,7 +3326,7 @@ rde_update_queue_pending(void)
continue; continue;
if (peer->throttled) if (peer->throttled)
continue; continue;
for (aid = 0; aid < AID_MAX; aid++) { for (aid = AID_MIN; aid < AID_MAX; aid++) {
if (!RB_EMPTY(&peer->updates[aid]) || if (!RB_EMPTY(&peer->updates[aid]) ||
!RB_EMPTY(&peer->withdraws[aid])) !RB_EMPTY(&peer->withdraws[aid]))
return 1; return 1;
@ -3821,7 +3821,7 @@ rde_softreconfig_in_done(void *arg, uint8_t dummy)
peer->reconf_out = 0; peer->reconf_out = 0;
} else if (peer->export_type == EXPORT_DEFAULT_ROUTE) { } else if (peer->export_type == EXPORT_DEFAULT_ROUTE) {
/* just resend the default route */ /* just resend the default route */
for (aid = 0; aid < AID_MAX; aid++) { for (aid = AID_MIN; aid < AID_MAX; aid++) {
if (peer->capa.mp[aid]) if (peer->capa.mp[aid])
up_generate_default(peer, aid); up_generate_default(peer, aid);
} }
@ -3831,7 +3831,7 @@ rde_softreconfig_in_done(void *arg, uint8_t dummy)
RECONF_RELOAD; RECONF_RELOAD;
} else if (peer->reconf_rib) { } else if (peer->reconf_rib) {
/* dump the full table to neighbors that changed rib */ /* dump the full table to neighbors that changed rib */
for (aid = 0; aid < AID_MAX; aid++) { for (aid = AID_MIN; aid < AID_MAX; aid++) {
if (peer->capa.mp[aid]) if (peer->capa.mp[aid])
peer_dump(peer, aid); peer_dump(peer, aid);
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rde_peer.c,v 1.35 2024/02/03 09:26:52 jsg Exp $ */ /* $OpenBSD: rde_peer.c,v 1.36 2024/03/20 09:35:46 claudio Exp $ */
/* /*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
@ -44,18 +44,15 @@ peer_has_as4byte(struct rde_peer *peer)
return (peer->capa.as4byte); return (peer->capa.as4byte);
} }
/*
* Check if ADD_PATH is enabled for aid and mode (rx / tx). If aid is
* AID_UNSPEC then the function returns true if any aid has mode enabled.
*/
int int
peer_has_add_path(struct rde_peer *peer, uint8_t aid, int mode) peer_has_add_path(struct rde_peer *peer, uint8_t aid, int mode)
{ {
if (aid >= AID_MAX) if (aid >= AID_MAX)
return 0; return 0;
if (aid == AID_UNSPEC) {
/* check if at capability is set for at least one AID */
for (aid = AID_MIN; aid < AID_MAX; aid++)
if (peer->capa.add_path[aid] & mode)
return 1;
return 0;
}
return (peer->capa.add_path[aid] & mode); return (peer->capa.add_path[aid] & mode);
} }
@ -444,7 +441,7 @@ peer_up(struct rde_peer *peer, struct session_up *sup)
} }
peer->state = PEER_UP; peer->state = PEER_UP;
for (i = 0; i < AID_MAX; i++) { for (i = AID_MIN; i < AID_MAX; i++) {
if (peer->capa.mp[i]) if (peer->capa.mp[i])
peer_dump(peer, i); peer_dump(peer, i);
} }
@ -500,7 +497,7 @@ peer_flush(struct rde_peer *peer, uint8_t aid, time_t staletime)
/* every route is gone so reset staletime */ /* every route is gone so reset staletime */
if (aid == AID_UNSPEC) { if (aid == AID_UNSPEC) {
uint8_t i; uint8_t i;
for (i = 0; i < AID_MAX; i++) for (i = AID_MIN; i < AID_MAX; i++)
peer->staletime[i] = 0; peer->staletime[i] = 0;
} else { } else {
peer->staletime[aid] = 0; peer->staletime[aid] = 0;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: session.c,v 1.463 2024/02/19 10:15:35 job Exp $ */ /* $OpenBSD: session.c,v 1.464 2024/03/20 09:35:46 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
@ -68,7 +68,7 @@ void session_tcp_established(struct peer *);
void session_capa_ann_none(struct peer *); void session_capa_ann_none(struct peer *);
int session_capa_add(struct ibuf *, uint8_t, uint8_t); int session_capa_add(struct ibuf *, uint8_t, uint8_t);
int session_capa_add_mp(struct ibuf *, uint8_t); int session_capa_add_mp(struct ibuf *, uint8_t);
int session_capa_add_afi(struct peer *, struct ibuf *, uint8_t, uint8_t); int session_capa_add_afi(struct ibuf *, uint8_t, uint8_t);
struct bgp_msg *session_newmsg(enum msg_type, uint16_t); struct bgp_msg *session_newmsg(enum msg_type, uint16_t);
int session_sendmsg(struct bgp_msg *, struct peer *); int session_sendmsg(struct bgp_msg *, struct peer *);
void session_open(struct peer *); void session_open(struct peer *);
@ -1357,8 +1357,7 @@ session_capa_add_mp(struct ibuf *buf, uint8_t aid)
} }
int int
session_capa_add_afi(struct peer *p, struct ibuf *b, uint8_t aid, session_capa_add_afi(struct ibuf *b, uint8_t aid, uint8_t flags)
uint8_t flags)
{ {
u_int errs = 0; u_int errs = 0;
uint16_t afi; uint16_t afi;
@ -1492,7 +1491,7 @@ session_open(struct peer *p)
} }
/* multiprotocol extensions, RFC 4760 */ /* multiprotocol extensions, RFC 4760 */
for (i = 0; i < AID_MAX; i++) for (i = AID_MIN; i < AID_MAX; i++)
if (p->capa.ann.mp[i]) { /* 4 bytes data */ if (p->capa.ann.mp[i]) { /* 4 bytes data */
errs += session_capa_add(opb, CAPA_MP, 4); errs += session_capa_add(opb, CAPA_MP, 4);
errs += session_capa_add_mp(opb, i); errs += session_capa_add_mp(opb, i);
@ -1517,7 +1516,7 @@ session_open(struct peer *p)
int rst = 0; int rst = 0;
uint16_t hdr = 0; uint16_t hdr = 0;
for (i = 0; i < AID_MAX; i++) { for (i = AID_MIN; i < AID_MAX; i++) {
if (p->capa.neg.grestart.flags[i] & CAPA_GR_RESTARTING) if (p->capa.neg.grestart.flags[i] & CAPA_GR_RESTARTING)
rst++; rst++;
} }
@ -1536,7 +1535,7 @@ session_open(struct peer *p)
} }
/* advertisement of multiple paths, RFC7911 */ /* advertisement of multiple paths, RFC7911 */
if (p->capa.ann.add_path[0]) { /* variable */ if (p->capa.ann.add_path[AID_MIN]) { /* variable */
uint8_t aplen; uint8_t aplen;
if (mpcapa) if (mpcapa)
@ -1547,12 +1546,12 @@ session_open(struct peer *p)
if (mpcapa) { if (mpcapa) {
for (i = AID_MIN; i < AID_MAX; i++) { for (i = AID_MIN; i < AID_MAX; i++) {
if (p->capa.ann.mp[i]) { if (p->capa.ann.mp[i]) {
errs += session_capa_add_afi(p, opb, errs += session_capa_add_afi(opb,
i, p->capa.ann.add_path[i]); i, p->capa.ann.add_path[i]);
} }
} }
} else { /* AID_INET */ } else { /* AID_INET */
errs += session_capa_add_afi(p, opb, AID_INET, errs += session_capa_add_afi(opb, AID_INET,
p->capa.ann.add_path[AID_INET]); p->capa.ann.add_path[AID_INET]);
} }
} }
@ -1759,7 +1758,7 @@ session_neighbor_rrefresh(struct peer *p)
if (!(p->capa.neg.refresh || p->capa.neg.enhanced_rr)) if (!(p->capa.neg.refresh || p->capa.neg.enhanced_rr))
return (-1); return (-1);
for (i = 0; i < AID_MAX; i++) { for (i = AID_MIN; i < AID_MAX; i++) {
if (p->capa.neg.mp[i] != 0) if (p->capa.neg.mp[i] != 0)
session_rrefresh(p, i, ROUTE_REFRESH_REQUEST); session_rrefresh(p, i, ROUTE_REFRESH_REQUEST);
} }
@ -1828,7 +1827,7 @@ session_graceful_restart(struct peer *p)
timer_set(&p->timers, Timer_RestartTimeout, timer_set(&p->timers, Timer_RestartTimeout,
p->capa.neg.grestart.timeout); p->capa.neg.grestart.timeout);
for (i = 0; i < AID_MAX; i++) { for (i = AID_MIN; i < AID_MAX; i++) {
if (p->capa.neg.grestart.flags[i] & CAPA_GR_PRESENT) { if (p->capa.neg.grestart.flags[i] & CAPA_GR_PRESENT) {
if (imsg_rde(IMSG_SESSION_STALE, p->conf.id, if (imsg_rde(IMSG_SESSION_STALE, p->conf.id,
&i, sizeof(i)) == -1) &i, sizeof(i)) == -1)
@ -1854,7 +1853,7 @@ session_graceful_stop(struct peer *p)
{ {
uint8_t i; uint8_t i;
for (i = 0; i < AID_MAX; i++) { for (i = AID_MIN; i < AID_MAX; i++) {
/* /*
* Only flush if the peer is restarting and the timeout fired. * Only flush if the peer is restarting and the timeout fired.
* In all other cases the session was already flushed when the * In all other cases the session was already flushed when the
@ -2485,7 +2484,6 @@ parse_notification(struct peer *peer)
uint8_t capa_code; uint8_t capa_code;
uint8_t capa_len; uint8_t capa_len;
size_t reason_len; size_t reason_len;
uint8_t i;
/* just log */ /* just log */
p = peer->rbuf->rptr; p = peer->rbuf->rptr;
@ -2545,8 +2543,8 @@ parse_notification(struct peer *peer)
datalen -= capa_len; datalen -= capa_len;
switch (capa_code) { switch (capa_code) {
case CAPA_MP: case CAPA_MP:
for (i = 0; i < AID_MAX; i++) memset(peer->capa.ann.mp, 0,
peer->capa.ann.mp[i] = 0; sizeof(peer->capa.ann.mp));
log_peer_warnx(&peer->conf, log_peer_warnx(&peer->conf,
"disabling multiprotocol capability"); "disabling multiprotocol capability");
break; break;
@ -2840,12 +2838,11 @@ capa_neg_calc(struct peer *p, uint8_t *suberr)
(p->capa.ann.refresh && p->capa.peer.refresh) != 0; (p->capa.ann.refresh && p->capa.peer.refresh) != 0;
p->capa.neg.enhanced_rr = p->capa.neg.enhanced_rr =
(p->capa.ann.enhanced_rr && p->capa.peer.enhanced_rr) != 0; (p->capa.ann.enhanced_rr && p->capa.peer.enhanced_rr) != 0;
p->capa.neg.as4byte = p->capa.neg.as4byte =
(p->capa.ann.as4byte && p->capa.peer.as4byte) != 0; (p->capa.ann.as4byte && p->capa.peer.as4byte) != 0;
/* MP: both side must agree on the AFI,SAFI pair */ /* MP: both side must agree on the AFI,SAFI pair */
for (i = 0; i < AID_MAX; i++) { for (i = AID_MIN; i < AID_MAX; i++) {
if (p->capa.ann.mp[i] && p->capa.peer.mp[i]) if (p->capa.ann.mp[i] && p->capa.peer.mp[i])
p->capa.neg.mp[i] = 1; p->capa.neg.mp[i] = 1;
else else
@ -2866,7 +2863,7 @@ capa_neg_calc(struct peer *p, uint8_t *suberr)
* supporting graceful restart. * supporting graceful restart.
*/ */
for (i = 0; i < AID_MAX; i++) { for (i = AID_MIN; i < AID_MAX; i++) {
int8_t negflags; int8_t negflags;
/* disable GR if the AFI/SAFI is not present */ /* disable GR if the AFI/SAFI is not present */
@ -2898,15 +2895,14 @@ capa_neg_calc(struct peer *p, uint8_t *suberr)
if (p->capa.ann.grestart.restart == 0) if (p->capa.ann.grestart.restart == 0)
p->capa.neg.grestart.restart = 0; p->capa.neg.grestart.restart = 0;
/* /*
* ADD-PATH: set only those bits where both sides agree. * ADD-PATH: set only those bits where both sides agree.
* For this compare our send bit with the recv bit from the peer * For this compare our send bit with the recv bit from the peer
* and vice versa. * and vice versa.
* The flags are stored from this systems view point. * The flags are stored from this systems view point.
* At index 0 the flags are set if any per-AID flag is set.
*/ */
memset(p->capa.neg.add_path, 0, sizeof(p->capa.neg.add_path)); memset(p->capa.neg.add_path, 0, sizeof(p->capa.neg.add_path));
if (p->capa.ann.add_path[0]) {
for (i = AID_MIN; i < AID_MAX; i++) { for (i = AID_MIN; i < AID_MAX; i++) {
if ((p->capa.ann.add_path[i] & CAPA_AP_RECV) && if ((p->capa.ann.add_path[i] & CAPA_AP_RECV) &&
(p->capa.peer.add_path[i] & CAPA_AP_SEND)) { (p->capa.peer.add_path[i] & CAPA_AP_SEND)) {
@ -2919,7 +2915,6 @@ capa_neg_calc(struct peer *p, uint8_t *suberr)
p->capa.neg.add_path[0] |= CAPA_AP_SEND; p->capa.neg.add_path[0] |= CAPA_AP_SEND;
} }
} }
}
/* /*
* Open policy: check that the policy is sensible. * Open policy: check that the policy is sensible.
@ -3323,7 +3318,7 @@ session_dispatch_imsg(struct imsgbuf *imsgbuf, int idx, u_int *listener_cnt)
log_warnx("no such peer: id=%u", peerid); log_warnx("no such peer: id=%u", peerid);
break; break;
} }
if (rr.aid >= AID_MAX) if (rr.aid < AID_MIN || rr.aid >= AID_MAX)
fatalx("IMSG_REFRESH: bad AID"); fatalx("IMSG_REFRESH: bad AID");
session_rrefresh(p, rr.aid, rr.subtype); session_rrefresh(p, rr.aid, rr.subtype);
break; break;
@ -3338,7 +3333,7 @@ session_dispatch_imsg(struct imsgbuf *imsgbuf, int idx, u_int *listener_cnt)
log_warnx("no such peer: id=%u", peerid); log_warnx("no such peer: id=%u", peerid);
break; break;
} }
if (aid >= AID_MAX) if (aid < AID_MIN || aid >= AID_MAX)
fatalx("IMSG_SESSION_RESTARTED: bad AID"); fatalx("IMSG_SESSION_RESTARTED: bad AID");
if (p->capa.neg.grestart.flags[aid] & if (p->capa.neg.grestart.flags[aid] &
CAPA_GR_RESTARTING) { CAPA_GR_RESTARTING) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: util.c,v 1.82 2024/02/22 06:45:22 miod Exp $ */ /* $OpenBSD: util.c,v 1.83 2024/03/20 09:35:46 claudio Exp $ */
/* /*
* Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org>
@ -922,7 +922,7 @@ aid2str(uint8_t aid)
int int
aid2afi(uint8_t aid, uint16_t *afi, uint8_t *safi) aid2afi(uint8_t aid, uint16_t *afi, uint8_t *safi)
{ {
if (aid < AID_MAX) { if (aid != AID_UNSPEC && aid < AID_MAX) {
*afi = aid_vals[aid].afi; *afi = aid_vals[aid].afi;
*safi = aid_vals[aid].safi; *safi = aid_vals[aid].safi;
return (0); return (0);
@ -935,7 +935,7 @@ afi2aid(uint16_t afi, uint8_t safi, uint8_t *aid)
{ {
uint8_t i; uint8_t i;
for (i = 0; i < AID_MAX; i++) for (i = AID_MIN; i < AID_MAX; i++)
if (aid_vals[i].afi == afi && aid_vals[i].safi == safi) { if (aid_vals[i].afi == afi && aid_vals[i].safi == safi) {
*aid = i; *aid = i;
return (0); return (0);
@ -960,7 +960,7 @@ af2aid(sa_family_t af, uint8_t safi, uint8_t *aid)
if (safi == 0) /* default to unicast subclass */ if (safi == 0) /* default to unicast subclass */
safi = SAFI_UNICAST; safi = SAFI_UNICAST;
for (i = 0; i < AID_MAX; i++) for (i = AID_UNSPEC; i < AID_MAX; i++)
if (aid_vals[i].af == af && aid_vals[i].safi == safi) { if (aid_vals[i].af == af && aid_vals[i].safi == safi) {
*aid = i; *aid = i;
return (0); return (0);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: x509.c,v 1.82 2024/03/19 05:04:13 tb Exp $ */ /* $OpenBSD: x509.c,v 1.83 2024/03/20 04:36:30 job Exp $ */
/* /*
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org> * Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
* Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
@ -536,7 +536,23 @@ x509_get_sia(X509 *x, const char *fn, char **sia)
continue; continue;
if (strncasecmp(*sia, "rsync://", 8) == 0) { if (strncasecmp(*sia, "rsync://", 8) == 0) {
const char *p = *sia + strlen("rsync://");
size_t fnlen, plen;
rsync_found = 1; rsync_found = 1;
if (filemode)
continue;
fnlen = strlen(fn);
plen = strlen(p);
if (fnlen < plen || strcmp(p, fn + fnlen - plen) != 0) {
warnx("%s: mismatch between pathname and SIA "
"(%s)", fn, *sia);
goto out;
}
continue; continue;
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: smtp_session.c,v 1.441 2024/01/28 17:23:17 op Exp $ */ /* $OpenBSD: smtp_session.c,v 1.442 2024/03/20 17:52:43 op Exp $ */
/* /*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@ -2481,7 +2481,7 @@ smtp_tx_rcpt_to(struct smtp_tx *tx, const char *line)
if ((p = strchr(opt, ';')) == NULL || if ((p = strchr(opt, ';')) == NULL ||
!valid_xtext(p + 1) || !valid_xtext(p + 1) ||
strlcpy(opt, tx->evp.dsn_orcpt, len) >= len) { strlcpy(tx->evp.dsn_orcpt, opt, len) >= len) {
smtp_reply(tx->session, smtp_reply(tx->session,
"553 ORCPT address syntax error"); "553 ORCPT address syntax error");
return; return;