CVS commit: src/sys/dev/i2c

2018-01-04 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Fri Jan  5 03:07:16 UTC 2018

Modified Files:
src/sys/dev/i2c: files.i2c
Added Files:
src/sys/dev/i2c: em3027.c em3027reg.h

Log Message:
Driver for EM Microelectronic EM3027 RTC and temperature sensor.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/i2c/em3027.c src/sys/dev/i2c/em3027reg.h
cvs rdiff -u -r1.80 -r1.81 src/sys/dev/i2c/files.i2c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/i2c/files.i2c
diff -u src/sys/dev/i2c/files.i2c:1.80 src/sys/dev/i2c/files.i2c:1.81
--- src/sys/dev/i2c/files.i2c:1.80	Thu Dec 28 23:23:47 2017
+++ src/sys/dev/i2c/files.i2c	Fri Jan  5 03:07:15 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files.i2c,v 1.80 2017/12/28 23:23:47 christos Exp $
+#	$NetBSD: files.i2c,v 1.81 2018/01/05 03:07:15 uwe Exp $
 
 obsolete defflag	opt_i2cbus.h		I2C_SCAN
 define	i2cbus { }
@@ -295,6 +295,11 @@ device	sy8106a
 attach	sy8106a at iic
 file	dev/i2c/sy8106a.c			sy8106a
 
+# EM3027 Real Time Clock and Temperature Sensor
+device	em3027rtc: sysmon_envsys
+attach	em3027rtc at iic
+file	dev/i2c/em3027.c			em3027rtc
+
 # HID over i2c
 # HID "bus"
 define  ihidbus {[ reportid = -1 ]}

Added files:

