Sat May 4 02:04:55 2024 UTC (16d)
Initialize `struct consdev` members cn_dev and cn_pri like other
UART drivers do.  If cn_dev is 0 instead of NODEV, then the kernel
may redirect console writes to major 0, minor 0, which is /dev/mem.
On my Zynq board the kernel overwrote the page free list with a
console message in this way.


(dyoung)
diff -r1.5 -r1.6 src/sys/arch/arm/xilinx/zynq_uart.c

cvs diff -r1.5 -r1.6 src/sys/arch/arm/xilinx/zynq_uart.c (expand / switch to unified diff)

--- src/sys/arch/arm/xilinx/zynq_uart.c 2022/10/27 07:57:46 1.5
+++ src/sys/arch/arm/xilinx/zynq_uart.c 2024/05/04 02:04:54 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: zynq_uart.c,v 1.5 2022/10/27 07:57:46 skrll Exp $ */ 1/* $NetBSD: zynq_uart.c,v 1.6 2024/05/04 02:04:54 dyoung Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2012 Genetec Corporation. All rights reserved. 4 * Copyright (c) 2012 Genetec Corporation. All rights reserved.
5 * Written by Hiroyuki Bessho, Hashimoto Kenichi for Genetec Corporation. 5 * Written by Hiroyuki Bessho, Hashimoto Kenichi for Genetec Corporation.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -86,27 +86,27 @@ @@ -86,27 +86,27 @@
86 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 86 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
87 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 87 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
88 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 88 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89 * SUCH DAMAGE. 89 * SUCH DAMAGE.
90 * 90 *
91 * @(#)com.c 7.5 (Berkeley) 5/16/91 91 * @(#)com.c 7.5 (Berkeley) 5/16/91
92 */ 92 */
93 93
94/* 94/*
95 * driver for UART in Zynq-7000. 95 * driver for UART in Zynq-7000.
96 */ 96 */
97 97
98#include <sys/cdefs.h> 98#include <sys/cdefs.h>
99__KERNEL_RCSID(0, "$NetBSD: zynq_uart.c,v 1.5 2022/10/27 07:57:46 skrll Exp $"); 99__KERNEL_RCSID(0, "$NetBSD: zynq_uart.c,v 1.6 2024/05/04 02:04:54 dyoung Exp $");
100 100
101#include "opt_soc.h" 101#include "opt_soc.h"
102#include "opt_console.h" 102#include "opt_console.h"
103#include "opt_com.h" 103#include "opt_com.h"
104#include "opt_ddb.h" 104#include "opt_ddb.h"
105#include "opt_kgdb.h" 105#include "opt_kgdb.h"
106#include "opt_ntp.h" 106#include "opt_ntp.h"
107 107
108/* 108/*
109 * Override cnmagic(9) macro before including <sys/systm.h>. 109 * Override cnmagic(9) macro before including <sys/systm.h>.
110 * We need to know if cn_check_magic triggered debugger, so set a flag. 110 * We need to know if cn_check_magic triggered debugger, so set a flag.
111 * Callers of cn_check_magic must declare int cn_trapped = 0; 111 * Callers of cn_check_magic must declare int cn_trapped = 0;
112 * XXX: this is *ugly*! 112 * XXX: this is *ugly*!
@@ -1964,27 +1964,29 @@ zynquart_init(struct zynquart_regs *regs @@ -1964,27 +1964,29 @@ zynquart_init(struct zynquart_regs *regs
1964 bus_space_write_4(regsp->ur_iot, regsp->ur_ioh, UART_CHANNEL_STS, 0xffff); 1964 bus_space_write_4(regsp->ur_iot, regsp->ur_ioh, UART_CHANNEL_STS, 0xffff);
1965 1965
1966 return (0); 1966 return (0);
1967} 1967}
1968 1968
1969 1969
1970 1970
1971/* 1971/*
1972 * Following are all routines needed for UART to act as console 1972 * Following are all routines needed for UART to act as console
1973 */ 1973 */
1974struct consdev zynquartcons = { 1974struct consdev zynquartcons = {
1975 .cn_getc = zynquartcngetc, 1975 .cn_getc = zynquartcngetc,
1976 .cn_putc = zynquartcnputc, 1976 .cn_putc = zynquartcnputc,
1977 .cn_pollc = nullcnpollc 1977 .cn_pollc = nullcnpollc,
 1978 .cn_dev = NODEV,
 1979 .cn_pri = CN_NORMAL,
1978}; 1980};
1979 1981
1980 1982
1981int 1983int
1982zynquart_cons_attach(bus_space_tag_t iot, paddr_t iobase, u_int rate, 1984zynquart_cons_attach(bus_space_tag_t iot, paddr_t iobase, u_int rate,
1983 tcflag_t cflag) 1985 tcflag_t cflag)
1984{ 1986{
1985 struct zynquart_regs regs; 1987 struct zynquart_regs regs;
1986 int res; 1988 int res;
1987 1989
1988 regs.ur_iot = iot; 1990 regs.ur_iot = iot;
1989 regs.ur_iobase = iobase; 1991 regs.ur_iobase = iobase;
1990 1992