From 361861c7dda36dbc0bd6f7533bf09f14c4c8d084 Mon Sep 17 00:00:00 2001 From: purplerain Date: Sat, 2 Sep 2023 04:20:23 +0000 Subject: [PATCH] sync code with last improvements from OpenBSD --- lib/libcrypto/evp/p_lib.c | 12 +-- lib/libcrypto/man/EVP_CIPHER_nid.3 | 157 ++++++++++++++++++++--------- sys/dev/mii/ytphy.c | 111 +++++++++++++++++++- sys/dev/usb/if_umb.c | 6 +- usr.bin/tmux/utf8-combined.c | 8 +- usr.sbin/vmd/i8259.c | 20 ++-- usr.sbin/vmd/vioblk.c | 14 ++- usr.sbin/vmd/vionet.c | 14 ++- 8 files changed, 257 insertions(+), 85 deletions(-) diff --git a/lib/libcrypto/evp/p_lib.c b/lib/libcrypto/evp/p_lib.c index 85e7978ff..e8f031714 100644 --- a/lib/libcrypto/evp/p_lib.c +++ b/lib/libcrypto/evp/p_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: p_lib.c,v 1.34 2023/07/07 19:37:54 beck Exp $ */ +/* $OpenBSD: p_lib.c,v 1.35 2023/09/01 17:12:19 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -439,11 +439,11 @@ EVP_PKEY_get0_hmac(const EVP_PKEY *pkey, size_t *len) RSA * EVP_PKEY_get0_RSA(EVP_PKEY *pkey) { - if (pkey->type != EVP_PKEY_RSA) { - EVPerror(EVP_R_EXPECTING_AN_RSA_KEY); - return NULL; - } - return pkey->pkey.rsa; + if (pkey->type == EVP_PKEY_RSA || pkey->type == EVP_PKEY_RSA_PSS) + return pkey->pkey.rsa; + + EVPerror(EVP_R_EXPECTING_AN_RSA_KEY); + return NULL; } RSA * diff --git a/lib/libcrypto/man/EVP_CIPHER_nid.3 b/lib/libcrypto/man/EVP_CIPHER_nid.3 index 3a3c42d0b..1c0683980 100644 --- a/lib/libcrypto/man/EVP_CIPHER_nid.3 +++ b/lib/libcrypto/man/EVP_CIPHER_nid.3 @@ -1,10 +1,11 @@ -.\" $OpenBSD: EVP_CIPHER_nid.3,v 1.1 2023/08/31 17:27:41 schwarze Exp $ -.\" full merge up to: OpenSSL 5211e094 Nov 11 14:39:11 2014 -0800 +.\" $OpenBSD: EVP_CIPHER_nid.3,v 1.2 2023/09/01 17:28:21 schwarze Exp $ +.\" full merge up to: OpenSSL man3/EVP_EncryptInit.pod +.\" 0874d7f2 Oct 11 13:13:47 2022 +0100 .\" .\" This file is a derived work. .\" The changes are covered by the following Copyright and license: .\" -.\" Copyright (c) 2018 Ingo Schwarze +.\" Copyright (c) 2018, 2023 Ingo Schwarze .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above @@ -65,7 +66,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED .\" OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: August 31 2023 $ +.Dd $Mdocdate: September 1 2023 $ .Dt EVP_CIPHER_NID 3 .Os .Sh NAME @@ -84,7 +85,7 @@ .In openssl/evp.h .Ft int .Fo EVP_CIPHER_nid -.Fa "const EVP_CIPHER *e" +.Fa "const EVP_CIPHER *cipher" .Fc .Ft int .Fo EVP_CIPHER_CTX_nid @@ -100,7 +101,7 @@ .Fc .Ft int .Fo EVP_CIPHER_block_size -.Fa "const EVP_CIPHER *e" +.Fa "const EVP_CIPHER *cipher" .Fc .Ft int .Fo EVP_CIPHER_CTX_block_size @@ -108,7 +109,7 @@ .Fc .Ft unsigned long .Fo EVP_CIPHER_flags -.Fa "const EVP_CIPHER *e" +.Fa "const EVP_CIPHER *cipher" .Fc .Ft unsigned long .Fo EVP_CIPHER_CTX_flags @@ -116,7 +117,7 @@ .Fc .Ft unsigned long .Fo EVP_CIPHER_mode -.Fa "const EVP_CIPHER *e" +.Fa "const EVP_CIPHER *cipher" .Fc .Ft unsigned long .Fo EVP_CIPHER_CTX_mode @@ -124,74 +125,124 @@ .Fc .Sh DESCRIPTION .Fn EVP_CIPHER_nid -and +returns the numerical identifier (NID) of the +.Fa cipher . +The NID is an internal value which may or may not have a corresponding +ASN.1 OBJECT IDENTIFIER; see +.Xr OBJ_nid2obj 3 +for details. +.Pp .Fn EVP_CIPHER_CTX_nid -return the NID of a cipher when passed an -.Vt EVP_CIPHER -or -.Vt EVP_CIPHER_CTX -structure. -The actual NID value is an internal value which may not have a -corresponding OBJECT IDENTIFIER. +returns the NID of the cipher that +.Fa ctx +is configured to use. .Pp .Fn EVP_CIPHER_type +returns the NID associated with the ASN.1 OBJECT IDENTIFIER of the +.Fa cipher , +ignoring the cipher parameters. +For example, +.Xr EVP_aes_256_cfb1 3 , +.Xr EVP_aes_256_cfb8 3 , and +.Xr EVP_aes_256_cfb128 3 +all return the same NID, +.Dv NID_aes_256_cfb128 . +.Pp .Fn EVP_CIPHER_CTX_type -return the type of the passed cipher or context. -This "type" is the actual NID of the cipher OBJECT IDENTIFIER as such it -ignores the cipher parameters and 40-bit RC2 and 128-bit RC2 have the -same NID. -If the cipher does not have an object identifier or does not -have ASN.1 support, this function will return -.Dv NID_undef . +returns the NID associated with the ASN.1 OBJECT IDENTIFIER of the cipher that +.Fa ctx +is configured to use. .Pp .Fn EVP_CIPHER_block_size -and +returns the block size of the +.Fa cipher +in bytes. .Fn EVP_CIPHER_CTX_block_size -return the block size of a cipher when passed an -.Vt EVP_CIPHER -or -.Vt EVP_CIPHER_CTX -structure. -The constant -.Dv EVP_MAX_BLOCK_LENGTH -is also the maximum block length for all ciphers. +returns the block size of the cipher that +.Fa ctx +is configured to use. +Block sizes are guaranteed to be less than or equal to the constant +.Dv EVP_MAX_BLOCK_LENGTH . +Currently, +.Xr EVP_CipherInit_ex 3 +and the other functions documented in the same manual page +only support block sizes of 1, 8, and 16 bytes. +.Pp +.Fn EVP_CIPHER_flags +returns the cipher flags used by the +.Fa cipher . +The meaning of the flags is described in the +.Xr EVP_CIPHER_meth_set_flags 3 +manual page. +.Pp +.Fn EVP_CIPHER_CTX_flags +returns the cipher flags of the cipher that +.Fa ctx +is configured to use. +Be careful to not confuse these with the unrelated cipher context flags +that can be inspected with +.Xr EVP_CIPHER_CTX_test_flags 3 . .Pp .Fn EVP_CIPHER_mode -and +returns the +.Fa cipher +mode, which is the logical AND of the constant +.Dv EVP_CIPH_MODE +and the return value of +.Fn EVP_CIPHER_flags . +.Pp .Fn EVP_CIPHER_CTX_mode -return the block cipher mode: -.Dv EVP_CIPH_ECB_MODE , -.Dv EVP_CIPH_CBC_MODE , -.Dv EVP_CIPH_CFB_MODE , -.Dv EVP_CIPH_OFB_MODE , -.Dv EVP_CIPH_CTR_MODE , -or -.Dv EVP_CIPH_XTS_MODE . -If the cipher is a stream cipher then -.Dv EVP_CIPH_STREAM_CIPHER -is returned. +returns the cipher mode of the cipher that +.Fa ctx +is configured to use. .Sh RETURN VALUES .Fn EVP_CIPHER_nid and .Fn EVP_CIPHER_CTX_nid -return a NID. +return an NID. .Pp .Fn EVP_CIPHER_type and .Fn EVP_CIPHER_CTX_type return the NID of the cipher's OBJECT IDENTIFIER or .Dv NID_undef -if it has no defined OBJECT IDENTIFIER. +if it is not associated with an OBJECT IDENTIFIER. .Pp .Fn EVP_CIPHER_block_size and .Fn EVP_CIPHER_CTX_block_size -return the block size. +return the block size in bytes. +.Pp +.Fn EVP_CIPHER_flags +and +.Fn EVP_CIPHER_CTX_flags +return one or more +.Dv EVP_CIPH_* +flag bits OR'ed together. +.Pp +.Fn EVP_CIPHER_mode +and +.Fn EVP_CIPHER_CTX_mode +return one of the constants +.Dv EVP_CIPH_ECB_MODE , +.Dv EVP_CIPH_CBC_MODE , +.Dv EVP_CIPH_CFB_MODE , +.Dv EVP_CIPH_OFB_MODE , +.Dv EVP_CIPH_CTR_MODE , +.Dv EVP_CIPH_GCM_MODE , +.Dv EVP_CIPH_CCM_MODE , +.Dv EVP_CIPH_XTS_MODE , +or +.Dv EVP_CIPH_WRAP_MODE +to indicate a block cipher or +.Dv EVP_CIPH_STREAM_CIPHER +to indicate a stream cipher. .Sh SEE ALSO .Xr evp 3 , .Xr EVP_CIPHER_CTX_ctrl 3 , -.Xr EVP_EncryptInit 3 +.Xr EVP_EncryptInit 3 , +.Xr OBJ_nid2obj 3 .Sh HISTORY .Fn EVP_CIPHER_type , .Fn EVP_CIPHER_CTX_type , @@ -213,3 +264,13 @@ and .Fn EVP_CIPHER_CTX_mode first appeared in OpenSSL 0.9.6 and have been available since .Ox 2.9 . +.Sh CAVEATS +The behaviour of the functions taking an +.Vt EVP_CIPHER_CTX +argument is undefined if they are called on a +.Fa ctx +that has no cipher configured yet, for example one freshly returned from +.Xr EVP_CIPHER_CTX_new 3 . +In that case, the program may for example be terminated by a +.Dv NULL +pointer access. diff --git a/sys/dev/mii/ytphy.c b/sys/dev/mii/ytphy.c index 00aa82e2c..ec7fca8ae 100644 --- a/sys/dev/mii/ytphy.c +++ b/sys/dev/mii/ytphy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ytphy.c,v 1.3 2023/07/08 08:18:30 kettenis Exp $ */ +/* $OpenBSD: ytphy.c,v 1.4 2023/09/01 20:35:31 kettenis Exp $ */ /* * Copyright (c) 2001 Theo de Raadt * Copyright (c) 2023 Mark Kettenis @@ -57,12 +57,22 @@ #define YT8521_EXT_CHIP_CONFIG 0xa001 #define YT8521_RXC_DLY_EN (1 << 8) +#define YT8521_CFG_LDO_MASK (0x3 << 4) +#define YT8521_CFG_LDO_3V3 0x0 +#define YT8521_CFG_LDO_2V5 0x1 +#define YT8521_CFG_LDO_1V8 0x2 /* or 0x3 */ #define YT8521_EXT_RGMII_CONFIG1 0xa003 #define YT8521_TX_CLK_SEL (1 << 14) #define YT8521_RX_DELAY_SEL_MASK (0xf << 10) #define YT8521_RX_DELAY_SEL_SHIFT 10 #define YT8521_TX_DELAY_SEL_MASK (0xf << 0) #define YT8521_TX_DELAY_SEL_SHIFT 0 +#define YT8521_EXT_PAD_DRIVE_STRENGTH 0xa010 +#define YT8531_RGMII_RXC_DS_MASK (0x7 << 13) +#define YT8531_RGMII_RXC_DS_SHIFT 13 +#define YT8531_RGMII_RXD_DS_MASK ((0x1 << 12) | (0x3 << 4)) +#define YT8531_RGMII_RXD_DS_LOW(x) (((x) & 0x3) << 4) +#define YT8531_RGMII_RXD_DS_HIGH(x) (((x) >> 2) << 12) int ytphy_match(struct device *, void *, void *); void ytphy_attach(struct device *, struct device *, void *); @@ -79,6 +89,7 @@ int ytphy_service(struct mii_softc *, struct mii_data *, int); void ytphy_yt8511_init(struct mii_softc *); void ytphy_yt8521_init(struct mii_softc *); void ytphy_yt8521_update(struct mii_softc *); +void ytphy_yt8531_init(struct mii_softc *); const struct mii_phy_funcs ytphy_funcs = { ytphy_service, ukphy_status, mii_phy_reset, @@ -138,8 +149,10 @@ ytphy_attach(struct device *parent, struct device *self, void *aux) if (ma->mii_id1 == 0x0000 && ma->mii_id2 == 0x010a) ytphy_yt8511_init(sc); - else + else if (ma->mii_id1 == 0x0000 && ma->mii_id2 == 0x011a) ytphy_yt8521_init(sc); + else + ytphy_yt8531_init(sc); sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask; @@ -362,3 +375,97 @@ ytphy_yt8521_update(struct mii_softc *sc) PHY_WRITE(sc, YT8511_REG_ADDR, addr); #endif } + +/* The RGMII drive strength depends on the voltage level. */ + +struct ytphy_ds_map { + uint32_t volt; /* mV */ + uint16_t amp; /* uA */ + uint16_t ds; +}; + +struct ytphy_ds_map ytphy_yt8531_ds_map[] = { + { 1800, 1200, 0 }, + { 1800, 2100, 1 }, + { 1800, 2700, 2 }, + { 1800, 2910, 3 }, + { 1800, 3110, 4 }, + { 1800, 3600, 5 }, + { 1800, 3970, 6 }, + { 1800, 4350, 7 }, + { 3300, 3070, 0 }, + { 3300, 4080, 1 }, + { 3300, 4370, 2 }, + { 3300, 4680, 3 }, + { 3300, 5020, 4 }, + { 3300, 5450, 5 }, + { 3300, 5740, 6 }, + { 3300, 6140, 7 }, +}; + +uint32_t +ytphy_yt8531_ds(struct mii_softc *sc, uint32_t volt, uint32_t amp) +{ + int i; + + for (i = 0; i < nitems(ytphy_yt8531_ds_map); i++) { + if (ytphy_yt8531_ds_map[i].volt == volt && + ytphy_yt8531_ds_map[i].amp == amp) + return ytphy_yt8531_ds_map[i].ds; + } + + if (amp) { + printf("%s: unknown drive strength (%d uA at %d mV)\n", + sc->mii_dev.dv_xname, amp, volt); + } + + /* Default drive strength. */ + return 3; +} + +void +ytphy_yt8531_init(struct mii_softc *sc) +{ + uint32_t rx_clk_drv = 0; + uint32_t rx_data_drv = 0; + uint16_t addr, data; + uint16_t volt; + + ytphy_yt8521_init(sc); + +#ifdef __HAVE_FDT + if (sc->mii_pdata->mii_node) { + rx_clk_drv = OF_getpropint(sc->mii_pdata->mii_node, + "motorcomm,rx-clk-drv-microamp", 0); + rx_data_drv = OF_getpropint(sc->mii_pdata->mii_node, + "motorcomm,rx-data-drv-microamp", 0); + } +#endif + + /* Save address register. */ + addr = PHY_READ(sc, YT8511_REG_ADDR); + + PHY_WRITE(sc, YT8511_REG_ADDR, YT8521_EXT_CHIP_CONFIG); + data = PHY_READ(sc, YT8511_REG_DATA); + if ((data & YT8521_CFG_LDO_MASK) == YT8521_CFG_LDO_3V3) + volt = 3300; + else if ((data & YT8521_CFG_LDO_MASK) == YT8521_CFG_LDO_2V5) + volt = 2500; + else + volt = 1800; + + rx_clk_drv = ytphy_yt8531_ds(sc, volt, rx_clk_drv); + rx_data_drv = ytphy_yt8531_ds(sc, volt, rx_data_drv); + + PHY_WRITE(sc, YT8511_REG_ADDR, YT8521_EXT_PAD_DRIVE_STRENGTH); + data = PHY_READ(sc, YT8511_REG_DATA); + data &= ~YT8531_RGMII_RXC_DS_MASK; + data |= rx_clk_drv << YT8531_RGMII_RXC_DS_SHIFT; + data &= ~YT8531_RGMII_RXD_DS_MASK; + data |= YT8531_RGMII_RXD_DS_LOW(rx_data_drv); + data |= YT8531_RGMII_RXD_DS_HIGH(rx_data_drv); + PHY_WRITE(sc, YT8511_REG_DATA, data); + + /* Restore address register. */ + PHY_WRITE(sc, YT8511_REG_ADDR, addr); +} diff --git a/sys/dev/usb/if_umb.c b/sys/dev/usb/if_umb.c index 3df4ad88e..46ecb6842 100644 --- a/sys/dev/usb/if_umb.c +++ b/sys/dev/usb/if_umb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_umb.c,v 1.54 2023/08/29 23:28:38 dlg Exp $ */ +/* $OpenBSD: if_umb.c,v 1.55 2023/09/01 20:24:29 mvs Exp $ */ /* * Copyright (c) 2016 genua mbH @@ -1851,7 +1851,6 @@ umb_add_inet_config(struct umb_softc *sc, struct in_addr ip, u_int prefixlen, info.rti_info[RTAX_GATEWAY] = sintosa(&ifra.ifra_dstaddr); rv = rtrequest(RTM_ADD, &info, 0, &rt, ifp->if_rdomain); - NET_UNLOCK(); if (rv) { printf("%s: unable to set IPv4 default route, " "error %d\n", DEVNAM(ifp->if_softc), rv); @@ -1862,6 +1861,7 @@ umb_add_inet_config(struct umb_softc *sc, struct in_addr ip, u_int prefixlen, rtm_send(rt, RTM_ADD, rv, ifp->if_rdomain); rtfree(rt); } + NET_UNLOCK(); if (ifp->if_flags & IFF_DEBUG) { char str[3][INET_ADDRSTRLEN]; @@ -1932,7 +1932,6 @@ umb_add_inet6_config(struct umb_softc *sc, struct in6_addr *ip, u_int prefixlen, info.rti_info[RTAX_GATEWAY] = sin6tosa(&ifra.ifra_dstaddr); rv = rtrequest(RTM_ADD, &info, 0, &rt, ifp->if_rdomain); - NET_UNLOCK(); if (rv) { printf("%s: unable to set IPv6 default route, " "error %d\n", DEVNAM(ifp->if_softc), rv); @@ -1943,6 +1942,7 @@ umb_add_inet6_config(struct umb_softc *sc, struct in6_addr *ip, u_int prefixlen, rtm_send(rt, RTM_ADD, rv, ifp->if_rdomain); rtfree(rt); } + NET_UNLOCK(); if (ifp->if_flags & IFF_DEBUG) { char str[3][INET6_ADDRSTRLEN]; diff --git a/usr.bin/tmux/utf8-combined.c b/usr.bin/tmux/utf8-combined.c index c1bdb6978..18dffbf6f 100644 --- a/usr.bin/tmux/utf8-combined.c +++ b/usr.bin/tmux/utf8-combined.c @@ -1,4 +1,4 @@ -/* $OpenBSD: utf8-combined.c,v 1.1 2023/09/01 14:29:11 nicm Exp $ */ +/* $OpenBSD: utf8-combined.c,v 1.2 2023/09/01 18:43:54 nicm Exp $ */ /* * Copyright (c) 2023 Nicholas Marriott @@ -962,7 +962,7 @@ utf8_combined_first_cmp(struct utf8_combined_first *uf1, return (-1); if (ud1->size > ud2->size) return (1); - return (memcmp(ud1->data, ud2->data, sizeof *ud1->data)); + return (memcmp(ud1->data, ud2->data, ud1->size)); } RB_HEAD(utf8_combined_tree, utf8_combined_first); RB_GENERATE_STATIC(utf8_combined_tree, utf8_combined_first, entry, @@ -979,7 +979,7 @@ utf8_combined_second_cmp(const void *vp1, const void *vp2) return (-1); if (ud1->size > ud2->size) return (1); - return (memcmp(ud1->data, ud2->data, sizeof *ud1->data)); + return (memcmp(ud1->data, ud2->data, ud1->size)); } static int @@ -1035,7 +1035,7 @@ utf8_build_combined(void) wc = utf8_combined_table[i].first; mlen = wctomb(first.data, wc); if (mlen <= 0 || mlen > UTF8_SIZE) { - log_debug("invalid combined character %08X", wc); + log_debug("invalid combined character %05X", wc); continue; } first.size = mlen; diff --git a/usr.sbin/vmd/i8259.c b/usr.sbin/vmd/i8259.c index f7862f5e9..189598965 100644 --- a/usr.sbin/vmd/i8259.c +++ b/usr.sbin/vmd/i8259.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i8259.c,v 1.21 2022/11/10 18:58:02 mbuhl Exp $ */ +/* $OpenBSD: i8259.c,v 1.22 2023/09/01 19:42:26 dv Exp $ */ /* * Copyright (c) 2016 Mike Larkin * @@ -222,20 +222,16 @@ i8259_assert_irq(uint8_t irq) { mutex_lock(&pic_mtx); if (irq <= 7) { - if (!ISSET(pics[MASTER].imr, 1 << irq)) { - SET(pics[MASTER].irr, 1 << irq); - pics[MASTER].asserted = 1; - } + SET(pics[MASTER].irr, 1 << irq); + pics[MASTER].asserted = 1; } else { irq -= 8; - if (!ISSET(pics[SLAVE].imr, 1 << irq)) { - SET(pics[SLAVE].irr, 1 << irq); - pics[SLAVE].asserted = 1; + SET(pics[SLAVE].irr, 1 << irq); + pics[SLAVE].asserted = 1; - /* Assert cascade IRQ on master PIC */ - SET(pics[MASTER].irr, 1 << 2); - pics[MASTER].asserted = 1; - } + /* Assert cascade IRQ on master PIC */ + SET(pics[MASTER].irr, 1 << 2); + pics[MASTER].asserted = 1; } mutex_unlock(&pic_mtx); } diff --git a/usr.sbin/vmd/vioblk.c b/usr.sbin/vmd/vioblk.c index 7bc76c4da..ef38e9eb3 100644 --- a/usr.sbin/vmd/vioblk.c +++ b/usr.sbin/vmd/vioblk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vioblk.c,v 1.4 2023/05/28 05:28:50 asou Exp $ */ +/* $OpenBSD: vioblk.c,v 1.5 2023/09/01 19:42:26 dv Exp $ */ /* * Copyright (c) 2023 Dave Voutila @@ -39,7 +39,8 @@ extern char *__progname; extern struct vmd_vm *current_vm; static const char *disk_type(int); -static uint32_t handle_io_read(struct viodev_msg *, struct virtio_dev *); +static uint32_t handle_io_read(struct viodev_msg *, struct virtio_dev *, + int8_t *); static int handle_io_write(struct viodev_msg *, struct virtio_dev *); void vioblk_notify_rx(struct vioblk_dev *); int vioblk_notifyq(struct vioblk_dev *); @@ -723,6 +724,7 @@ handle_sync_io(int fd, short event, void *arg) struct viodev_msg msg; struct imsg imsg; ssize_t n; + int8_t intr = INTR_STATE_NOOP; if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) @@ -770,8 +772,9 @@ handle_sync_io(int fd, short event, void *arg) } case VIODEV_MSG_IO_READ: /* Read IO: make sure to send a reply */ - msg.data = handle_io_read(&msg, dev); + msg.data = handle_io_read(&msg, dev, &intr); msg.data_valid = 1; + msg.state = intr; imsg_compose_event(iev, IMSG_DEVOP_MSG, 0, 0, -1, &msg, sizeof(msg)); break; @@ -844,7 +847,7 @@ handle_io_write(struct viodev_msg *msg, struct virtio_dev *dev) } static uint32_t -handle_io_read(struct viodev_msg *msg, struct virtio_dev *dev) +handle_io_read(struct viodev_msg *msg, struct virtio_dev *dev, int8_t *intr) { struct vioblk_dev *vioblk = &dev->vioblk; uint8_t sz = msg->io_sz; @@ -1001,7 +1004,8 @@ handle_io_read(struct viodev_msg *msg, struct virtio_dev *dev) case VIRTIO_CONFIG_ISR_STATUS: data = vioblk->cfg.isr_status; vioblk->cfg.isr_status = 0; - virtio_deassert_pic_irq(dev, 0); + if (intr != NULL) + *intr = INTR_STATE_DEASSERT; break; default: return (0xFFFFFFFF); diff --git a/usr.sbin/vmd/vionet.c b/usr.sbin/vmd/vionet.c index c16ad2635..5123ad4c1 100644 --- a/usr.sbin/vmd/vionet.c +++ b/usr.sbin/vmd/vionet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vionet.c,v 1.3 2023/05/13 23:15:28 dv Exp $ */ +/* $OpenBSD: vionet.c,v 1.4 2023/09/01 19:42:26 dv Exp $ */ /* * Copyright (c) 2023 Dave Voutila @@ -52,7 +52,8 @@ struct event ev_tap; static int vionet_rx(struct vionet_dev *); static void vionet_rx_event(int, short, void *); -static uint32_t handle_io_read(struct viodev_msg *, struct virtio_dev *); +static uint32_t handle_io_read(struct viodev_msg *, struct virtio_dev *, + int8_t *); static int handle_io_write(struct viodev_msg *, struct virtio_dev *); void vionet_notify_rx(struct virtio_dev *); int vionet_notifyq(struct virtio_dev *); @@ -757,6 +758,7 @@ handle_sync_io(int fd, short event, void *arg) struct viodev_msg msg; struct imsg imsg; ssize_t n; + int8_t intr = INTR_STATE_NOOP; if (event & EV_READ) { if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) @@ -804,8 +806,9 @@ handle_sync_io(int fd, short event, void *arg) } case VIODEV_MSG_IO_READ: /* Read IO: make sure to send a reply */ - msg.data = handle_io_read(&msg, dev); + msg.data = handle_io_read(&msg, dev, &intr); msg.data_valid = 1; + msg.state = intr; imsg_compose_event(iev, IMSG_DEVOP_MSG, 0, 0, -1, &msg, sizeof(msg)); break; @@ -891,7 +894,7 @@ handle_io_write(struct viodev_msg *msg, struct virtio_dev *dev) } static uint32_t -handle_io_read(struct viodev_msg *msg, struct virtio_dev *dev) +handle_io_read(struct viodev_msg *msg, struct virtio_dev *dev, int8_t *intr) { struct vionet_dev *vionet = &dev->vionet; uint32_t data; @@ -930,7 +933,8 @@ handle_io_read(struct viodev_msg *msg, struct virtio_dev *dev) case VIRTIO_CONFIG_ISR_STATUS: data = vionet->cfg.isr_status; vionet->cfg.isr_status = 0; - virtio_deassert_pic_irq(dev, 0); + if (intr != NULL) + *intr = INTR_STATE_DEASSERT; break; default: return (0xFFFFFFFF);