Index: src/sys/dev/i2c/em3027.c
diff -u /dev/null src/sys/dev/i2c/em3027.c:1.1
--- /dev/null	Fri Jan  5 03:07:16 2018
+++ src/sys/dev/i2c/em3027.c	Fri Jan  5 03:07:15 2018
@@ -0,0 +1,480 @@
+/*	$NetBSD: em3027.c,v 1.1 2018/01/05 03:07:15 uwe Exp $ */
+/*
+ * Copyright (c) 2018 Valery Ushakov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * EM Microelectronic EM3027 RTC
+ */
+#include 
+__KERNEL_RCSID(0, "$NetBSD: em3027.c,v 1.1 2018/01/05 03:07:15 uwe Exp $");
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+
+#if 0
+#define aprint_verbose_dev	aprint_normal_dev
+#define aprint_debug_dev	aprint_normal_dev
+#endif
+
+
+struct em3027rtc_softc {
+	device_t sc_dev;
+
+	i2c_tag_t sc_tag;
+	i2c_addr_t sc_addr;
+
+	bool sc_vlow;
+
+	struct todr_chip_handle sc_todr;
+
+	struct sysmon_envsys *sc_sme;
+	envsys_data_t sc_sensor;
+};
+
+
+#define EM3027_CONTROL_BASE	EM3027_ONOFF
+#define EM3027_WATCH_BASE	EM3027_WATCH_SEC
+
+struct em3027rtc_watch {
+	uint8_t sec;
+	uint8_t min;
+	uint8_t hour;
+	uint8_t day;
+	uint8_t wday;
+	uint8_t mon;
+	uint8_t year;
+};
+
+#define EM3027_WATCH_SIZE	(EM3027_WATCH_YEAR - EM3027_WATCH_BASE + 1)
+__CTASSERT(sizeof(struct em3027rtc_watch) == EM3027_WATCH_SIZE);
+
+#define EM3027_BASE_YEAR	1980
+
+
+static int em3027rtc_match(device_t, cfdata_t, void *);
+static void em3027rtc_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(em3027rtc, sizeof(struct em3027rtc_softc),
+em3027rtc_match, em3027rtc_attach, NULL, NULL);
+
+
+static bool em3027rtc_enable_thermometer(struct em3027rtc_softc *);
+static void em3027rtc_envsys_attach(struct em3027rtc_softc *);
+
+static int em3027rtc_gettime(struct todr_chip_handle *, struct clock_ymdhms *);
+static int em3027rtc_settime(struct todr_chip_handle *, struct clock_ymdhms *);
+
+static void em3027rtc_sme_refresh(struct sysmon_envsys *, envsys_data_t *);
+
+static int em3027rtc_iic_exec(struct em3027rtc_softc *, i2c_op_t, uint8_t,
+			  void *, size_t);
+
+static int em3027rtc_read(struct em3027rtc_softc *, uint8_t, void *, size_t);
+static int em3027rtc_write(struct em3027rtc_softc *, uint8_t, void *, size_t);
+
+static int em3027rtc_read_byte(struct em3027rtc_softc *, uint8_t, uint8_t *);
+static int em3027rtc_write_byte(struct em3027rtc_softc *, uint8_t, uint8_t);
+
+
+
+static int
+em3027rtc_match(device_t parent, cfdata_t cf, void *aux)
+{
+	const struct 

CVS commit: src/sys/net

2018-01-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan  5 01:53:15 UTC 2018

Modified Files:
src/sys/net: route.c

Log Message:
Don't stomp past the end of the array! need __arraycount not sizeof()
Found by chuq, while debugging the sdf.org crashes
XXX: pullup-8
Restructure a bit for readability.


To generate a diff of this commit:
cvs rdiff -u -r1.201 -r1.202 src/sys/net/route.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.201 src/sys/net/route.c:1.202
--- src/sys/net/route.c:1.201	Mon Sep 25 00:15:33 2017
+++ src/sys/net/route.c	Thu Jan  4 20:53:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.201 2017/09/25 04:15:33 ozaki-r Exp $	*/
+/*	$NetBSD: route.c,v 1.202 2018/01/05 01:53:15 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.201 2017/09/25 04:15:33 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.202 2018/01/05 01:53:15 christos Exp $");
 
 #include 
 #ifdef RTFLUSH_DEBUG
@@ -686,15 +686,13 @@ _rt_free(struct rtentry *rt)
 static void
 rt_free_work(struct work *wk, void *arg)
 {
-	int i;
-	struct rtentry *rt;
 
 restart:
 	mutex_enter(_free_global.lock);
-	for (i = 0; i < sizeof(rt_free_global.queue); i++) {
+	for (size_t i = 0; i < __arraycount(rt_free_global.queue); i++) {
 		if (rt_free_global.queue[i] == NULL)
 			continue;
-		rt = rt_free_global.queue[i];
+		struct rtentry *rt = rt_free_global.queue[i];
 		rt_free_global.queue[i] = NULL;
 		mutex_exit(_free_global.lock);
 
@@ -710,23 +708,24 @@ rt_free(struct rtentry *rt)
 {
 
 	KASSERT(rt->rt_refcnt > 0);
-	if (!rt_wait_ok()) {
-		int i;
-		mutex_enter(_free_global.lock);
-		for (i = 0; i < sizeof(rt_free_global.queue); i++) {
-			if (rt_free_global.queue[i] == NULL) {
-rt_free_global.queue[i] = rt;
-break;
-			}
-		}
-		KASSERT(i < sizeof(rt_free_global.queue));
-		rt_ref(rt);
-		mutex_exit(_free_global.lock);
-		workqueue_enqueue(rt_free_global.wq, _free_global.wk, NULL);
-	} else {
+	if (rt_wait_ok()) {
 		atomic_dec_uint(>rt_refcnt);
 		_rt_free(rt);
+		return;
 	}
+
+	size_t i;
+	mutex_enter(_free_global.lock);
+	for (i = 0; i < __arraycount(rt_free_global.queue); i++) {
+		if (rt_free_global.queue[i] == NULL)
+			break;
+	}
+
+	KASSERT(i < __arraycount(rt_free_global.queue));
+	rt_free_global.queue[i] = rt;
+	rt_ref(rt);
+	mutex_exit(_free_global.lock);
+	workqueue_enqueue(rt_free_global.wq, _free_global.wk, NULL);
 }
 
 #ifdef NET_MPSAFE



CVS commit: src/sys/kern

2018-01-04 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan  5 01:51:36 UTC 2018

Modified Files:
src/sys/kern: kern_exec.c

Log Message:
don't print for ENOEXEC


To generate a diff of this commit:
cvs rdiff -u -r1.453 -r1.454 src/sys/kern/kern_exec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.453 src/sys/kern/kern_exec.c:1.454
--- src/sys/kern/kern_exec.c:1.453	Mon Nov 13 17:01:45 2017
+++ src/sys/kern/kern_exec.c	Thu Jan  4 20:51:36 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.453 2017/11/13 22:01:45 christos Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.454 2018/01/05 01:51:36 christos Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.453 2017/11/13 22:01:45 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.454 2018/01/05 01:51:36 christos Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -760,7 +760,7 @@ execve_loadvm(struct lwp *l, const char 
 
 	/* see if we can run it. */
 	if ((error = check_exec(l, epp, data->ed_pathbuf)) != 0) {
-		if (error != ENOENT && error != EACCES) {
+		if (error != ENOENT && error != EACCES && error != ENOEXEC) {
 			DPRINTF(("%s: check exec failed for %s, error %d\n",
 			__func__, epp->ep_kname, error));
 		}



CVS commit: src/distrib/amd64/uefi-installimage

2018-01-04 Thread Paul Goyette
Module Name:src
Committed By:   pgoyette
Date:   Fri Jan  5 01:33:11 UTC 2018

Modified Files:
src/distrib/amd64/uefi-installimage: Makefile

Log Message:
Bump size of uefi image - we've outgrown the old size


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/distrib/amd64/uefi-installimage/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/amd64/uefi-installimage/Makefile
diff -u src/distrib/amd64/uefi-installimage/Makefile:1.3 src/distrib/amd64/uefi-installimage/Makefile:1.4
--- src/distrib/amd64/uefi-installimage/Makefile:1.3	Mon Sep 18 14:42:16 2017
+++ src/distrib/amd64/uefi-installimage/Makefile	Fri Jan  5 01:33:11 2018
@@ -1,11 +1,11 @@
-#	$NetBSD: Makefile,v 1.3 2017/09/18 14:42:16 joerg Exp $
+#	$NetBSD: Makefile,v 1.4 2018/01/05 01:33:11 pgoyette Exp $
 
 .include 
 
 INSTIMGBASE=	NetBSD-${DISTRIBVER}-amd64-uefi-install	# gives ${IMGBASE}.img
 
 BOOTDISK=	dk1			# unused (use GUID)
-INSTIMAGEMB?=	1450			# for all installation binaries
+INSTIMAGEMB?=	1500			# for all installation binaries
 
 PRIMARY_BOOT=		bootxx_ffsv1
 SECONDARY_BOOT=		boot



CVS commit: src

2018-01-04 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Thu Jan  4 20:57:29 UTC 2018

Modified Files:
src/common/lib/libc/sys: cpuset.c
src/lib/libc/citrus: citrus_module.c
src/lib/libc/compat-43: killpg.c
src/lib/libc/db/db: dbfile.c
src/lib/libc/gen: posix_spawnp.c signalnumber.c
src/lib/libc/locale: generic_lc_all.c setlocale.c
src/lib/libc/stdlib: reallocarray.c strtonum.c
src/lib/libc/sys: sched.c
src/lib/libc/time: getdate.c

Log Message:
Add bunch of missing includes of namespace.h in libc

The NetBSD Standard C Library uses internally some of its functions with
a mangled symbol name, usually "_symbol". The internal functions shall not
use the global (public) symbols.

This change eliminates usage of the global changes of the following symbols:
 - strlcat -> _strlcat
 - sysconf -> __sysconf
 - closedir -> _closedir
 - fparseln -> _fparseln
 - kill -> _kill
 - mkstemp -> _mkstemp
 - reallocarr -> _reallocarr
 - strcasecmp -> _strcasecmp
 - strncasecmp -> _strncasecmp
 - strptime -> _strptime
 - strtok_r -> _strtok_r
 - sysctl -> _sysctl
 - dlopen -> __dlopen
 - dlclose -> __dlclose
 - dlsym -> __dlsym

Sponsored by 


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/common/lib/libc/sys/cpuset.c
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/citrus/citrus_module.c
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/compat-43/killpg.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/db/db/dbfile.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/gen/posix_spawnp.c
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/gen/signalnumber.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/locale/generic_lc_all.c
cvs rdiff -u -r1.64 -r1.65 src/lib/libc/locale/setlocale.c
cvs rdiff -u -r1.9 -r1.10 src/lib/libc/stdlib/reallocarray.c
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/stdlib/strtonum.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/sys/sched.c
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/time/getdate.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/common/lib/libc/sys/cpuset.c
diff -u src/common/lib/libc/sys/cpuset.c:1.18 src/common/lib/libc/sys/cpuset.c:1.19
--- src/common/lib/libc/sys/cpuset.c:1.18	Fri Mar  9 15:41:16 2012
+++ src/common/lib/libc/sys/cpuset.c	Thu Jan  4 20:57:28 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpuset.c,v 1.18 2012/03/09 15:41:16 christos Exp $	*/
+/*	$NetBSD: cpuset.c,v 1.19 2018/01/04 20:57:28 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,9 +32,13 @@
 #ifndef _STANDALONE
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: cpuset.c,v 1.18 2012/03/09 15:41:16 christos Exp $");
+__RCSID("$NetBSD: cpuset.c,v 1.19 2018/01/04 20:57:28 kamil Exp $");
 #endif /* LIBC_SCCS and not lint */
 
+#ifdef _LIBC
+#include "namespace.h"
+#endif
+
 #include 
 #include 
 #ifdef _KERNEL

Index: src/lib/libc/citrus/citrus_module.c
diff -u src/lib/libc/citrus/citrus_module.c:1.12 src/lib/libc/citrus/citrus_module.c:1.13
--- src/lib/libc/citrus/citrus_module.c:1.12	Fri Aug 28 11:45:02 2015
+++ src/lib/libc/citrus/citrus_module.c	Thu Jan  4 20:57:28 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: citrus_module.c,v 1.12 2015/08/28 11:45:02 joerg Exp $	*/
+/*	$NetBSD: citrus_module.c,v 1.13 2018/01/04 20:57:28 kamil Exp $	*/
 
 /*-
  * Copyright (c)1999, 2000, 2001, 2002 Citrus Project,
@@ -89,9 +89,11 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: citrus_module.c,v 1.12 2015/08/28 11:45:02 joerg Exp $");
+__RCSID("$NetBSD: citrus_module.c,v 1.13 2018/01/04 20:57:28 kamil Exp $");
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
+
 #include 
 #include 
 #include 

Index: src/lib/libc/compat-43/killpg.c
diff -u src/lib/libc/compat-43/killpg.c:1.8 src/lib/libc/compat-43/killpg.c:1.9
--- src/lib/libc/compat-43/killpg.c:1.8	Thu Aug  7 16:42:39 2003
+++ src/lib/libc/compat-43/killpg.c	Thu Jan  4 20:57:28 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: killpg.c,v 1.8 2003/08/07 16:42:39 agc Exp $	*/
+/*	$NetBSD: killpg.c,v 1.9 2018/01/04 20:57:28 kamil Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -34,10 +34,12 @@
 #if 0
 static char sccsid[] = "@(#)killpg.c	8.1 (Berkeley) 6/2/93";
 #else
-__RCSID("$NetBSD: killpg.c,v 1.8 2003/08/07 16:42:39 agc Exp $");
+__RCSID("$NetBSD: killpg.c,v 1.9 2018/01/04 20:57:28 kamil Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
+#include "namespace.h"
+
 #include 
 #include 
 #include 

Index: src/lib/libc/db/db/dbfile.c
diff -u src/lib/libc/db/db/dbfile.c:1.1 src/lib/libc/db/db/dbfile.c:1.2
--- src/lib/libc/db/db/dbfile.c:1.1	Sun Dec  1 00:22:48 2013
+++ src/lib/libc/db/db/dbfile.c	Thu Jan  4 20:57:29 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dbfile.c,v 1.1 2013/12/01 00:22:48 christos Exp $	*/
+/*	$NetBSD: dbfile.c,v 1.2 2018/01/04 20:57:29 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -31,7 +31,9 @@
 #endif
 
 #include 
-__RCSID("$NetBSD: dbfile.c,v 1.1 2013/12/01 00:22:48 christos Exp 

CVS commit: src/sys/arch

2018-01-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan  4 20:38:31 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: gdt.c
src/sys/arch/i386/i386: gdt.c

Log Message:
Declare gdt_size as const, simplifies.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/amd64/amd64/gdt.c
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/i386/i386/gdt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/gdt.c
diff -u src/sys/arch/amd64/amd64/gdt.c:1.43 src/sys/arch/amd64/amd64/gdt.c:1.44
--- src/sys/arch/amd64/amd64/gdt.c:1.43	Sun Sep 10 10:51:13 2017
+++ src/sys/arch/amd64/amd64/gdt.c	Thu Jan  4 20:38:30 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.43 2017/09/10 10:51:13 maxv Exp $	*/
+/*	$NetBSD: gdt.c,v 1.44 2018/01/04 20:38:30 maxv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.43 2017/09/10 10:51:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.44 2018/01/04 20:38:30 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -66,8 +66,15 @@ typedef struct {
 	size_t nslots;
 } gdt_bitmap_t;
 
-size_t gdt_size;			/* size of GDT in bytes */
-static gdt_bitmap_t gdt_bitmap;		/* bitmap of busy slots */
+/* size of GDT in bytes */
+#ifdef XEN
+const size_t gdt_size = FIRST_RESERVED_GDT_BYTE;
+#else
+const size_t gdt_size = MAXGDTSIZ;
+#endif
+
+/* bitmap of busy slots */
+static gdt_bitmap_t gdt_bitmap;
 
 #if defined(USER_LDT) || !defined(XEN)
 static void set_sys_gdt(int, void *, size_t, int, int, int);
@@ -130,11 +137,6 @@ gdt_init(void)
 	struct cpu_info *ci = _info_primary;
 
 	/* Initialize the global values */
-#ifdef XEN
-	gdt_size = FIRST_RESERVED_GDT_BYTE;
-#else
-	gdt_size = MAXGDTSIZ;
-#endif
 	memset(_bitmap.busy, 0, sizeof(gdt_bitmap.busy));
 	gdt_bitmap.nslots = NSLOTS(gdt_size);
 

Index: src/sys/arch/i386/i386/gdt.c
diff -u src/sys/arch/i386/i386/gdt.c:1.67 src/sys/arch/i386/i386/gdt.c:1.68
--- src/sys/arch/i386/i386/gdt.c:1.67	Wed Sep  6 12:39:18 2017
+++ src/sys/arch/i386/i386/gdt.c	Thu Jan  4 20:38:31 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: gdt.c,v 1.67 2017/09/06 12:39:18 bouyer Exp $	*/
+/*	$NetBSD: gdt.c,v 1.68 2018/01/04 20:38:31 maxv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.67 2017/09/06 12:39:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.68 2018/01/04 20:38:31 maxv Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -54,8 +54,15 @@ typedef struct {
 	size_t nslots;
 } gdt_bitmap_t;
 
-size_t gdt_size;			/* size of GDT in bytes */
-static gdt_bitmap_t gdt_bitmap;		/* bitmap of busy slots */
+/* size of GDT in bytes */
+#ifdef XEN
+const size_t gdt_size = FIRST_RESERVED_GDT_BYTE;
+#else
+const size_t gdt_size = MAXGDTSIZ;
+#endif
+
+/* bitmap of busy slots */
+static gdt_bitmap_t gdt_bitmap;
 
 #ifndef XEN
 static int ldt_count;	/* number of LDTs */
@@ -119,11 +126,6 @@ gdt_init(void)
 	struct cpu_info *ci = _info_primary;
 
 	/* Initialize the global values */
-#ifdef XEN
-	gdt_size = FIRST_RESERVED_GDT_BYTE;
-#else
-	gdt_size = MAXGDTSIZ;
-#endif
 	memset(_bitmap.busy, 0, sizeof(gdt_bitmap.busy));
 	gdt_bitmap.nslots = NSLOTS(gdt_size);
 



CVS commit: src/sys/arch

2018-01-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan  4 14:02:24 UTC 2018

Modified Files:
src/sys/arch/amd64/include: tss.h
src/sys/arch/i386/i386: genassym.cf locore.S
src/sys/arch/i386/include: tss.h
src/sys/arch/x86/x86: sys_machdep.c

Log Message:
Declare IOMAP_VALIDOFF, not to use ci_tss pointers.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/amd64/include/tss.h
cvs rdiff -u -r1.106 -r1.107 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.155 -r1.156 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/i386/include/tss.h
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/x86/x86/sys_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/include/tss.h
diff -u src/sys/arch/amd64/include/tss.h:1.6 src/sys/arch/amd64/include/tss.h:1.7
--- src/sys/arch/amd64/include/tss.h:1.6	Wed Jul 12 17:52:18 2017
+++ src/sys/arch/amd64/include/tss.h	Thu Jan  4 14:02:23 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tss.h,v 1.6 2017/07/12 17:52:18 maxv Exp $	*/
+/*	$NetBSD: tss.h,v 1.7 2018/01/04 14:02:23 maxv Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -65,6 +65,11 @@ struct x86_64_tss {
  */
 #define	IOMAP_INVALOFF	0x
 
+/*
+ * If we have an I/O bitmap, there is only one valid offset.
+ */
+#define	IOMAP_VALIDOFF	sizeof(struct x86_64_tss)
+
 #else	/*	__x86_64__	*/
 
 #include 

Index: src/sys/arch/i386/i386/genassym.cf
diff -u src/sys/arch/i386/i386/genassym.cf:1.106 src/sys/arch/i386/i386/genassym.cf:1.107
--- src/sys/arch/i386/i386/genassym.cf:1.106	Thu Jan  4 13:36:30 2018
+++ src/sys/arch/i386/i386/genassym.cf	Thu Jan  4 14:02:23 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.106 2018/01/04 13:36:30 maxv Exp $
+#	$NetBSD: genassym.cf,v 1.107 2018/01/04 14:02:23 maxv Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -256,6 +256,7 @@ define	CPU_INFO_IDLELWP	offsetof(struct 
 define	CPU_INFO_PMAP		offsetof(struct cpu_info, ci_pmap)
 define	CPU_INFO_TSS		offsetof(struct cpu_info, ci_tss)
 define	IOMAP_INVALOFF		IOMAP_INVALOFF
+define	IOMAP_VALIDOFF		IOMAP_VALIDOFF
 define	CPU_INFO_NSYSCALL	offsetof(struct cpu_info, ci_data.cpu_nsyscall)
 define	CPU_INFO_NTRAP		offsetof(struct cpu_info, ci_data.cpu_ntrap)
 define	CPU_INFO_NINTR		offsetof(struct cpu_info, ci_data.cpu_nintr)

Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.155 src/sys/arch/i386/i386/locore.S:1.156
--- src/sys/arch/i386/i386/locore.S:1.155	Thu Jan  4 13:36:30 2018
+++ src/sys/arch/i386/i386/locore.S	Thu Jan  4 14:02:23 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.155 2018/01/04 13:36:30 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.156 2018/01/04 14:02:23 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.155 2018/01/04 13:36:30 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.156 2018/01/04 14:02:23 maxv Exp $");
 
 #include "opt_copy_symtab.h"
 #include "opt_ddb.h"
@@ -1209,7 +1209,7 @@ switch_return:
 	popl	%edi
 	popl	%esi
 	movl	CPUVAR(TSS),%eax
-	movl	$((TSS_IOMAP - TSS_TSS) << 16),TSS_IOBASE(%eax)
+	movl	$(IOMAP_VALIDOFF << 16),TSS_IOBASE(%eax)
 	jmp	.Liobitmap_done
 END(cpu_switchto)
 

Index: src/sys/arch/i386/include/tss.h
diff -u src/sys/arch/i386/include/tss.h:1.10 src/sys/arch/i386/include/tss.h:1.11
--- src/sys/arch/i386/include/tss.h:1.10	Sat Jan  5 21:45:00 2008
+++ src/sys/arch/i386/include/tss.h	Thu Jan  4 14:02:23 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: tss.h,v 1.10 2008/01/05 21:45:00 yamt Exp $	*/
+/*	$NetBSD: tss.h,v 1.11 2018/01/04 14:02:23 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -76,4 +76,9 @@ struct i386tss {
  */
 #define	IOMAP_INVALOFF	0x
 
+/*
+ * If we have an I/O bitmap, there is only one valid offset.
+ */
+#define	IOMAP_VALIDOFF	sizeof(struct i386tss)
+
 #endif /* #ifndef _I386_TSS_H_ */

Index: src/sys/arch/x86/x86/sys_machdep.c
diff -u src/sys/arch/x86/x86/sys_machdep.c:1.45 src/sys/arch/x86/x86/sys_machdep.c:1.46
--- src/sys/arch/x86/x86/sys_machdep.c:1.45	Thu Jan  4 13:36:30 2018
+++ src/sys/arch/x86/x86/sys_machdep.c	Thu Jan  4 14:02:23 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_machdep.c,v 1.45 2018/01/04 13:36:30 maxv Exp $	*/
+/*	$NetBSD: sys_machdep.c,v 1.46 2018/01/04 14:02:23 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2009, 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.45 2018/01/04 13:36:30 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.46 2018/01/04 14:02:23 maxv Exp $");
 
 #include "opt_mtrr.h"
 #include "opt_pmc.h"
@@ -480,11 +480,13 @@ x86_set_ioperm(struct lwp *l, void *args
 		kmem_free(old, IOMAPSIZE);
 	}
 
+	CTASSERT(offsetof(struct cpu_tss, iomap) -
+	offsetof(struct cpu_tss, tss) == IOMAP_VALIDOFF);
+
 	kpreempt_disable();

CVS commit: src/sys/arch

2018-01-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan  4 13:36:30 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: genassym.cf locore.S machdep.c
src/sys/arch/i386/i386: genassym.cf locore.S machdep.c
src/sys/arch/x86/include: cpu.h
src/sys/arch/x86/x86: intr.c pmap.c sys_machdep.c

Log Message:
Allocate the TSS area dynamically. This way cpu_info and cpu_tss can be
put in separate pages.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.143 -r1.144 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.282 -r1.283 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.105 -r1.106 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.154 -r1.155 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.801 -r1.802 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.85 -r1.86 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.274 -r1.275 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/x86/x86/sys_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/genassym.cf
diff -u src/sys/arch/amd64/amd64/genassym.cf:1.63 src/sys/arch/amd64/amd64/genassym.cf:1.64
--- src/sys/arch/amd64/amd64/genassym.cf:1.63	Thu Jan  4 12:34:15 2018
+++ src/sys/arch/amd64/amd64/genassym.cf	Thu Jan  4 13:36:30 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.63 2018/01/04 12:34:15 maxv Exp $
+#	$NetBSD: genassym.cf,v 1.64 2018/01/04 13:36:30 maxv Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -223,6 +223,8 @@ define	TF_REGSIZE		offsetof(struct trapf
 # Total size includes registers pushed by hardware
 define	FRAMESIZE		sizeof(struct trapframe)
 
+define	TSS_RSP0		offsetof(struct cpu_tss, tss.tss_rsp0)
+
 define	CPU_INFO_SCRATCH	offsetof(struct cpu_info, ci_scratch)
 define	CPU_INFO_SELF		offsetof(struct cpu_info, ci_self)
 define	CPU_INFO_RESCHED	offsetof(struct cpu_info, ci_want_resched)
@@ -233,7 +235,7 @@ define	CPU_INFO_CURLWP		offsetof(struct 
 define	CPU_INFO_CURLDT		offsetof(struct cpu_info, ci_curldt)
 define	CPU_INFO_IDLELWP	offsetof(struct cpu_info, ci_data.cpu_idlelwp)
 define	CPU_INFO_PMAP		offsetof(struct cpu_info, ci_pmap)
-define	CPU_INFO_RSP0		offsetof(struct cpu_info, ci_tss.tss.tss_rsp0)
+define	CPU_INFO_TSS		offsetof(struct cpu_info, ci_tss)
 define	CPU_INFO_NSYSCALL	offsetof(struct cpu_info, ci_data.cpu_nsyscall)
 define	CPU_INFO_NTRAP		offsetof(struct cpu_info, ci_data.cpu_ntrap)
 define	CPU_INFO_NINTR		offsetof(struct cpu_info, ci_data.cpu_nintr)

Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.143 src/sys/arch/amd64/amd64/locore.S:1.144
--- src/sys/arch/amd64/amd64/locore.S:1.143	Sun Nov 26 15:00:16 2017
+++ src/sys/arch/amd64/amd64/locore.S	Thu Jan  4 13:36:30 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.143 2017/11/26 15:00:16 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.144 2018/01/04 13:36:30 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1107,7 +1107,8 @@ ENTRY(cpu_switchto)
 	/* Switch ring0 stack */
 #ifndef XEN
 	movq	PCB_RSP0(%r14),%rax
-	movq	%rax,CPUVAR(RSP0)
+	movq	CPUVAR(TSS),%rdi
+	movq	%rax,TSS_RSP0(%rdi)
 #else
 	movq	%r14,%rdi
 	callq	_C_LABEL(x86_64_switch_context);

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.282 src/sys/arch/amd64/amd64/machdep.c:1.283
--- src/sys/arch/amd64/amd64/machdep.c:1.282	Thu Jan  4 12:34:15 2018
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Jan  4 13:36:30 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.282 2018/01/04 12:34:15 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.283 2018/01/04 13:36:30 maxv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.282 2018/01/04 12:34:15 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.283 2018/01/04 13:36:30 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -502,21 +502,25 @@ x86_64_proc0_pcb_ldt_init(void)
 void
 cpu_init_tss(struct cpu_info *ci)
 {
-	struct x86_64_tss *tss = >ci_tss.tss;
+	struct cpu_tss *cputss;
 	uintptr_t p;
 
-	tss->tss_iobase = IOMAP_INVALOFF << 16;
-	/* tss->tss_ist[0] is filled by cpu_intr_init */
+	cputss = (struct cpu_tss *)uvm_km_alloc(kernel_map,
+	sizeof(struct cpu_tss), 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
+
+	cputss->tss.tss_iobase = IOMAP_INVALOFF << 16;
+	/* cputss->tss.tss_ist[0] is filled by cpu_intr_init */
 
 	/* double fault */
 	p = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED);
-	tss->tss_ist[1] = p + PAGE_SIZE - 16;
+	cputss->tss.tss_ist[1] = p + PAGE_SIZE - 16;
 
 	/* NMI */
 	p = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED);
-	tss->tss_ist[2] = p + PAGE_SIZE - 16;
+	cputss->tss.tss_ist[2] = p + PAGE_SIZE - 16;
 
-	ci->ci_tss_sel = tss_alloc(tss);
+	ci->ci_tss = cputss;
+	

CVS commit: src/sys/arch

2018-01-04 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Thu Jan  4 12:34:15 UTC 2018

Modified Files:
src/sys/arch/amd64/amd64: genassym.cf machdep.c
src/sys/arch/i386/i386: genassym.cf machdep.c
src/sys/arch/x86/include: cpu.h
src/sys/arch/x86/x86: intr.c pmap.c sys_machdep.c

Log Message:
Group the different TSSes into a cpu_tss structure. And pack this
structure to make sure there is no padding between 'tss' and 'iomap'.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.281 -r1.282 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.104 -r1.105 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.800 -r1.801 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.114 -r1.115 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.273 -r1.274 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/x86/x86/sys_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/genassym.cf
diff -u src/sys/arch/amd64/amd64/genassym.cf:1.62 src/sys/arch/amd64/amd64/genassym.cf:1.63
--- src/sys/arch/amd64/amd64/genassym.cf:1.62	Sat Oct 28 20:57:17 2017
+++ src/sys/arch/amd64/amd64/genassym.cf	Thu Jan  4 12:34:15 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.62 2017/10/28 20:57:17 bouyer Exp $
+#	$NetBSD: genassym.cf,v 1.63 2018/01/04 12:34:15 maxv Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -233,7 +233,7 @@ define	CPU_INFO_CURLWP		offsetof(struct 
 define	CPU_INFO_CURLDT		offsetof(struct cpu_info, ci_curldt)
 define	CPU_INFO_IDLELWP	offsetof(struct cpu_info, ci_data.cpu_idlelwp)
 define	CPU_INFO_PMAP		offsetof(struct cpu_info, ci_pmap)
-define	CPU_INFO_RSP0		offsetof(struct cpu_info, ci_tss.tss_rsp0)
+define	CPU_INFO_RSP0		offsetof(struct cpu_info, ci_tss.tss.tss_rsp0)
 define	CPU_INFO_NSYSCALL	offsetof(struct cpu_info, ci_data.cpu_nsyscall)
 define	CPU_INFO_NTRAP		offsetof(struct cpu_info, ci_data.cpu_ntrap)
 define	CPU_INFO_NINTR		offsetof(struct cpu_info, ci_data.cpu_nintr)

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.281 src/sys/arch/amd64/amd64/machdep.c:1.282
--- src/sys/arch/amd64/amd64/machdep.c:1.281	Tue Jan  2 18:54:26 2018
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Jan  4 12:34:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.281 2018/01/02 18:54:26 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.282 2018/01/04 12:34:15 maxv Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.281 2018/01/02 18:54:26 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.282 2018/01/04 12:34:15 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -502,7 +502,7 @@ x86_64_proc0_pcb_ldt_init(void)
 void
 cpu_init_tss(struct cpu_info *ci)
 {
-	struct x86_64_tss *tss = >ci_tss;
+	struct x86_64_tss *tss = >ci_tss.tss;
 	uintptr_t p;
 
 	tss->tss_iobase = IOMAP_INVALOFF << 16;

Index: src/sys/arch/i386/i386/genassym.cf
diff -u src/sys/arch/i386/i386/genassym.cf:1.104 src/sys/arch/i386/i386/genassym.cf:1.105
--- src/sys/arch/i386/i386/genassym.cf:1.104	Sun Sep 17 09:04:51 2017
+++ src/sys/arch/i386/i386/genassym.cf	Thu Jan  4 12:34:15 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.104 2017/09/17 09:04:51 maxv Exp $
+#	$NetBSD: genassym.cf,v 1.105 2018/01/04 12:34:15 maxv Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -249,11 +249,11 @@ define	CPU_INFO_FPCURLWP	offsetof(struct
 define	CPU_INFO_CURLDT		offsetof(struct cpu_info, ci_curldt)
 define	CPU_INFO_IDLELWP	offsetof(struct cpu_info, ci_data.cpu_idlelwp)
 define	CPU_INFO_PMAP		offsetof(struct cpu_info, ci_pmap)
-define	CPU_INFO_TSS		offsetof(struct cpu_info, ci_tss)
+define	CPU_INFO_TSS		offsetof(struct cpu_info, ci_tss.tss)
 define	CPU_INFO_TSS_SEL	offsetof(struct cpu_info, ci_tss_sel)
-define	CPU_INFO_ESP0		offsetof(struct cpu_info, ci_tss.tss_esp0)
-define	CPU_INFO_IOBASE		offsetof(struct cpu_info, ci_tss.tss_iobase)
-define	CPU_INFO_IOMAP		offsetof(struct cpu_info, ci_iomap)
+define	CPU_INFO_ESP0		offsetof(struct cpu_info, ci_tss.tss.tss_esp0)
+define	CPU_INFO_IOBASE		offsetof(struct cpu_info, ci_tss.tss.tss_iobase)
+define	CPU_INFO_IOMAP		offsetof(struct cpu_info, ci_tss.iomap)
 define	IOMAP_INVALOFF		IOMAP_INVALOFF
 define	CPU_INFO_NSYSCALL	offsetof(struct cpu_info, ci_data.cpu_nsyscall)
 define	CPU_INFO_NTRAP		offsetof(struct cpu_info, ci_data.cpu_ntrap)

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.800 src/sys/arch/i386/i386/machdep.c:1.801
--- src/sys/arch/i386/i386/machdep.c:1.800	Sun Dec 31 08:29:38 2017
+++ src/sys/arch/i386/i386/machdep.c	Thu Jan  4 12:34:15 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.800 2017/12/31 08:29:38 maxv Exp $	*/
+/*	

CVS commit: src/sys/dev/pci

2018-01-04 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Jan  4 09:43:28 UTC 2018

Modified Files:
src/sys/dev/pci: if_wm.c

Log Message:
 Add ASPM workaround for 8257[1234] and 82583 to prevent device timeout or
hangup. Fixes PR#52818 reported by Shinichi Doyashiki.


To generate a diff of this commit:
cvs rdiff -u -r1.551 -r1.552 src/sys/dev/pci/if_wm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.551 src/sys/dev/pci/if_wm.c:1.552
--- src/sys/dev/pci/if_wm.c:1.551	Mon Jan  1 08:33:28 2018
+++ src/sys/dev/pci/if_wm.c	Thu Jan  4 09:43:27 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.551 2018/01/01 08:33:28 jnemeth Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.552 2018/01/04 09:43:27 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.551 2018/01/01 08:33:28 jnemeth Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.552 2018/01/04 09:43:27 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -921,6 +921,7 @@ static void	wm_ulp_disable(struct wm_sof
 static void	wm_enable_phy_wakeup(struct wm_softc *);
 static void	wm_igp3_phy_powerdown_workaround_ich8lan(struct wm_softc *);
 static void	wm_enable_wakeup(struct wm_softc *);
+static void	wm_disable_aspm(struct wm_softc *);
 /* LPLU (Low Power Link Up) */
 static void	wm_lplu_d0_disable(struct wm_softc *);
 /* EEE */
@@ -2048,6 +2049,9 @@ alloc_retry:
 		(sc->sc_flags & WM_F_PCIX) ? "PCIX" : "PCI");
 	}
 
+	/* Disable ASPM L0s and/or L1 for workaround */
+	wm_disable_aspm(sc);
+
 	/* clear interesting stat counters */
 	CSR_READ(sc, WMREG_COLC);
 	CSR_READ(sc, WMREG_RXERRC);
@@ -2911,6 +2915,8 @@ wm_resume(device_t self, const pmf_qual_
 {
 	struct wm_softc *sc = device_private(self);
 
+	/* Disable ASPM L0s and/or L1 for workaround */
+	wm_disable_aspm(sc);
 	wm_init_manageability(sc);
 
 	return true;
@@ -13806,6 +13812,66 @@ wm_enable_wakeup(struct wm_softc *sc)
 	pci_conf_write(sc->sc_pc, sc->sc_pcitag, pmreg + PCI_PMCSR, pmode);
 }
 
+/* Disable ASPM L0s and/or L1 for workaround */
+static void
+wm_disable_aspm(struct wm_softc *sc)
+{
+	pcireg_t reg, mask = 0;
+	unsigned const char *str = "";
+
+	/*
+	 *  Only for PCIe device which has PCIe capability in the PCI config
+	 * space.
+	 */
+	if (((sc->sc_flags & WM_F_PCIE) == 0) || (sc->sc_pcixe_capoff == 0))
+		return;
+
+	switch (sc->sc_type) {
+	case WM_T_82571:
+	case WM_T_82572:
+		/*
+		 * 8257[12] Errata 13: Device Does Not Support PCIe Active
+		 * State Power management L1 State (ASPM L1).
+		 */
+		mask = PCIE_LCSR_ASPM_L1;
+		str = "L1 is";
+		break;
+	case WM_T_82573:
+	case WM_T_82574:
+	case WM_T_82583:
+		/*
+		 * The 82573 disappears when PCIe ASPM L0s is enabled.
+		 *
+		 * The 82574 and 82583 does not support PCIe ASPM L0s with
+		 * some chipset.  The document of 82574 and 82583 says that
+		 * disabling L0s with some specific chipset is sufficient,
+		 * but we follow as of the Intel em driver does.
+		 *
+		 * References:
+		 * Errata 8 of the Specification Update of i82573.
+		 * Errata 20 of the Specification Update of i82574.
+		 * Errata 9 of the Specification Update of i82583.
+		 */
+		mask = PCIE_LCSR_ASPM_L1 | PCIE_LCSR_ASPM_L0S;
+		str = "L0s and L1 are";
+		break;
+	default:
+		return;
+	}
+
+	reg = pci_conf_read(sc->sc_pc, sc->sc_pcitag,
+	sc->sc_pcixe_capoff + PCIE_LCSR);
+	reg &= ~mask;
+	pci_conf_write(sc->sc_pc, sc->sc_pcitag,
+	sc->sc_pcixe_capoff + PCIE_LCSR, reg);
+
+	/* Print only in wm_attach() */
+	if ((sc->sc_flags & WM_F_ATTACHED) == 0)
+		aprint_verbose_dev(sc->sc_dev,
+		"ASPM %s disabled to workaround the errata.\n",
+			str);
+}
+
 /* LPLU */
 
 static void