CVS commit: src/sys/arch/powerpc/oea

2021-07-19 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Mon Jul 19 14:49:45 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: pmap.c

Log Message:
there is no need to keep pvos for unmanaged mappings on a hidden p/v list,
since "unmanaged" means that we don't want to find such pvos on any p/v list.
instead, just don't put such pvos on any p/v list at all and remove
the two hidden p/v lists for unmanaged mappings.  code mostly from martin,
to implement rin's suggestion of unifying the two hidden lists.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/arch/powerpc/oea/pmap.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/powerpc/oea/pmap.c
diff -u src/sys/arch/powerpc/oea/pmap.c:1.106 src/sys/arch/powerpc/oea/pmap.c:1.107
--- src/sys/arch/powerpc/oea/pmap.c:1.106	Sun Jun 27 12:26:33 2021
+++ src/sys/arch/powerpc/oea/pmap.c	Mon Jul 19 14:49:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.106 2021/06/27 12:26:33 martin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.107 2021/07/19 14:49:45 chs Exp $	*/
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.106 2021/06/27 12:26:33 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.107 2021/07/19 14:49:45 chs Exp $");
 
 #define	PMAP_NOOPNAMES
 
@@ -328,8 +328,6 @@ struct pvo_entry {
 
 TAILQ_HEAD(pvo_tqhead, pvo_entry);
 struct pvo_tqhead *pmap_pvo_table;	/* pvo entries by ptegroup index */
-static struct pvo_head pmap_pvo_kunmanaged = LIST_HEAD_INITIALIZER(pmap_pvo_kunmanaged);	/* list of unmanaged pages */
-static struct pvo_head pmap_pvo_unmanaged = LIST_HEAD_INITIALIZER(pmap_pvo_unmanaged);	/* list of unmanaged pages */
 
 struct pool pmap_pool;		/* pool for pmap structures */
 struct pool pmap_pvo_pool;	/* pool for pvo entries */
@@ -652,7 +650,7 @@ pa_to_pvoh(paddr_t pa, struct vm_page **
 	if (pg_p != NULL)
 		*pg_p = pg;
 	if (pg == NULL)
-		return _pvo_unmanaged;
+		return NULL;
 	md = VM_PAGE_TO_MD(pg);
 	return >mdpg_pvoh;
 }
@@ -1410,22 +1408,19 @@ pmap_pvo_check(const struct pvo_entry *p
 
 	if (PVO_MANAGED_P(pvo)) {
 		pvo_head = pa_to_pvoh(pvo->pvo_pte.pte_lo & PTE_RPGN, NULL);
-	} else {
-		if (pvo->pvo_vaddr < VM_MIN_KERNEL_ADDRESS) {
-			printf("pmap_pvo_check: pvo %p: non kernel address "
-			"on kernel unmanaged list\n", pvo);
+		LIST_FOREACH(pvo0, pvo_head, pvo_vlink) {
+			if (pvo0 == pvo)
+break;
+		}
+		if (pvo0 == NULL) {
+			printf("pmap_pvo_check: pvo %p: not present "
+			   "on its vlist head %p\n", pvo, pvo_head);
 			failed = 1;
 		}
-		pvo_head = _pvo_kunmanaged;
-	}
-	LIST_FOREACH(pvo0, pvo_head, pvo_vlink) {
-		if (pvo0 == pvo)
-			break;
-	}
-	if (pvo0 == NULL) {
-		printf("pmap_pvo_check: pvo %p: not present "
-		"on its vlist head %p\n", pvo, pvo_head);
-		failed = 1;
+	} else {
+		KASSERT(pvo->pvo_vaddr >= VM_MIN_KERNEL_ADDRESS);
+		if (__predict_false(pvo->pvo_vaddr < VM_MIN_KERNEL_ADDRESS))
+			failed = 1;
 	}
 	if (pvo != pmap_pvo_find_va(pvo->pvo_pmap, pvo->pvo_vaddr, NULL)) {
 		printf("pmap_pvo_check: pvo %p: not present "
@@ -1620,7 +1615,7 @@ pmap_pvo_enter(pmap_t pm, struct pool *p
 	}
 	if (flags & PMAP_WIRED)
 		pvo->pvo_vaddr |= PVO_WIRED;
-	if (pvo_head != _pvo_kunmanaged) {
+	if (pvo_head != NULL) {
 		pvo->pvo_vaddr |= PVO_MANAGED; 
 		PMAPCOUNT(mappings);
 	} else {
@@ -1628,7 +1623,8 @@ pmap_pvo_enter(pmap_t pm, struct pool *p
 	}
 	pmap_pte_create(>pvo_pte, pm, va, pa | pte_lo);
 
-	LIST_INSERT_HEAD(pvo_head, pvo, pvo_vlink);
+	if (pvo_head != NULL)
+		LIST_INSERT_HEAD(pvo_head, pvo, pvo_vlink);
 	if (PVO_WIRED_P(pvo))
 		pvo->pvo_pmap->pm_stats.wired_count++;
 	pvo->pvo_pmap->pm_stats.resident_count++;
@@ -1728,7 +1724,9 @@ pmap_pvo_remove(struct pvo_entry *pvo, i
 		pvo->pvo_pmap->pm_stats.wired_count--;
 
 	/*
-	 * Save the REF/CHG bits into their cache if the page is managed.
+	 * If the page is managed:
+	 * Save the REF/CHG bits into their cache.
+	 * Remove the PVO from the P/V list.
 	 */
 	if (PVO_MANAGED_P(pvo)) {
 		register_t ptelo = pvo->pvo_pte.pte_lo;
@@ -1760,15 +1758,15 @@ pmap_pvo_remove(struct pvo_entry *pvo, i
 
 			pmap_attr_save(pg, ptelo & (PTE_REF|PTE_CHG));
 		}
+		LIST_REMOVE(pvo, pvo_vlink);
 		PMAPCOUNT(unmappings);
 	} else {
 		PMAPCOUNT(kernel_unmappings);
 	}
 
 	/*
-	 * Remove the PVO from its lists and return it to the pool.
+	 * Remove the PVO from its list and return it to the pool.
 	 */
-	LIST_REMOVE(pvo, pvo_vlink);
 	TAILQ_REMOVE(_pvo_table[ptegidx], pvo, pvo_olink);
 	if (pvol) {
 		LIST_INSERT_HEAD(pvol, pvo, pvo_vlink);
@@ -1861,9 +1859,10 @@ pmap_enter(pmap_t pm, vaddr_t va, paddr_
 	PMAP_LOCK();
 
 	if (__predict_false(!pmap_initialized)) {
-		pvo_head = _pvo_kunmanaged;
+		pvo_head = NULL;
 		pg = NULL;
 		was_exec = PTE_EXEC;
+
 	} else {
 		pvo_head = pa_to_pvoh(pa, );
 	}
@@ -1952,7 +1951,6 @@ pmap_enter(pmap_t pm, 

CVS commit: src/sys/arch/powerpc/oea

2021-06-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jun 27 12:26:33 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: pmap.c

Log Message:
PR 55325: unify both pvo pools (for managed and unmanaged pages).
Analyzis by rin, fix suggested by chs.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/arch/powerpc/oea/pmap.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/powerpc/oea/pmap.c
diff -u src/sys/arch/powerpc/oea/pmap.c:1.105 src/sys/arch/powerpc/oea/pmap.c:1.106
--- src/sys/arch/powerpc/oea/pmap.c:1.105	Fri Mar 12 18:10:00 2021
+++ src/sys/arch/powerpc/oea/pmap.c	Sun Jun 27 12:26:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.105 2021/03/12 18:10:00 thorpej Exp $	*/
+/*	$NetBSD: pmap.c,v 1.106 2021/06/27 12:26:33 martin Exp $	*/
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.105 2021/03/12 18:10:00 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.106 2021/06/27 12:26:33 martin Exp $");
 
 #define	PMAP_NOOPNAMES
 
@@ -172,8 +172,7 @@ static u_int mem_cnt, avail_cnt;
 #define pmap_procwr		PMAPNAME(procwr)
 
 #define pmap_pool		PMAPNAME(pool)
-#define pmap_upvo_pool		PMAPNAME(upvo_pool)
-#define pmap_mpvo_pool		PMAPNAME(mpvo_pool)
+#define pmap_pvo_pool		PMAPNAME(pvo_pool)
 #define pmap_pvo_table		PMAPNAME(pvo_table)
 #if defined(DEBUG) || defined(PMAPCHECK) || defined(DDB)
 #define pmap_pte_print		PMAPNAME(pte_print)
@@ -333,8 +332,7 @@ static struct pvo_head pmap_pvo_kunmanag
 static struct pvo_head pmap_pvo_unmanaged = LIST_HEAD_INITIALIZER(pmap_pvo_unmanaged);	/* list of unmanaged pages */
 
 struct pool pmap_pool;		/* pool for pmap structures */
-struct pool pmap_upvo_pool;	/* pool for pvo entries for unmanaged pages */
-struct pool pmap_mpvo_pool;	/* pool for pvo entries for managed pages */
+struct pool pmap_pvo_pool;	/* pool for pvo entries */
 
 /*
  * We keep a cache of unmanaged pages to be used for pvo entries for
@@ -344,28 +342,16 @@ struct pvo_page {
 	SIMPLEQ_ENTRY(pvo_page) pvop_link;
 };
 SIMPLEQ_HEAD(pvop_head, pvo_page);
-static struct pvop_head pmap_upvop_head = SIMPLEQ_HEAD_INITIALIZER(pmap_upvop_head);
-static struct pvop_head pmap_mpvop_head = SIMPLEQ_HEAD_INITIALIZER(pmap_mpvop_head);
-static u_long pmap_upvop_free;
-static u_long pmap_upvop_maxfree;
-static u_long pmap_mpvop_free;
-static u_long pmap_mpvop_maxfree;
-
-static void *pmap_pool_ualloc(struct pool *, int);
-static void *pmap_pool_malloc(struct pool *, int);
-
-static void pmap_pool_ufree(struct pool *, void *);
-static void pmap_pool_mfree(struct pool *, void *);
-
-static struct pool_allocator pmap_pool_mallocator = {
-	.pa_alloc = pmap_pool_malloc,
-	.pa_free = pmap_pool_mfree,
-	.pa_pagesz = 0,
-};
-
-static struct pool_allocator pmap_pool_uallocator = {
-	.pa_alloc = pmap_pool_ualloc,
-	.pa_free = pmap_pool_ufree,
+static struct pvop_head pmap_pvop_head = SIMPLEQ_HEAD_INITIALIZER(pmap_pvop_head);
+static u_long pmap_pvop_free;
+static u_long pmap_pvop_maxfree;
+
+static void *pmap_pool_alloc(struct pool *, int);
+static void pmap_pool_free(struct pool *, void *);
+
+static struct pool_allocator pmap_pool_allocator = {
+	.pa_alloc = pmap_pool_alloc,
+	.pa_free = pmap_pool_free,
 	.pa_pagesz = 0,
 };
 
@@ -1101,14 +1087,8 @@ pmap_real_memory(paddr_t *start, psize_t
 void
 pmap_init(void)
 {
-	pool_init(_mpvo_pool, sizeof(struct pvo_entry),
-	sizeof(struct pvo_entry), 0, 0, "pmap_mpvopl",
-	_pool_mallocator, IPL_NONE);
-
-	pool_setlowat(_mpvo_pool, 1008);
 
 	pmap_initialized = 1;
-
 }
 
 /*
@@ -1532,13 +1512,6 @@ pmap_pvo_reclaim(struct pmap *pm)
 	return NULL;
 }
 
-static struct pool *
-pmap_pvo_pl(struct pvo_entry *pvo)
-{
-
-	return PVO_MANAGED_P(pvo) ? _mpvo_pool : _upvo_pool;
-}
-
 /*
  * This returns whether this is the first mapping of a page.
  */
@@ -1603,9 +1576,7 @@ pmap_pvo_enter(pmap_t pm, struct pool *p
 	--pmap_pvo_enter_depth;
 #endif
 	pmap_interrupts_restore(msr);
-	if (pvo) {
-		KASSERT(pmap_pvo_pl(pvo) == pl);
-	} else {
+	if (pvo == NULL) {
 		pvo = pool_get(pl, poolflags);
 	}
 	KASSERT((vaddr_t)pvo < VM_MIN_KERNEL_ADDRESS);
@@ -1811,7 +1782,7 @@ void
 pmap_pvo_free(struct pvo_entry *pvo)
 {
 
-	pool_put(pmap_pvo_pl(pvo), pvo);
+	pool_put(_pvo_pool, pvo);
 }
 
 void
@@ -1883,7 +1854,6 @@ pmap_enter(pmap_t pm, vaddr_t va, paddr_
 	struct mem_region *mp;
 	struct pvo_head *pvo_head;
 	struct vm_page *pg;
-	struct pool *pl;
 	register_t pte_lo;
 	int error;
 	u_int was_exec = 0;
@@ -1892,12 +1862,10 @@ pmap_enter(pmap_t pm, vaddr_t va, paddr_
 
 	if (__predict_false(!pmap_initialized)) {
 		pvo_head = _pvo_kunmanaged;
-		pl = _upvo_pool;
 		pg = NULL;
 		was_exec = PTE_EXEC;
 	} else {
 		pvo_head = pa_to_pvoh(pa, );
-		pl = _mpvo_pool;
 	}
 
 	DPRINTFN(ENTER,
@@ -1961,7 +1929,7 @@ pmap_enter(pmap_t pm, vaddr_t va, paddr_
 	 * 

CVS commit: src/sys/arch/powerpc/booke/dev

2021-04-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Apr 22 01:33:18 UTC 2021

Modified Files:
src/sys/arch/powerpc/booke/dev: pq3etsec.c

Log Message:
Fix rnd(9) support; events were not sampled actually in the previous.

Remove #if-0'ed and wrap long line for clarity.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/powerpc/booke/dev/pq3etsec.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/powerpc/booke/dev/pq3etsec.c
diff -u src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.52 src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.53
--- src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.52	Sun Jan 24 05:16:56 2021
+++ src/sys/arch/powerpc/booke/dev/pq3etsec.c	Thu Apr 22 01:33:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pq3etsec.c,v 1.52 2021/01/24 05:16:56 rin Exp $	*/
+/*	$NetBSD: pq3etsec.c,v 1.53 2021/04/22 01:33:18 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.52 2021/01/24 05:16:56 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.53 2021/04/22 01:33:18 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1640,14 +1640,14 @@ pq3etsec_rxq_consume(
 			rxq->rxq_consumer = consumer;
 			rxq->rxq_inuse -= rxconsumed;
 			KASSERT(rxq->rxq_inuse == 0);
-			return;
+			break;
 		}
 		pq3etsec_rxq_desc_postsync(sc, rxq, consumer, 1);
 		const uint16_t rxbd_flags = consumer->rxbd_flags;
 		if (rxbd_flags & RXBD_E) {
 			rxq->rxq_consumer = consumer;
 			rxq->rxq_inuse -= rxconsumed;
-			return;
+			break;
 		}
 		KASSERT(rxq->rxq_mconsumer != NULL);
 #ifdef ETSEC_DEBUG
@@ -2178,6 +2178,7 @@ pq3etsec_txq_consume(
 	struct ifnet * const ifp = >sc_if;
 	volatile struct txbd *consumer = txq->txq_consumer;
 	size_t txfree = 0;
+	bool ret;
 
 #if 0
 	printf("%s: entry: free=%zu\n", __func__, txq->txq_free);
@@ -2189,13 +2190,11 @@ pq3etsec_txq_consume(
 			txq->txq_consumer = consumer;
 			txq->txq_free += txfree;
 			txq->txq_lastintr -= uimin(txq->txq_lastintr, txfree);
-#if 0
-			printf("%s: empty: freed %zu descriptors going form %zu to %zu\n",
-			__func__, txfree, txq->txq_free - txfree, txq->txq_free);
-#endif
 			KASSERT(txq->txq_lastintr == 0);
-			KASSERT(txq->txq_free == txq->txq_last - txq->txq_first - 1);
-			return true;
+			KASSERT(txq->txq_free ==
+			txq->txq_last - txq->txq_first - 1);
+			ret = true;
+			break;
 		}
 		pq3etsec_txq_desc_postsync(sc, txq, consumer, 1);
 		const uint16_t txbd_flags = consumer->txbd_flags;
@@ -2203,11 +2202,8 @@ pq3etsec_txq_consume(
 			txq->txq_consumer = consumer;
 			txq->txq_free += txfree;
 			txq->txq_lastintr -= uimin(txq->txq_lastintr, txfree);
-#if 0
-			printf("%s: freed %zu descriptors\n",
-			__func__, txfree);
-#endif
-			return pq3etsec_txq_fillable_p(sc, txq);
+			ret = pq3etsec_txq_fillable_p(sc, txq);
+			break;
 		}
 
 		/*
@@ -2274,6 +2270,7 @@ pq3etsec_txq_consume(
 
 	if (txfree != 0)
 		rnd_add_uint32(>rnd_source, txfree);
+	return ret;
 }
 
 static void



CVS commit: src/sys/arch/powerpc/include/booke

2021-04-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Apr 17 13:25:57 UTC 2021

Modified Files:
src/sys/arch/powerpc/include/booke: vmparam.h

Log Message:
Sync MAXfoo params with oea:

  MAXTSIZ: 512MB -> 128MB
  MAXDSIZ: 3.25GB -> 1GB

There should be no particular reasons for having different values.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/powerpc/include/booke/vmparam.h

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/powerpc/include/booke/vmparam.h
diff -u src/sys/arch/powerpc/include/booke/vmparam.h:1.8 src/sys/arch/powerpc/include/booke/vmparam.h:1.9
--- src/sys/arch/powerpc/include/booke/vmparam.h:1.8	Sat Apr 17 13:23:24 2021
+++ src/sys/arch/powerpc/include/booke/vmparam.h	Sat Apr 17 13:25:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.8 2021/04/17 13:23:24 rin Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.9 2021/04/17 13:25:57 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -56,11 +56,11 @@
 #endif
 
 #ifndef	MAXTSIZ
-#define	MAXTSIZ		(2*256*1024*1024)	/* maximum text size */
+#define	MAXTSIZ		(128*1024*1024)		/* maximum text size */
 #endif
 
 #ifndef	MAXDSIZ
-#define	MAXDSIZ		(13*256*1024*1024U)	/* maximum data size */
+#define	MAXDSIZ		(1024*1024*1024)	/* maximum data size */
 #endif
 
 #ifndef	MAXSSIZ



CVS commit: src/sys/arch/powerpc/include/booke

2021-04-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Apr 17 13:23:24 UTC 2021

Modified Files:
src/sys/arch/powerpc/include/booke: vmparam.h

Log Message:
PR port-powerpc/56107

Decrease MAXSSIZ from ~256MB to 32MB (same as oea).

This fixes tests in /usr/tests/usr.bin/make, that run with "ulimit -v 20",
fail with "Cannot map anonymous memory".

Although I'm not fully convinced whether this limit is reasonable or not,
old MAXSSIZ of ~256MB is too much anyway.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/powerpc/include/booke/vmparam.h

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/powerpc/include/booke/vmparam.h
diff -u src/sys/arch/powerpc/include/booke/vmparam.h:1.7 src/sys/arch/powerpc/include/booke/vmparam.h:1.8
--- src/sys/arch/powerpc/include/booke/vmparam.h:1.7	Tue Oct  2 23:51:39 2012
+++ src/sys/arch/powerpc/include/booke/vmparam.h	Sat Apr 17 13:23:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.7 2012/10/02 23:51:39 christos Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.8 2021/04/17 13:23:24 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -64,7 +64,7 @@
 #endif
 
 #ifndef	MAXSSIZ
-#define	MAXSSIZ		(1*256*1024*1024-PAGE_SIZE) /* maximum stack size */
+#define	MAXSSIZ		(32*1024*1024)		/* maximum stack size */
 #endif
 
 #ifndef	DFLDSIZ



CVS commit: src/sys/arch/powerpc/include/oea

2021-04-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Apr 17 09:22:29 UTC 2021

Modified Files:
src/sys/arch/powerpc/include/oea: vmparam.h

Log Message:
Adjust TABs. No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/powerpc/include/oea/vmparam.h

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/powerpc/include/oea/vmparam.h
diff -u src/sys/arch/powerpc/include/oea/vmparam.h:1.20 src/sys/arch/powerpc/include/oea/vmparam.h:1.21
--- src/sys/arch/powerpc/include/oea/vmparam.h:1.20	Thu Aug 17 22:55:47 2017
+++ src/sys/arch/powerpc/include/oea/vmparam.h	Sat Apr 17 09:22:28 2021
@@ -47,54 +47,54 @@
 #define	PAGE_MASK	(PAGE_SIZE - 1)
 
 #ifndef	USRSTACK
-#define	USRSTACK		VM_MAXUSER_ADDRESS
+#define	USRSTACK	VM_MAXUSER_ADDRESS
 #endif
 
 #ifndef	USRSTACK32
-#define	USRSTACK32		VM_MAXUSER_ADDRESS32
+#define	USRSTACK32	VM_MAXUSER_ADDRESS32
 #endif
 
 #ifndef	MAXTSIZ
-#define	MAXTSIZ			(128*1024*1024)		/* maximum text size */
+#define	MAXTSIZ		(128*1024*1024)		/* maximum text size */
 #endif
 
 #ifndef	MAXDSIZ
-#define	MAXDSIZ			(1024*1024*1024)	/* maximum data size */
+#define	MAXDSIZ		(1024*1024*1024)	/* maximum data size */
 #endif
 
 #ifndef	MAXDSIZ32
-#define	MAXDSIZ32		(1024*1024*1024)	/* maximum data size */
+#define	MAXDSIZ32	(1024*1024*1024)	/* maximum data size */
 #endif
 
 #ifndef	MAXSSIZ
-#define	MAXSSIZ			(32*1024*1024)		/* maximum stack size */
+#define	MAXSSIZ		(32*1024*1024)		/* maximum stack size */
 #endif
 
 #ifndef	MAXSSIZ32
-#define	MAXSSIZ32		(32*1024*1024)		/* maximum stack size */
+#define	MAXSSIZ32	(32*1024*1024)		/* maximum stack size */
 #endif
 
 #ifndef	DFLDSIZ
-#define	DFLDSIZ			(256*1024*1024)		/* default data size */
+#define	DFLDSIZ		(256*1024*1024)		/* default data size */
 #endif
 
 #ifndef	DFLDSIZ32
-#define	DFLSSIZ32		(256*1024*1024)
+#define	DFLSSIZ32	(256*1024*1024)
 #endif
 
 #ifndef	DFLSSIZ
-#define	DFLSSIZ			(2*1024*1024)		/* default stack size */
+#define	DFLSSIZ		(2*1024*1024)		/* default stack size */
 #endif
 
 #ifndef	DFLSSIZ32
-#define	DFLSSIZ32		(2*1024*1024)		/* default stack size */
+#define	DFLSSIZ32	(2*1024*1024)		/* default stack size */
 #endif
 
 /*
  * Default number of pages in the user raw I/O map.
  */
 #ifndef USRIOSIZE
-#define	USRIOSIZE		1024
+#define	USRIOSIZE	1024
 #endif
 
 /*
@@ -102,7 +102,7 @@
  * considered very swappable.
  */
 #ifndef MAXSLP
-#define	MAXSLP			20
+#define	MAXSLP		20
 #endif
 
 /*



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-04-14 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Apr 15 00:00:46 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: pmap.c

Log Message:
Use uvm_km_alloc(9) with UVM_KMF_NOWAIT flag in pte_enter(), in order not to
sleep in pmap_enter(9) and pmap_kenter_pa(9), which can result in dead lock.

In most cases, pmap_enter(9) is used with PMAP_CANFAIL flag. In this case,
if pte_enter() fails due to uvm_km_alloc(9), we can safely return ENOMEM.
UVM layer will take care of it.

uvm_km_alloc(9) fails for pmap_enter(9) without PMAP_CANFAIL or for
pmap_kenter_pa(9), we have no choice but to panic there.

However, my testbeds for 403 and 405 survive more than a week at least
without hitting this panic.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/arch/powerpc/ibm4xx/pmap.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/powerpc/ibm4xx/pmap.c
diff -u src/sys/arch/powerpc/ibm4xx/pmap.c:1.97 src/sys/arch/powerpc/ibm4xx/pmap.c:1.98
--- src/sys/arch/powerpc/ibm4xx/pmap.c:1.97	Wed Apr 14 23:45:11 2021
+++ src/sys/arch/powerpc/ibm4xx/pmap.c	Thu Apr 15 00:00:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.97 2021/04/14 23:45:11 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.98 2021/04/15 00:00:46 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.97 2021/04/14 23:45:11 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.98 2021/04/15 00:00:46 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -236,11 +236,15 @@ pte_enter(struct pmap *pm, vaddr_t va, u
 	if (!pm->pm_ptbl[seg]) {
 		/* Don't allocate a page to clear a non-existent mapping. */
 		if (!pte)
+			return 1;
+
+		vaddr_t km = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
+		UVM_KMF_WIRED | UVM_KMF_ZERO | UVM_KMF_NOWAIT);
+
+		if (__predict_false(km == 0))
 			return 0;
-		/* Allocate a page  this will sleep! */
-		pm->pm_ptbl[seg] =
-		(uint *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
-		UVM_KMF_WIRED | UVM_KMF_ZERO);
+
+		pm->pm_ptbl[seg] = (u_int *)km;
 	}
 	oldpte = pm->pm_ptbl[seg][ptn];
 	pm->pm_ptbl[seg][ptn] = pte;
@@ -862,7 +866,7 @@ pmap_enter(struct pmap *pm, vaddr_t va, 
 
 		if (!pmap_enter_pv(pm, va, pa, flags)) {
 			/* Could not enter pv on a managed page */
-			return 1;
+			return ENOMEM;
 		}
 
 		/* Now set attributes. */
@@ -880,7 +884,12 @@ pmap_enter(struct pmap *pm, vaddr_t va, 
 	s = splvm();
 
 	/* Insert page into page table. */
-	pte_enter(pm, va, tte);
+	if (__predict_false(!pte_enter(pm, va, tte))) {
+		if (__predict_false((flags & PMAP_CANFAIL) == 0))
+			panic("%s: pte_enter", __func__);
+		splx(s);
+		return ENOMEM;
+	}
 
 	/* If this is a real fault, enter it in the tlb */
 	if (tte && ((flags & PMAP_WIRED) == 0)) {
@@ -969,7 +978,8 @@ pmap_kenter_pa(vaddr_t va, paddr_t pa, v
 	s = splvm();
 
 	/* Insert page into page table. */
-	pte_enter(pm, va, tte);
+	if (__predict_false(!pte_enter(pm, va, tte)))
+		panic("%s: pte_enter", __func__);
 	splx(s);
 }
 
@@ -978,7 +988,7 @@ pmap_kremove(vaddr_t va, vsize_t len)
 {
 
 	while (len > 0) {
-		pte_enter(pmap_kernel(), va, 0);
+		(void)pte_enter(pmap_kernel(), va, 0);	/* never fail */
 		va += PAGE_SIZE;
 		len -= PAGE_SIZE;
 	}



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-04-14 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Apr 14 23:45:11 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: pmap.c

Log Message:
Style fixes:

- Add "static inline" to pte_enter(), to match with its declaration.
- Remove parentheses from return.
- Use NULL instead of 0 for pointer initialization.

No binary changes.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/arch/powerpc/ibm4xx/pmap.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/powerpc/ibm4xx/pmap.c
diff -u src/sys/arch/powerpc/ibm4xx/pmap.c:1.96 src/sys/arch/powerpc/ibm4xx/pmap.c:1.97
--- src/sys/arch/powerpc/ibm4xx/pmap.c:1.96	Tue Mar 30 03:15:53 2021
+++ src/sys/arch/powerpc/ibm4xx/pmap.c	Wed Apr 14 23:45:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.96 2021/03/30 03:15:53 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.97 2021/04/14 23:45:11 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.96 2021/03/30 03:15:53 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.97 2021/04/14 23:45:11 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -226,7 +226,7 @@ pa_to_attr(paddr_t pa)
 /*
  * Insert PTE into page table.
  */
-int
+static inline int
 pte_enter(struct pmap *pm, vaddr_t va, u_int pte)
 {
 	int seg = STIDX(va);
@@ -236,7 +236,7 @@ pte_enter(struct pmap *pm, vaddr_t va, u
 	if (!pm->pm_ptbl[seg]) {
 		/* Don't allocate a page to clear a non-existent mapping. */
 		if (!pte)
-			return (0);
+			return 0;
 		/* Allocate a page  this will sleep! */
 		pm->pm_ptbl[seg] =
 		(uint *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
@@ -253,7 +253,7 @@ pte_enter(struct pmap *pm, vaddr_t va, u
 		else
 			pm->pm_stats.resident_count++;
 	}
-	return (1);
+	return 1;
 }
 
 /*
@@ -266,9 +266,9 @@ pte_find(struct pmap *pm, vaddr_t va)
 	int ptn = PTIDX(va);
 
 	if (pm->pm_ptbl[seg])
-		return (>pm_ptbl[seg][ptn]);
+		return >pm_ptbl[seg][ptn];
 
-	return (NULL);
+	return NULL;
 }
 
 /*
@@ -293,7 +293,7 @@ pmap_bootstrap(u_int kernelstart, u_int 
 	 * Initialize kernel page table.
 	 */
 	for (i = 0; i < STSZ; i++) {
-		pmap_kernel()->pm_ptbl[i] = 0;
+		pmap_kernel()->pm_ptbl[i] = NULL;
 	}
 	ctxbusy[0] = ctxbusy[1] = pmap_kernel();
 
@@ -565,7 +565,7 @@ pmap_growkernel(vaddr_t maxkvaddr)
 		pm->pm_ptbl[seg] = (u_int *)pg;
 	}
 	splx(s);
-	return (kbreak);
+	return kbreak;
 }
 
 /*
@@ -758,7 +758,7 @@ pmap_enter_pv(struct pmap *pm, vaddr_t v
 		pm->pm_stats.wired_count++;
 	}
 	splx(s);
-	return (1);
+	return 1;
 }
 
 static void
@@ -1026,7 +1026,7 @@ pmap_extract(struct pmap *pm, vaddr_t va
 		*pap = TTE_PA(pa) | (va & PGOFSET);
 	}
 	splx(s);
-	return (pa != 0);
+	return pa != 0;
 }
 
 /*
@@ -1338,7 +1338,7 @@ ppc4xx_tlb_find_victim(void)
 tlb_info[tlbnext].ti_flags = flags;
 			} else {
 /* Found it! */
-return (tlbnext);
+return tlbnext;
 			}
 		} else {
 			tlb_info[tlbnext].ti_flags = (flags & ~TLBF_REF);
@@ -1428,9 +1428,9 @@ ppc4xx_tlb_size_mask(size_t size, int *m
 		if (size <= tlbsize[i]) {
 			*mask = (i << TLB_SIZE_SHFT);
 			*rsiz = tlbsize[i];
-			return (0);
+			return 0;
 		}
-	return (EINVAL);
+	return EINVAL;
 }
 
 /*
@@ -1470,10 +1470,10 @@ ppc4xx_tlb_mapiodev(paddr_t base, psize_
 			continue;
 
 		va = (hi & TLB_EPN_MASK) + (base & (sz - 1)); 	/* sz = 2^n */
-		return (void *)(va);
+		return (void *)va;
 	}
 
-	return (NULL);
+	return NULL;
 }
 
 /*
@@ -1579,7 +1579,7 @@ ctx_flush(int cnum)
 Debugger();
 #endif
 #endif
-return (1);
+return 1;
 			}
 #ifdef DIAGNOSTIC
 			if (i < tlb_nreserved)
@@ -1592,7 +1592,7 @@ ctx_flush(int cnum)
 			tlb_invalidate_entry(i);
 		}
 	}
-	return (0);
+	return 0;
 }
 
 /*
@@ -1610,7 +1610,7 @@ ctx_alloc(struct pmap *pm)
 #ifdef DIAGNOSTIC
 		printf("ctx_alloc: kernel pmap!\n");
 #endif
-		return (0);
+		return 0;
 	}
 	s = splvm();
 



CVS commit: src/sys/arch/powerpc/oea

2021-04-02 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Fri Apr  2 16:59:59 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofwoea_machdep.c

Log Message:
clarify comment in previous
( this is a hack, should go away when the root cause is fixed etc. )
no functional change


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/arch/powerpc/oea/ofwoea_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/powerpc/oea/ofwoea_machdep.c
diff -u src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.60 src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.61
--- src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.60	Thu Apr  1 22:02:20 2021
+++ src/sys/arch/powerpc/oea/ofwoea_machdep.c	Fri Apr  2 16:59:59 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofwoea_machdep.c,v 1.60 2021/04/01 22:02:20 macallan Exp $ */
+/* $NetBSD: ofwoea_machdep.c,v 1.61 2021/04/02 16:59:59 macallan Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.60 2021/04/01 22:02:20 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.61 2021/04/02 16:59:59 macallan Exp $");
 
 #include "ksyms.h"
 #include "wsdisplay.h"
@@ -379,9 +379,12 @@ restore_ofmap(void)
 			continue;
 
 		/*
-		 * XXX
-		 * my beige G3 throws a DSI trap if we try to map the last page
-		 * of the firmware ROM
+		 * XXX macallan@
+		 * My beige G3 throws a DSI trap if we try to map the last page
+		 * of the 32bit address space. On old world macs the firmware
+		 * ROM occupies 4MB at 0xffc0, triggering it when we 
+		 * restore OF translations. This just works around a bug
+		 * elsewhere in pmap and should go away once fixed there.
 		 */
 		if (pa == 0xffc0 && size == 0x40)
 			size = 0x3ff000;



CVS commit: src/sys/arch/powerpc/include/ibm4xx

2021-04-01 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Apr  2 03:20:54 UTC 2021

Modified Files:
src/sys/arch/powerpc/include/ibm4xx: dcr4xx.h

Log Message:
Add bit-field definitions for DCR_SDRAM0_B[0-3]CR registers.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/powerpc/include/ibm4xx/dcr4xx.h

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/powerpc/include/ibm4xx/dcr4xx.h
diff -u src/sys/arch/powerpc/include/ibm4xx/dcr4xx.h:1.3 src/sys/arch/powerpc/include/ibm4xx/dcr4xx.h:1.4
--- src/sys/arch/powerpc/include/ibm4xx/dcr4xx.h:1.3	Thu Nov 21 13:33:15 2013
+++ src/sys/arch/powerpc/include/ibm4xx/dcr4xx.h	Fri Apr  2 03:20:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dcr4xx.h,v 1.3 2013/11/21 13:33:15 kiyohara Exp $	*/
+/*	$NetBSD: dcr4xx.h,v 1.4 2021/04/02 03:20:53 rin Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -303,6 +303,8 @@
 #define DCR_SDRAM0_B1CR		0x44
 #define DCR_SDRAM0_B2CR		0x48
 #define DCR_SDRAM0_B3CR		0x4c
+#define   SDRAM0_BnCR_EN	  0x0001
+#define   SDRAM0_BnCR_SZ(n)	  (1 << n) >> 17) & 7) + 22))
 #define DCR_SDRAM0_TR		0x80
 #define DCR_SDRAM0_ECCCFG	0x94
 #define DCR_SDRAM0_ECCESR	0x98



CVS commit: src/sys/arch/powerpc/oea

2021-04-01 Thread Michael Lorenz
Module Name:src
Committed By:   macallan
Date:   Thu Apr  1 22:02:20 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofwoea_machdep.c

Log Message:
avoid mapping 0xf000 - my beige G3 DSIs on it
with this my the machine boots again
tested on a variety of G4 and G5 models with no problems


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/arch/powerpc/oea/ofwoea_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/powerpc/oea/ofwoea_machdep.c
diff -u src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.59 src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.60
--- src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.59	Fri Mar  5 18:10:06 2021
+++ src/sys/arch/powerpc/oea/ofwoea_machdep.c	Thu Apr  1 22:02:20 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofwoea_machdep.c,v 1.59 2021/03/05 18:10:06 thorpej Exp $ */
+/* $NetBSD: ofwoea_machdep.c,v 1.60 2021/04/01 22:02:20 macallan Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.59 2021/03/05 18:10:06 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.60 2021/04/01 22:02:20 macallan Exp $");
 
 #include "ksyms.h"
 #include "wsdisplay.h"
@@ -378,6 +378,14 @@ restore_ofmap(void)
 		if (va < 0xf000)	/* XXX */
 			continue;
 
+		/*
+		 * XXX
+		 * my beige G3 throws a DSI trap if we try to map the last page
+		 * of the firmware ROM
+		 */
+		if (pa == 0xffc0 && size == 0x40)
+			size = 0x3ff000;
+
 		while (size > 0) {
 			pmap_enter(_pmap, va, pa, VM_PROT_ALL,
 			VM_PROT_ALL|PMAP_WIRED);



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-03-30 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Mar 30 14:33:10 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: ibm4xx_machdep.c

Log Message:
Use ``for (;;)'' for infinite loop, as required by style.
No binary changes.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/powerpc/ibm4xx/ibm4xx_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/powerpc/ibm4xx/ibm4xx_machdep.c
diff -u src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c:1.36 src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c:1.37
--- src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c:1.36	Tue Mar 30 01:33:50 2021
+++ src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c	Tue Mar 30 14:33:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ibm4xx_machdep.c,v 1.36 2021/03/30 01:33:50 rin Exp $	*/
+/*	$NetBSD: ibm4xx_machdep.c,v 1.37 2021/03/30 14:33:10 rin Exp $	*/
 /*	Original: ibm40x_machdep.c,v 1.3 2005/01/17 17:19:36 shige Exp $ */
 
 /*
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ibm4xx_machdep.c,v 1.36 2021/03/30 01:33:50 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibm4xx_machdep.c,v 1.37 2021/03/30 14:33:10 rin Exp $");
 
 #include "ksyms.h"
 
@@ -221,7 +221,7 @@ cpu_reboot(int howto, char *what)
 
 	printf("ppc4xx_reset() failed!\n");
 
-	while (1 /* CONSTCOND */) {
+	for (;;) {
 #if defined(DDB)
 		Debugger();
 #elif defined(KGDB)



CVS commit: src/sys/arch/powerpc/booke

2021-03-30 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Mar 30 14:29:54 UTC 2021

Modified Files:
src/sys/arch/powerpc/booke: booke_machdep.c

Log Message:
- Write-back msgbuf and update bootstr for reboot from halt.
- Remove dead code.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/powerpc/booke/booke_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/powerpc/booke/booke_machdep.c
diff -u src/sys/arch/powerpc/booke/booke_machdep.c:1.32 src/sys/arch/powerpc/booke/booke_machdep.c:1.33
--- src/sys/arch/powerpc/booke/booke_machdep.c:1.32	Mon Jul  6 10:08:16 2020
+++ src/sys/arch/powerpc/booke/booke_machdep.c	Tue Mar 30 14:29:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: booke_machdep.c,v 1.32 2020/07/06 10:08:16 rin Exp $	*/
+/*	$NetBSD: booke_machdep.c,v 1.33 2021/03/30 14:29:54 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -38,7 +38,7 @@
 #define	_POWERPC_BUS_DMA_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: booke_machdep.c,v 1.32 2020/07/06 10:08:16 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: booke_machdep.c,v 1.33 2021/03/30 14:29:54 rin Exp $");
 
 #include "ksyms.h"
 
@@ -288,15 +288,6 @@ cpu_reboot(int howto, char *what)
 		cnpollc(1);	/* For proper keyboard command handling */
 		cngetc();
 		cnpollc(0);
-
-		printf("rebooting...\n\n");
-		goto reboot;	/* XXX for now... */
-
-#ifdef DDB
-		printf("dropping to debugger\n");
-		while(1)
-			Debugger();
-#endif
 	}
 
 	printf("rebooting\n\n");
@@ -321,7 +312,6 @@ cpu_reboot(int howto, char *what)
 	/* flush cache for msgbuf */
 	dcache_wb(msgbuf_paddr, round_page(MSGBUFSIZE));
 
- reboot:
 	__asm volatile("msync; isync");
 	(*cpu_md_ops.md_cpu_reset)();
 



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-03-30 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Tue Mar 30 13:41:46 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: cpu.c

Log Message:
Fix nearly 20 year old type - cache sizes are 2048 bytes, not 2848 bytes.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/powerpc/ibm4xx/cpu.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/powerpc/ibm4xx/cpu.c
diff -u src/sys/arch/powerpc/ibm4xx/cpu.c:1.37 src/sys/arch/powerpc/ibm4xx/cpu.c:1.38
--- src/sys/arch/powerpc/ibm4xx/cpu.c:1.37	Tue Mar 30 02:27:00 2021
+++ src/sys/arch/powerpc/ibm4xx/cpu.c	Tue Mar 30 13:41:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.37 2021/03/30 02:27:00 rin Exp $	*/
+/*	$NetBSD: cpu.c,v 1.38 2021/03/30 13:41:46 simonb Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.37 2021/03/30 02:27:00 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.38 2021/03/30 13:41:46 simonb Exp $");
 
 #include 
 #include 
@@ -66,7 +66,7 @@ static const struct cputab models[] = {
 		.ci = {
 			.dcache_size = 1024,
 			.dcache_line_size = 16,
-			.icache_size = 2848,
+			.icache_size = 2048,
 			.icache_line_size = 16,
 		}
 	}, {
@@ -94,7 +94,7 @@ static const struct cputab models[] = {
 		.mask = 0x,
 		.name = "401D2",
 		.ci = {
-			.dcache_size = 2848,
+			.dcache_size = 2048,
 			.dcache_line_size = 16,
 			.icache_size = 4096,
 			.icache_line_size = 16,
@@ -116,7 +116,7 @@ static const struct cputab models[] = {
 		.ci = {
 			.dcache_size = 2048,
 			.dcache_line_size = 16,
-			.icache_size = 2848,
+			.icache_size = 2048,
 			.icache_line_size = 16,
 		}
 	}, {
@@ -124,7 +124,7 @@ static const struct cputab models[] = {
 		.mask = 0x,
 		.name = "401G2",
 		.ci = {
-			.dcache_size = 2848,
+			.dcache_size = 2048,
 			.dcache_line_size = 16,
 			.icache_size = 8192,
 			.icache_line_size = 16,



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-03-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Mar 30 02:27:00 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: cpu.c

Log Message:
According to "PPC405GP Embedded Processor User’s Manual",
405GP has 16KB instruction cache, not 8KB.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/powerpc/ibm4xx/cpu.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/powerpc/ibm4xx/cpu.c
diff -u src/sys/arch/powerpc/ibm4xx/cpu.c:1.36 src/sys/arch/powerpc/ibm4xx/cpu.c:1.37
--- src/sys/arch/powerpc/ibm4xx/cpu.c:1.36	Fri Mar  5 07:11:24 2021
+++ src/sys/arch/powerpc/ibm4xx/cpu.c	Tue Mar 30 02:27:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.36 2021/03/05 07:11:24 rin Exp $	*/
+/*	$NetBSD: cpu.c,v 1.37 2021/03/30 02:27:00 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.36 2021/03/05 07:11:24 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.37 2021/03/30 02:27:00 rin Exp $");
 
 #include 
 #include 
@@ -176,7 +176,7 @@ static const struct cputab models[] = {
 		.ci = {
 			.dcache_size = 8192,
 			.dcache_line_size = 32,
-			.icache_size = 8192,
+			.icache_size = 16384,
 			.icache_line_size = 32,
 		}
 	}, {



CVS commit: src/sys/arch/powerpc/ibm4xx/dev

2021-03-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Mar 30 02:25:24 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx/dev: emacreg.h if_emac.c

Log Message:
Support OPB running @ 33MHz for 405GP based boards.
No need to modify EMAC_MR1 register this case
(STACR_OPBC fields are reserved for 405GP).


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/powerpc/ibm4xx/dev/emacreg.h
cvs rdiff -u -r1.55 -r1.56 src/sys/arch/powerpc/ibm4xx/dev/if_emac.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/powerpc/ibm4xx/dev/emacreg.h
diff -u src/sys/arch/powerpc/ibm4xx/dev/emacreg.h:1.4 src/sys/arch/powerpc/ibm4xx/dev/emacreg.h:1.5
--- src/sys/arch/powerpc/ibm4xx/dev/emacreg.h:1.4	Mon Jul  6 09:34:17 2020
+++ src/sys/arch/powerpc/ibm4xx/dev/emacreg.h	Tue Mar 30 02:25:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: emacreg.h,v 1.4 2020/07/06 09:34:17 rin Exp $	*/
+/*	$NetBSD: emacreg.h,v 1.5 2021/03/30 02:25:24 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -215,6 +215,7 @@
 #define	  STACR_PHYE		  0x4000	/* PHY error */
 #define	  STACR_WRITE		  0x2000	/* STA command - write */
 #define	  STACR_READ		  0x1000	/* STA command - read */
+#define	  STACR_OPBC_33MHZ	  0x0		/*   -  33MHz */
 #define	  STACR_OPBC_50MHZ	  0x0		/*   -  50MHz */
 #define	  STACR_OPBC_66MHZ	  0x1		/*   -  66MHz */
 #define	  STACR_OPBC_83MHZ	  0x2		/*   -  83MHz */

Index: src/sys/arch/powerpc/ibm4xx/dev/if_emac.c
diff -u src/sys/arch/powerpc/ibm4xx/dev/if_emac.c:1.55 src/sys/arch/powerpc/ibm4xx/dev/if_emac.c:1.56
--- src/sys/arch/powerpc/ibm4xx/dev/if_emac.c:1.55	Sat Feb 27 20:43:58 2021
+++ src/sys/arch/powerpc/ibm4xx/dev/if_emac.c	Tue Mar 30 02:25:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_emac.c,v 1.55 2021/02/27 20:43:58 rin Exp $	*/
+/*	$NetBSD: if_emac.c,v 1.56 2021/03/30 02:25:24 rin Exp $	*/
 
 /*
  * Copyright 2001, 2002 Wasabi Systems, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_emac.c,v 1.55 2021/02/27 20:43:58 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_emac.c,v 1.56 2021/03/30 02:25:24 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_emac.h"
@@ -456,6 +456,7 @@ emac_attach(device_t parent, device_t se
 
 	opb_freq = opb_get_frequency();
 	switch (opb_freq) {
+	case  : opbc =  STACR_OPBC_33MHZ; break;
 	case  5000: opbc =  STACR_OPBC_50MHZ; break;
 	case  : opbc =  STACR_OPBC_66MHZ; break;
 	case  8333: opbc =  STACR_OPBC_83MHZ; break;



CVS commit: src/sys/arch/powerpc/ibm4xx/openbios

2021-03-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Mar 30 01:57:20 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx/openbios: locore.S

Log Message:
Use mnemonic "bdneq". Add missing register prefix.

No binary changes.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/powerpc/ibm4xx/openbios/locore.S

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/powerpc/ibm4xx/openbios/locore.S
diff -u src/sys/arch/powerpc/ibm4xx/openbios/locore.S:1.16 src/sys/arch/powerpc/ibm4xx/openbios/locore.S:1.17
--- src/sys/arch/powerpc/ibm4xx/openbios/locore.S:1.16	Sun Mar  7 02:54:06 2021
+++ src/sys/arch/powerpc/ibm4xx/openbios/locore.S	Tue Mar 30 01:57:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.16 2021/03/07 02:54:06 simonb Exp $	*/
+/*	$NetBSD: locore.S,v 1.17 2021/03/30 01:57:20 rin Exp $	*/
 /*	$OpenBSD: locore.S,v 1.4 1997/01/26 09:06:38 rahnds Exp $	*/
 
 /*
@@ -95,11 +95,6 @@
 #define BOARD_CFG_FP   0xFFFE0B50
 
 /*
- * Some instructions gas doesn't understand (yet?)
- */
-#define	bdneq	bdnzf 2,
-
-/*
  * This symbol is here for the benefit of kvm_mkdb, and is supposed to
  * mark the start of kernel text.
  */
@@ -192,7 +187,7 @@ __start_cpu0:
 	mtpid	%r0
 	sync
 
-	INIT_CPUINFO(8,1,9,0)
+	INIT_CPUINFO(%r8,%r1,%r9,%r0)
 	mr	%r4,%r8
 
 	lis	%r3,__start@ha



CVS commit: src/sys/arch/powerpc/ibm4xx/openbios

2021-03-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Mar 30 01:50:13 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx/openbios: openbios.c

Log Message:
- Document IBM/AMCC Walnut is supported by this file.
- Misc style fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/powerpc/ibm4xx/openbios/openbios.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/powerpc/ibm4xx/openbios/openbios.c
diff -u src/sys/arch/powerpc/ibm4xx/openbios/openbios.c:1.6 src/sys/arch/powerpc/ibm4xx/openbios/openbios.c:1.7
--- src/sys/arch/powerpc/ibm4xx/openbios/openbios.c:1.6	Tue Mar 30 01:47:45 2021
+++ src/sys/arch/powerpc/ibm4xx/openbios/openbios.c	Tue Mar 30 01:50:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: openbios.c,v 1.6 2021/03/30 01:47:45 rin Exp $	*/
+/*	$NetBSD: openbios.c,v 1.7 2021/03/30 01:50:13 rin Exp $	*/
 
 /*
  * Copyright (c) 2004 Shigeyuki Fukushima.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: openbios.c,v 1.6 2021/03/30 01:47:45 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: openbios.c,v 1.7 2021/03/30 01:50:13 rin Exp $");
 
 #include 
 #include 
@@ -44,6 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: openbios.c,v
  * Board configuration structure from the OpenBIOS.
  *
  * Supported (XXX):
+ *IBM/AMCC Walnut PowerPC 405GP Evaluation Board
  *405GPr 1.2 ROM Monitor (5/25/02)
  */
 struct board_bios_data {
@@ -73,6 +74,7 @@ openbios_board_init(void *info_block)
 unsigned int
 openbios_board_memsize_get(void)
 {
+
 	return board_bios.mem_size;
 }
 
@@ -142,7 +144,6 @@ openbios_board_info_set(void)
 	prop_object_release(pn);
 }
 
-
 void
 openbios_board_print(void)
 {



CVS commit: src/sys/arch/powerpc

2021-03-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Mar 29 13:40:21 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: ibm4xx_autoconf.c
src/sys/arch/powerpc/include/ibm4xx: cpu.h

Log Message:
Set com(4) frequency in ibm4xx_device_register() in order to dedup codes.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/powerpc/ibm4xx/ibm4xx_autoconf.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/powerpc/include/ibm4xx/cpu.h

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/powerpc/ibm4xx/ibm4xx_autoconf.c
diff -u src/sys/arch/powerpc/ibm4xx/ibm4xx_autoconf.c:1.16 src/sys/arch/powerpc/ibm4xx/ibm4xx_autoconf.c:1.17
--- src/sys/arch/powerpc/ibm4xx/ibm4xx_autoconf.c:1.16	Mon Mar 29 13:17:53 2021
+++ src/sys/arch/powerpc/ibm4xx/ibm4xx_autoconf.c	Mon Mar 29 13:40:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ibm4xx_autoconf.c,v 1.16 2021/03/29 13:17:53 rin Exp $	*/
+/*	$NetBSD: ibm4xx_autoconf.c,v 1.17 2021/03/29 13:40:21 rin Exp $	*/
 /*	Original Tag: ibm4xxgpx_autoconf.c,v 1.2 2004/10/23 17:12:22 thorpej Exp $	*/
 
 /*
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ibm4xx_autoconf.c,v 1.16 2021/03/29 13:17:53 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibm4xx_autoconf.c,v 1.17 2021/03/29 13:40:21 rin Exp $");
 
 #include 
 #include 
@@ -45,6 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: ibm4xx_autoc
 #include 
 
 #include 
+#include 
 #include 
 
 void
@@ -55,10 +56,16 @@ cpu_rootconf(void)
 }
 
 void
-ibm4xx_device_register(device_t dev, void *aux)
+ibm4xx_device_register(device_t dev, void *aux, int com_freq)
 {
 	device_t parent = device_parent(dev);
 
+	if (device_is_a(dev, "com") && device_is_a(parent, "opb")) {
+		/* Set the frequency of the on-chip UART. */
+		com_opb_device_register(dev, com_freq);
+		return;
+	}
+
 	if (device_is_a(dev, "emac") && device_is_a(parent, "opb")) {
 		/* Set the mac-address of the on-chip Ethernet. */
 		struct opb_attach_args *oaa = aux;

Index: src/sys/arch/powerpc/include/ibm4xx/cpu.h
diff -u src/sys/arch/powerpc/include/ibm4xx/cpu.h:1.22 src/sys/arch/powerpc/include/ibm4xx/cpu.h:1.23
--- src/sys/arch/powerpc/include/ibm4xx/cpu.h:1.22	Thu Apr 19 21:50:07 2018
+++ src/sys/arch/powerpc/include/ibm4xx/cpu.h	Mon Mar 29 13:40:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.22 2018/04/19 21:50:07 christos Exp $	*/
+/*	$NetBSD: cpu.h,v 1.23 2021/03/29 13:40:21 rin Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -73,7 +73,7 @@ extern void ibm4xx_dumpsys(void);
 extern void ibm4xx_install_extint(void (*)(void));
 
 /* export from ibm4xx/ibm4xx_autoconf.c */
-extern void ibm4xx_device_register(device_t dev, void *aux);
+extern void ibm4xx_device_register(device_t, void *, int);
 
 /* export from ibm4xx/clock.c */
 extern void calc_delayconst(void);



CVS commit: src/sys/arch/powerpc/pic

2021-03-23 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Mar 23 08:07:23 UTC 2021

Modified Files:
src/sys/arch/powerpc/pic: intr.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/powerpc/pic/intr.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/powerpc/pic/intr.c
diff -u src/sys/arch/powerpc/pic/intr.c:1.32 src/sys/arch/powerpc/pic/intr.c:1.33
--- src/sys/arch/powerpc/pic/intr.c:1.32	Mon Mar 22 01:36:10 2021
+++ src/sys/arch/powerpc/pic/intr.c	Tue Mar 23 08:07:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.32 2021/03/22 01:36:10 rin Exp $ */
+/*	$NetBSD: intr.c,v 1.33 2021/03/23 08:07:23 skrll Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -29,7 +29,7 @@
 #define __INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.32 2021/03/22 01:36:10 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.33 2021/03/23 08:07:23 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_interrupt.h"
@@ -619,7 +619,8 @@ splraise(int ncpl)
 	struct cpu_info *ci = curcpu();
 	int ocpl;
 
-	if (ncpl == ci->ci_cpl) return ncpl;
+	if (ncpl == ci->ci_cpl)
+		return ncpl;
 	REORDER_PROTECT();
 	ocpl = ci->ci_cpl;
 	KASSERT(ncpl < NIPL);



CVS commit: src/sys/arch/powerpc/pic

2021-03-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Mar 22 01:36:10 UTC 2021

Modified Files:
src/sys/arch/powerpc/pic: intr.c picvar.h

Log Message:
Brush up previous, or make things more similar to x86:

- Prevent pic_name from appearing vmstat(1) twice.
- Restore "irq" in interrupt id fields of intrctl(8).

For these purposes,

- Add is_evname member to struct intr_source.
- Bump size of is_source to INTRIDBUF, and rename it to is_intrid for clarity.

Now, outputs from vmstat(1) and intrctl(8) are like:


$ vmstat -ev
...
openpic irq 39 3967   26 intr
...
$ intrctl list
interrupt id   CPU0  device name(s)
...
openpic irq 39 3967* wdc1
...



To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/powerpc/pic/intr.c
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/powerpc/pic/picvar.h

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/powerpc/pic/intr.c
diff -u src/sys/arch/powerpc/pic/intr.c:1.31 src/sys/arch/powerpc/pic/intr.c:1.32
--- src/sys/arch/powerpc/pic/intr.c:1.31	Sat Mar  6 07:24:24 2021
+++ src/sys/arch/powerpc/pic/intr.c	Mon Mar 22 01:36:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.31 2021/03/06 07:24:24 rin Exp $ */
+/*	$NetBSD: intr.c,v 1.32 2021/03/22 01:36:10 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -29,7 +29,7 @@
 #define __INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.31 2021/03/06 07:24:24 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.32 2021/03/22 01:36:10 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_interrupt.h"
@@ -200,10 +200,12 @@ intr_establish_xname(int hwirq, int type
 		break;
 	}
 	if (is->is_hand == NULL) {
-		snprintf(is->is_source, sizeof(is->is_source), "%s %d",
+		snprintf(is->is_intrid, sizeof(is->is_intrid), "%s irq %d",
 		pic->pic_name, is->is_hwirq);
+		snprintf(is->is_evname, sizeof(is->is_evname), "irq %d",
+		is->is_hwirq);
 		evcnt_attach_dynamic(>is_ev, EVCNT_TYPE_INTR, NULL,
-		pic->pic_name, is->is_source);
+		pic->pic_name, is->is_evname);
 	}
 
 	/*
@@ -744,7 +746,7 @@ intr_get_source(const char *intrid)
 	int irq;
 
 	for (irq = 0, is = intrsources; irq < NVIRQ; irq++, is++) {
-		if (strcmp(intrid, is->is_source) == 0)
+		if (strcmp(intrid, is->is_intrid) == 0)
 			return is;
 	}
 	return NULL;
@@ -858,7 +860,7 @@ interrupt_construct_intrids(const kcpuse
 		if (is->is_hand == NULL)
 			continue;
 
-		strncpy(ids[i], is->is_source, sizeof(intrid_t));
+		strncpy(ids[i], is->is_intrid, sizeof(intrid_t));
 		i++;
 	}
 

Index: src/sys/arch/powerpc/pic/picvar.h
diff -u src/sys/arch/powerpc/pic/picvar.h:1.12 src/sys/arch/powerpc/pic/picvar.h:1.13
--- src/sys/arch/powerpc/pic/picvar.h:1.12	Thu Apr 16 23:29:52 2020
+++ src/sys/arch/powerpc/pic/picvar.h	Mon Mar 22 01:36:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: picvar.h,v 1.12 2020/04/16 23:29:52 rin Exp $ */
+/*	$NetBSD: picvar.h,v 1.13 2021/03/22 01:36:10 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: picvar.h,v 1.12 2020/04/16 23:29:52 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: picvar.h,v 1.13 2021/03/22 01:36:10 rin Exp $");
 
 #ifndef PIC_VAR_H
 #define PIC_VAR_H
@@ -62,7 +62,8 @@ struct intr_source {
 	struct intrhand *is_hand;
 	struct pic_ops *is_pic;
 	struct evcnt is_ev;
-	char is_source[16];
+	char is_evname[16];
+	char is_intrid[INTRIDBUF];
 };
 
 #define OPENPIC_MAX_ISUS	4



CVS commit: src/sys/arch/powerpc/oea

2021-03-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Mar 21 23:41:52 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: cpu_subr.c

Log Message:
Fix copy-paste.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/arch/powerpc/oea/cpu_subr.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/powerpc/oea/cpu_subr.c
diff -u src/sys/arch/powerpc/oea/cpu_subr.c:1.107 src/sys/arch/powerpc/oea/cpu_subr.c:1.108
--- src/sys/arch/powerpc/oea/cpu_subr.c:1.107	Fri Feb 26 21:15:20 2021
+++ src/sys/arch/powerpc/oea/cpu_subr.c	Sun Mar 21 23:41:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu_subr.c,v 1.107 2021/02/26 21:15:20 thorpej Exp $	*/
+/*	$NetBSD: cpu_subr.c,v 1.108 2021/03/21 23:41:52 rin Exp $	*/
 
 /*-
  * Copyright (c) 2001 Matt Thomas.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.107 2021/02/26 21:15:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.108 2021/03/21 23:41:52 rin Exp $");
 
 #include "sysmon_envsys.h"
 
@@ -856,7 +856,7 @@ cpu_setup(device_t self, struct cpu_info
 	evcnt_attach_dynamic(>ci_ev_ali, EVCNT_TYPE_TRAP,
 		>ci_ev_traps, xname, "user alignment traps");
 	evcnt_attach_dynamic(>ci_ev_ali_fatal, EVCNT_TYPE_TRAP,
-		>ci_ev_ali, xname, "user alignment traps");
+		>ci_ev_ali, xname, "user alignment failures");
 	evcnt_attach_dynamic(>ci_ev_umchk, EVCNT_TYPE_TRAP,
 		>ci_ev_umchk, xname, "user MCHK failures");
 	evcnt_attach_dynamic(>ci_ev_vec, EVCNT_TYPE_TRAP,



CVS commit: src/sys/arch/powerpc/oea

2021-03-12 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Mar 12 18:10:00 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: pmap.c

Log Message:
Fix paste-o in last.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/arch/powerpc/oea/pmap.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/powerpc/oea/pmap.c
diff -u src/sys/arch/powerpc/oea/pmap.c:1.104 src/sys/arch/powerpc/oea/pmap.c:1.105
--- src/sys/arch/powerpc/oea/pmap.c:1.104	Fri Mar 12 04:57:42 2021
+++ src/sys/arch/powerpc/oea/pmap.c	Fri Mar 12 18:10:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.104 2021/03/12 04:57:42 thorpej Exp $	*/
+/*	$NetBSD: pmap.c,v 1.105 2021/03/12 18:10:00 thorpej Exp $	*/
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.104 2021/03/12 04:57:42 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.105 2021/03/12 18:10:00 thorpej Exp $");
 
 #define	PMAP_NOOPNAMES
 
@@ -3432,7 +3432,7 @@ pmap_bootstrap1(paddr_t kernelstart, pad
 #endif /* PMAP_OEA || PMAP_OEA64_BRIDGE */
 
 #if defined(PMAP_OEA) && defined(PPC_OEA601)
-	if ((MFPVR() >> 16) == MPC601)) {
+	if ((MFPVR() >> 16) == MPC601) {
 		for (i = 0; i < 16; i++) {
 			if (iosrtable[i] & SR601_T) {
 pmap_kernel()->pm_sr[i] = iosrtable[i];



CVS commit: src/sys/arch/powerpc

2021-03-11 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Mar 12 04:57:42 UTC 2021

Modified Files:
src/sys/arch/powerpc/include/oea: pmap.h
src/sys/arch/powerpc/oea: pmap.c

Log Message:
Re-factor the code in pmap_extract() that checks the 601 I/O segment
table and the BAT tables into separate functions that can be called
from outside of the pmap module.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/powerpc/include/oea/pmap.h
cvs rdiff -u -r1.103 -r1.104 src/sys/arch/powerpc/oea/pmap.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/powerpc/include/oea/pmap.h
diff -u src/sys/arch/powerpc/include/oea/pmap.h:1.34 src/sys/arch/powerpc/include/oea/pmap.h:1.35
--- src/sys/arch/powerpc/include/oea/pmap.h:1.34	Tue Mar  2 01:47:44 2021
+++ src/sys/arch/powerpc/include/oea/pmap.h	Fri Mar 12 04:57:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.34 2021/03/02 01:47:44 thorpej Exp $	*/
+/*	$NetBSD: pmap.h,v 1.35 2021/03/12 04:57:42 thorpej Exp $	*/
 
 /*-
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -158,6 +158,13 @@ int pmap_pte_spill(pmap_t, vaddr_t, bool
 int pmap_ste_spill(pmap_t, vaddr_t, bool);
 void pmap_pinit(pmap_t);
 
+#ifdef PPC_OEA601
+bool	pmap_extract_ioseg601(vaddr_t, paddr_t *);
+#endif /* PPC_OEA601 */
+#ifdef PPC_OEA
+bool	pmap_extract_battable(vaddr_t, paddr_t *);
+#endif /* PPC_OEA */
+
 u_int powerpc_mmap_flags(paddr_t);
 #define POWERPC_MMAP_FLAG_MASK	0xf
 #define POWERPC_MMAP_FLAG_PREFETCHABLE	0x1

Index: src/sys/arch/powerpc/oea/pmap.c
diff -u src/sys/arch/powerpc/oea/pmap.c:1.103 src/sys/arch/powerpc/oea/pmap.c:1.104
--- src/sys/arch/powerpc/oea/pmap.c:1.103	Thu Mar 11 04:43:47 2021
+++ src/sys/arch/powerpc/oea/pmap.c	Fri Mar 12 04:57:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.103 2021/03/11 04:43:47 thorpej Exp $	*/
+/*	$NetBSD: pmap.c,v 1.104 2021/03/12 04:57:42 thorpej Exp $	*/
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.103 2021/03/11 04:43:47 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.104 2021/03/12 04:57:42 thorpej Exp $");
 
 #define	PMAP_NOOPNAMES
 
@@ -2087,6 +2087,66 @@ pmap_remove(pmap_t pm, vaddr_t va, vaddr
 	PMAP_UNLOCK();
 }
 
+#if defined(PMAP_OEA)
+#ifdef PPC_OEA601
+bool
+pmap_extract_ioseg601(vaddr_t va, paddr_t *pap)
+{
+	if ((MFPVR() >> 16) != MPC601)
+		return false;
+
+	const register_t sr = iosrtable[va >> ADDR_SR_SHFT];
+
+	if (SR601_VALID_P(sr) && SR601_PA_MATCH_P(sr, va)) {
+		if (pap)
+			*pap = va;
+		return true;
+	}
+	return false;
+}
+
+static bool
+pmap_extract_battable601(vaddr_t va, paddr_t *pap)
+{
+	const register_t batu = battable[va >> 23].batu;
+	const register_t batl = battable[va >> 23].batl;
+
+	if (BAT601_VALID_P(batl) && BAT601_VA_MATCH_P(batu, batl, va)) {
+		const register_t mask =
+		(~(batl & BAT601_BSM) << 17) & ~0x1L;
+		if (pap)
+			*pap = (batl & mask) | (va & ~mask);
+		return true;
+	}
+	return false;
+}
+#endif /* PPC_OEA601 */
+
+bool
+pmap_extract_battable(vaddr_t va, paddr_t *pap)
+{
+#ifdef PPC_OEA601
+	if ((MFPVR() >> 16) == MPC601)
+		return pmap_extract_battable601(va, pap);
+#endif /* PPC_OEA601 */
+
+	if (oeacpufeat & OEACPU_NOBAT)
+		return false;
+
+	const register_t batu = battable[BAT_VA2IDX(va)].batu;
+
+	if (BAT_VALID_P(batu, 0) && BAT_VA_MATCH_P(batu, va)) {
+		const register_t batl = battable[BAT_VA2IDX(va)].batl;
+		const register_t mask =
+		(~(batu & (BAT_XBL|BAT_BL)) << 15) & ~0x1L;
+		if (pap)
+			*pap = (batl & mask) | (va & ~mask);
+		return true;
+	}
+	return false;
+}
+#endif /* PMAP_OEA */
+
 /*
  * Get the physical page address for the given pmap/virtual address.
  */
@@ -2099,63 +2159,42 @@ pmap_extract(pmap_t pm, vaddr_t va, padd
 	PMAP_LOCK();
 
 	/*
-	 * If this is a kernel pmap lookup, also check the battable
-	 * and if we get a hit, translate the VA to a PA using the
-	 * BAT entries.  Don't check for VM_MAX_KERNEL_ADDRESS is
-	 * that will wrap back to 0.
+	 * If this is the kernel pmap, check the battable and I/O
+	 * segments for a hit.  This is done only for regions outside
+	 * VM_MIN_KERNEL_ADDRESS-VM_MAX_KERNEL_ADDRESS.
+	 *
+	 * Be careful when checking VM_MAX_KERNEL_ADDRESS; you don't
+	 * want to wrap around to 0.
 	 */
 	if (pm == pmap_kernel() &&
 	(va < VM_MIN_KERNEL_ADDRESS ||
 	 (KERNEL2_SR < 15 && VM_MAX_KERNEL_ADDRESS <= va))) {
 		KASSERT((va >> ADDR_SR_SHFT) != USER_SR);
-#if defined (PMAP_OEA)
+#if defined(PMAP_OEA)
 #ifdef PPC_OEA601
-		if ((MFPVR() >> 16) == MPC601) {
-			register_t batu = battable[va >> 23].batu;
-			register_t batl = battable[va >> 23].batl;
-			register_t sr = iosrtable[va >> ADDR_SR_SHFT];
-			if (BAT601_VALID_P(batl) &&
-			BAT601_VA_MATCH_P(batu, batl, va)) {
-register_t mask =
-(~(batl & BAT601_BSM) << 17) & ~0x1L;
-if 

CVS commit: src/sys/arch/powerpc/include

2021-03-11 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Thu Mar 11 08:33:34 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: db_machdep.h

Log Message:
Use ifdef _KERNEL_OPT instead of ifdef _KERNEL before including
"opt_ppcarch.h".


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/powerpc/include/db_machdep.h

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/powerpc/include/db_machdep.h
diff -u src/sys/arch/powerpc/include/db_machdep.h:1.29 src/sys/arch/powerpc/include/db_machdep.h:1.30
--- src/sys/arch/powerpc/include/db_machdep.h:1.29	Wed Jan  6 08:14:34 2021
+++ src/sys/arch/powerpc/include/db_machdep.h	Thu Mar 11 08:33:34 2021
@@ -1,5 +1,5 @@
 /*	$OpenBSD: db_machdep.h,v 1.2 1997/03/21 00:48:48 niklas Exp $	*/
-/*	$NetBSD: db_machdep.h,v 1.29 2021/01/06 08:14:34 rin Exp $	*/
+/*	$NetBSD: db_machdep.h,v 1.30 2021/03/11 08:33:34 simonb Exp $	*/
 
 /* 
  * Mach Operating System
@@ -33,7 +33,7 @@
 #ifndef	_PPC_DB_MACHDEP_H_
 #define	_PPC_DB_MACHDEP_H_
 
-#ifdef _KERNEL
+#if defined(_KERNEL_OPT)
 #include "opt_ppcarch.h"
 #endif
 



CVS commit: src/sys/arch/powerpc/oea

2021-03-10 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Mar 11 04:43:47 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: pmap.c

Log Message:
Tidy up initialization of the kernel SRs just a bit.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/arch/powerpc/oea/pmap.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/powerpc/oea/pmap.c
diff -u src/sys/arch/powerpc/oea/pmap.c:1.102 src/sys/arch/powerpc/oea/pmap.c:1.103
--- src/sys/arch/powerpc/oea/pmap.c:1.102	Wed Mar 10 18:29:07 2021
+++ src/sys/arch/powerpc/oea/pmap.c	Thu Mar 11 04:43:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.102 2021/03/10 18:29:07 thorpej Exp $	*/
+/*	$NetBSD: pmap.c,v 1.103 2021/03/11 04:43:47 thorpej Exp $	*/
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.102 2021/03/10 18:29:07 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.103 2021/03/11 04:43:47 thorpej Exp $");
 
 #define	PMAP_NOOPNAMES
 
@@ -3378,17 +3378,10 @@ pmap_bootstrap1(paddr_t kernelstart, pad
 	pmap_vsid_bitmap[0] |= 1;
 
 	/*
-	 * Initialize kernel pmap and hardware.
+	 * Initialize kernel pmap.
 	 */
-
-/* PMAP_OEA64_BRIDGE does support these instructions */
-#if defined (PMAP_OEA) || defined (PMAP_OEA64_BRIDGE)
+#if defined(PMAP_OEA) || defined(PMAP_OEA64_BRIDGE)
 	for (i = 0; i < 16; i++) {
-#if defined(PPC_OEA601)
-	/* XXX wedges for segment register 0xf , so set later */
-	if ((iosrtable[i] & SR601_T) && ((MFPVR() >> 16) == MPC601))
-		continue;
-#endif
  		pmap_kernel()->pm_sr[i] = KERNELN_SEGMENT(i)|SR_PRKEY;
 	}
 	pmap_kernel()->pm_vsid = KERNEL_VSIDBITS;
@@ -3398,13 +3391,16 @@ pmap_bootstrap1(paddr_t kernelstart, pad
 	pmap_kernel()->pm_sr[KERNEL2_SR] = KERNEL2_SEGMENT|SR_SUKEY|SR_PRKEY;
 #endif
 #endif /* PMAP_OEA || PMAP_OEA64_BRIDGE */
-#if defined (PMAP_OEA)
-	for (i = 0; i < 16; i++) {
-		if (iosrtable[i] & SR601_T) {
-			pmap_kernel()->pm_sr[i] = iosrtable[i];
+
+#if defined(PMAP_OEA) && defined(PPC_OEA601)
+	if ((MFPVR() >> 16) == MPC601)) {
+		for (i = 0; i < 16; i++) {
+			if (iosrtable[i] & SR601_T) {
+pmap_kernel()->pm_sr[i] = iosrtable[i];
+			}
 		}
 	}
-#endif
+#endif /* PMAP_OEA && PPC_OEA601 */
 
 #ifdef ALTIVEC
 	pmap_use_altivec = cpu_altivec;
@@ -3500,9 +3496,9 @@ pmap_bootstrap1(paddr_t kernelstart, pad
 			pmap_pte_create(, pm, va, pa | PTE_M|PTE_BW);
 			pmap_pte_insert(ptegidx, );
 		}
-#endif
+#endif /* PMAP_NEED_FULL_MAPKERNEL */
 	}
-#endif
+#endif /* PMAP_NEED_MAPKERNEL */
 }
 
 /*
@@ -3512,23 +3508,18 @@ pmap_bootstrap1(paddr_t kernelstart, pad
 void
 pmap_bootstrap2(void)
 {
-/* PMAP_OEA64_BRIDGE does support these instructions */
-#if defined (PMAP_OEA) || defined (PMAP_OEA64_BRIDGE)
+#if defined(PMAP_OEA) || defined(PMAP_OEA64_BRIDGE)
 	for (int i = 0; i < 16; i++) {
-#if defined(PPC_OEA601)
-		/* XXX wedges for segment register 0xf , so set later */
-		if ((iosrtable[i] & SR601_T) && ((MFPVR() >> 16) == MPC601))
-			continue;
-#endif /* PPC_OEA601 */
 		__asm volatile("mtsrin %0,%1"
 			:: "r"(pmap_kernel()->pm_sr[i]),
 			   "r"(i << ADDR_SR_SHFT));
 	}
 #endif /* PMAP_OEA || PMAP_OEA64_BRIDGE */
-#if defined (PMAP_OEA)
+
+#if defined(PMAP_OEA)
 	 __asm volatile("sync; mtsdr1 %0; isync"
 		:: "r"((uintptr_t)pmap_pteg_table | (pmap_pteg_mask >> 10)));
-#elif defined (PMAP_OEA64) || defined (PMAP_OEA64_BRIDGE)
+#elif defined(PMAP_OEA64) || defined(PMAP_OEA64_BRIDGE)
 	__asm __volatile("sync; mtsdr1 %0; isync"
 		:: "r"((uintptr_t)pmap_pteg_table |
 		   (32 - __builtin_clz(pmap_pteg_mask >> 11;
@@ -3536,7 +3527,7 @@ pmap_bootstrap2(void)
 	tlbia();
 
 #if defined(PMAPDEBUG)
-	if ( pmapdebug )
+	if (pmapdebug)
 	pmap_print_mmuregs();
 #endif
 }



CVS commit: src/sys/arch/powerpc/oea

2021-03-10 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Mar 10 18:29:07 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: pmap.c

Log Message:
- In pmap_bootstrap1(), make sure to initialize pmap_kernel()->pm_vsid
  with the kernel's base VSID.
- In va_to_vsid(), always compute the VSID from the base VSID in the
  pmap and the effective segment ID (ESID), rather than extracting it
  from the pmap's segment register value for that ESID.  Not only does
  this make the code the same between OEA and OEA64, but is also lets
  us compute the correct VSID for that pmap/ESID even if the cached SR
  for that ESID currently contains something else, such as an I/O segment
  mapping (as might be the case on a 601).

With this change, we can temporarily toggle between an I/O segment and
and HTAB-mapped segment if needed (e.g. when calling OpenFirmware on
a 601-based system).


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/arch/powerpc/oea/pmap.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/powerpc/oea/pmap.c
diff -u src/sys/arch/powerpc/oea/pmap.c:1.101 src/sys/arch/powerpc/oea/pmap.c:1.102
--- src/sys/arch/powerpc/oea/pmap.c:1.101	Tue Mar  2 01:47:44 2021
+++ src/sys/arch/powerpc/oea/pmap.c	Wed Mar 10 18:29:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.101 2021/03/02 01:47:44 thorpej Exp $	*/
+/*	$NetBSD: pmap.c,v 1.102 2021/03/10 18:29:07 thorpej Exp $	*/
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.101 2021/03/02 01:47:44 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.102 2021/03/10 18:29:07 thorpej Exp $");
 
 #define	PMAP_NOOPNAMES
 
@@ -595,45 +595,17 @@ tlbia(void)
 static inline register_t
 va_to_vsid(const struct pmap *pm, vaddr_t addr)
 {
-#if defined (PMAP_OEA) || defined (PMAP_OEA64_BRIDGE)
-	return (pm->pm_sr[addr >> ADDR_SR_SHFT] & SR_VSID) >> SR_VSID_SHFT;
-#else /* PMAP_OEA64 */
-#if 0
-	const struct ste *ste;
-	register_t hash;
-	int i;
-
-	hash = (addr >> ADDR_ESID_SHFT) & ADDR_ESID_HASH;
-
-	/*
-	 * Try the primary group first
-	 */
-	ste = pm->pm_stes[hash].stes;
-	for (i = 0; i < 8; i++, ste++) {
-		if (ste->ste_hi & STE_V) &&
-		   (addr & ~(ADDR_POFF|ADDR_PIDX)) == (ste->ste_hi & STE_ESID))
-			return ste;
-	}
-
 	/*
-	 * Then the secondary group.
-	 */
-	ste = pm->pm_stes[hash ^ ADDR_ESID_HASH].stes;
-	for (i = 0; i < 8; i++, ste++) {
-		if (ste->ste_hi & STE_V) &&
-		   (addr & ~(ADDR_POFF|ADDR_PIDX)) == (ste->ste_hi & STE_ESID))
-			return addr;
-	}
-		
-	return NULL;
-#else
-	/*
-	 * Rather than searching the STE groups for the VSID, we know
-	 * how we generate that from the ESID and so do that.
+	 * Rather than searching the STE groups for the VSID or extracting
+	 * it from the SR, we know how we generate that from the ESID and
+	 * so do that.
+	 *
+	 * This makes the code the same for OEA and OEA64, and also allows
+	 * us to generate a correct-for-that-address-space VSID even if the
+	 * pmap contains a different SR value at any given moment (e.g.
+	 * kernel pmap on a 601 that is using I/O segments).
 	 */
 	return VSID_MAKE(addr >> ADDR_SR_SHFT, pm->pm_vsid) >> SR_VSID_SHFT;
-#endif
-#endif /* PMAP_OEA */
 }
 
 static inline register_t
@@ -3419,6 +3391,7 @@ pmap_bootstrap1(paddr_t kernelstart, pad
 #endif
  		pmap_kernel()->pm_sr[i] = KERNELN_SEGMENT(i)|SR_PRKEY;
 	}
+	pmap_kernel()->pm_vsid = KERNEL_VSIDBITS;
 
 	pmap_kernel()->pm_sr[KERNEL_SR] = KERNEL_SEGMENT|SR_SUKEY|SR_PRKEY;
 #ifdef KERNEL2_SR



CVS commit: src/sys/arch/powerpc/include

2021-03-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Mar  7 14:42:53 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: cpu.h

Log Message:
For LP64, remove members of struct cpu_info that exist just for
compatible with booke or ibm4xx. Even if MODULAR || _MODULE,
these members are useless for powerpc64.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/sys/arch/powerpc/include/cpu.h

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/powerpc/include/cpu.h
diff -u src/sys/arch/powerpc/include/cpu.h:1.117 src/sys/arch/powerpc/include/cpu.h:1.118
--- src/sys/arch/powerpc/include/cpu.h:1.117	Wed Feb 24 16:42:38 2021
+++ src/sys/arch/powerpc/include/cpu.h	Sun Mar  7 14:42:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.117 2021/02/24 16:42:38 thorpej Exp $	*/
+/*	$NetBSD: cpu.h,v 1.118 2021/03/07 14:42:53 rin Exp $	*/
 
 /*
  * Copyright (C) 1999 Wolfgang Solfrank.
@@ -118,18 +118,20 @@ struct cpu_info {
 	volatile uint32_t ci_pending_ipis;
 	int ci_mtx_oldspl;
 	int ci_mtx_count;
-#if defined(PPC_IBM4XX) || defined(MODULAR) || defined(_MODULE)
+#if defined(PPC_IBM4XX) || \
+((defined(MODULAR) || defined(_MODULE)) && !defined(_LP64))
 	char *ci_intstk;
 #endif
 
 	register_t ci_savearea[CPUSAVE_SIZE];
-#if defined(PPC_BOOKE) || defined(MODULAR) || defined(_MODULE)
+#if defined(PPC_BOOKE) || \
+((defined(MODULAR) || defined(_MODULE)) && !defined(_LP64))
 	uint32_t ci_pmap_asid_cur;
 	union pmap_segtab *ci_pmap_segtabs[2];
 #define	ci_pmap_kern_segtab	ci_pmap_segtabs[0]
 #define	ci_pmap_user_segtab	ci_pmap_segtabs[1]
 	struct pmap_tlb_info *ci_tlb_info;
-#endif /* PPC_BOOKE || MODULAR || _MODULE */
+#endif /* PPC_BOOKE || ((MODULAR || _MODULE) && !_LP64) */
 	struct cache_info ci_ci;		
 	void *ci_sysmon_cookie;
 	void (*ci_idlespin)(void);



CVS commit: src/sys/arch/powerpc/include

2021-03-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Mar  7 14:31:53 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: proc.h

Log Message:
For _LP64, disable members of struct mdproc just for compatible with
booke and ibm4xx, even if MODULAR or _MODULE is defined.

Fix build failure for evbppc64 due to CTASSERT in COND_SET_STRUCT,
which restricts sizeof(struct mdproc) < 31 for unknown reason...


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/powerpc/include/proc.h

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/powerpc/include/proc.h
diff -u src/sys/arch/powerpc/include/proc.h:1.14 src/sys/arch/powerpc/include/proc.h:1.15
--- src/sys/arch/powerpc/include/proc.h:1.14	Sat Mar  6 08:08:19 2021
+++ src/sys/arch/powerpc/include/proc.h	Sun Mar  7 14:31:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: proc.h,v 1.14 2021/03/06 08:08:19 rin Exp $	*/
+/*	$NetBSD: proc.h,v 1.15 2021/03/07 14:31:53 rin Exp $	*/
 
 /*-
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -53,7 +53,7 @@ struct trapframe;
 struct mdproc {
 	void (*md_syscall)(struct trapframe *);
 #if defined(PPC_BOOKE) || defined(PPC_IBM4XX) || \
-defined(MODULAR) || defined(_MODULE)
+((defined(MODULAR) || defined(_MODULE)) && !defined(_LP64))
 	vaddr_t md_ss_addr[2];
 	uint32_t md_ss_insn[2];
 #endif



CVS commit: src/sys/arch/powerpc/ibm4xx/openbios

2021-03-06 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Sun Mar  7 02:54:07 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx/openbios: locore.S

Log Message:
Remove unused/unreferenced legacy intrcnt/intrnames.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/powerpc/ibm4xx/openbios/locore.S

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/powerpc/ibm4xx/openbios/locore.S
diff -u src/sys/arch/powerpc/ibm4xx/openbios/locore.S:1.15 src/sys/arch/powerpc/ibm4xx/openbios/locore.S:1.16
--- src/sys/arch/powerpc/ibm4xx/openbios/locore.S:1.15	Mon Jul  6 10:48:54 2020
+++ src/sys/arch/powerpc/ibm4xx/openbios/locore.S	Sun Mar  7 02:54:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.15 2020/07/06 10:48:54 rin Exp $	*/
+/*	$NetBSD: locore.S,v 1.16 2021/03/07 02:54:06 simonb Exp $	*/
 /*	$OpenBSD: locore.S,v 1.4 1997/01/26 09:06:38 rahnds Exp $	*/
 
 /*
@@ -100,27 +100,6 @@
 #define	bdneq	bdnzf 2,
 
 /*
- * Globals
- */
-GLOBAL(intrnames)
-	.asciz	"clock", "irq1", "irq2", "irq3"
-	.asciz	"irq4", "irq5", "irq6", "irq7"
-	.asciz	"irq8", "irq9", "irq10", "irq11"
-	.asciz	"irq12", "irq13", "irq14", "irq15"
-	.asciz	"irq16", "irq17", "irq18", "irq19"
-	.asciz	"irq20", "irq21", "irq22", "irq23"
-	.asciz	"irq24", "irq25", "irq26", "irq27"
-	.asciz	"irq28", "softnet", "softclock", "softserial"
-	.asciz  "statclock"
-GLOBAL(eintrnames)
-	.align	4
-GLOBAL(intrcnt)
-	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-	.long	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-	.long	0
-GLOBAL(eintrcnt)
-
-/*
  * This symbol is here for the benefit of kvm_mkdb, and is supposed to
  * mark the start of kernel text.
  */



CVS commit: src/sys/arch/powerpc/powerpc

2021-03-06 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Mar  6 08:34:58 UTC 2021

Modified Files:
src/sys/arch/powerpc/powerpc: locore_subr.S

Log Message:
For ibm4xx and booke, restore saved PSL_EE bit as done for oea,
instead of forcibly enabling interrupts.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/powerpc/powerpc/locore_subr.S

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/powerpc/powerpc/locore_subr.S
diff -u src/sys/arch/powerpc/powerpc/locore_subr.S:1.64 src/sys/arch/powerpc/powerpc/locore_subr.S:1.65
--- src/sys/arch/powerpc/powerpc/locore_subr.S:1.64	Sat Mar  6 08:08:19 2021
+++ src/sys/arch/powerpc/powerpc/locore_subr.S	Sat Mar  6 08:34:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore_subr.S,v 1.64 2021/03/06 08:08:19 rin Exp $	*/
+/*	$NetBSD: locore_subr.S,v 1.65 2021/03/06 08:34:58 rin Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -401,7 +401,7 @@ _ENTRY(softint_fast_dispatch)
 	addi	%r1, %r5, USPACE - FRAMELEN - CALLFRAMELEN
 
 #if defined(PPC_IBM4XX) || defined(PPC_BOOKE)
-	wrteei	1			/* interrupts are okay again */
+	wrtee	%r29			/* interrupts are okay again */
 #else /* PPC_OEA */
 	mtmsr	%r29
 #endif



CVS commit: src/sys/arch/powerpc/powerpc

2021-03-06 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Mar  6 08:32:17 UTC 2021

Modified Files:
src/sys/arch/powerpc/powerpc: powerpc_machdep.c

Log Message:
Convert to KASSERTMSG(9) to display wrong IPL.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/sys/arch/powerpc/powerpc/powerpc_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/powerpc/powerpc/powerpc_machdep.c
diff -u src/sys/arch/powerpc/powerpc/powerpc_machdep.c:1.81 src/sys/arch/powerpc/powerpc/powerpc_machdep.c:1.82
--- src/sys/arch/powerpc/powerpc/powerpc_machdep.c:1.81	Sat Mar  6 08:08:19 2021
+++ src/sys/arch/powerpc/powerpc/powerpc_machdep.c	Sat Mar  6 08:32:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: powerpc_machdep.c,v 1.81 2021/03/06 08:08:19 rin Exp $	*/
+/*	$NetBSD: powerpc_machdep.c,v 1.82 2021/03/06 08:32:17 rin Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: powerpc_machdep.c,v 1.81 2021/03/06 08:08:19 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: powerpc_machdep.c,v 1.82 2021/03/06 08:32:17 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altivec.h"
@@ -381,7 +381,8 @@ void
 cpu_idle(void)
 {
 	KASSERT(mfmsr() & PSL_EE);
-	KASSERT(curcpu()->ci_cpl == IPL_NONE);
+	KASSERTMSG(curcpu()->ci_cpl == IPL_NONE,
+	"ci_cpl = %d", curcpu()->ci_cpl);
 	(*curcpu()->ci_idlespin)();
 }
 



CVS commit: src/sys/arch/powerpc

2021-03-06 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Mar  6 08:08:19 UTC 2021

Modified Files:
src/sys/arch/powerpc/booke: trap.c
src/sys/arch/powerpc/ibm4xx: ibm4xx_machdep.c trap.c
src/sys/arch/powerpc/include: proc.h psl.h ptrace.h
src/sys/arch/powerpc/powerpc: locore_subr.S powerpc_machdep.c
process_machdep.c

Log Message:
For booke and ibm4xx, switch to software-based single-stepping for PT_STEP
ptrace(2) command from broken hardware-based implementation.

As described in proposal on port-powerpc@,

http://mail-index.netbsd.org/port-powerpc/2021/02/26/msg003597.html

hardware debug facilities of booke and 4xx use critical interrupts, that
are difficult to handle for this purpose; they are not automatically masked
when entering kernel mode via system call trap or hardware interrupt.
See my proposal above for more details.

Now, hardware debug facilities are exclusively usable by kernel itself.
They are much more functional than PSL_SE MSR bit of oea, and should be
useful to, e.g., support byte-granular watchpoint for DDB in the future.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/arch/powerpc/booke/trap.c
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c
cvs rdiff -u -r1.85 -r1.86 src/sys/arch/powerpc/ibm4xx/trap.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/powerpc/include/proc.h
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/powerpc/include/psl.h
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/powerpc/include/ptrace.h
cvs rdiff -u -r1.63 -r1.64 src/sys/arch/powerpc/powerpc/locore_subr.S
cvs rdiff -u -r1.80 -r1.81 src/sys/arch/powerpc/powerpc/powerpc_machdep.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/powerpc/powerpc/process_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/powerpc/booke/trap.c
diff -u src/sys/arch/powerpc/booke/trap.c:1.36 src/sys/arch/powerpc/booke/trap.c:1.37
--- src/sys/arch/powerpc/booke/trap.c:1.36	Wed Jan  6 08:04:57 2021
+++ src/sys/arch/powerpc/booke/trap.c	Sat Mar  6 08:08:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.36 2021/01/06 08:04:57 rin Exp $	*/
+/*	$NetBSD: trap.c,v 1.37 2021/03/06 08:08:19 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.36 2021/01/06 08:04:57 rin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.37 2021/03/06 08:08:19 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altivec.h"
@@ -47,6 +47,7 @@ __KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.3
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -461,11 +462,31 @@ pgm_exception(struct trapframe *tf, ksig
 
 	ci->ci_ev_pgm.ev_count++;
 
+	KSI_INIT_TRAP(ksi);
+
 	if (tf->tf_esr & ESR_PTR) {
-		struct proc *p = curlwp->l_proc;
-		if (p->p_raslist != NULL
-		&& ras_lookup(p, (void *)tf->tf_srr0) != (void *) -1) {
-			tf->tf_srr0 += 4;
+		struct lwp * const l = curlwp;
+		struct proc * const p = curlwp->l_proc;
+		vaddr_t va = (vaddr_t)tf->tf_srr0;
+		int error;
+
+		/*
+		 * Restore original instruction and clear BP.
+		 */
+		if (p->p_md.md_ss_addr[0] == va ||
+		p->p_md.md_ss_addr[1] == va) {
+			error = ppc_sstep(l, 0);
+			if (error != 0) {
+vm_signal(error, EXC_PGM /* XXX */, va, ksi);
+return error;
+			}
+			ksi->ksi_code = TRAP_TRACE;
+		} else
+			ksi->ksi_code = TRAP_BRKPT;
+
+		if (p->p_raslist != NULL &&
+		ras_lookup(p, (void *)va) != (void *)-1) {
+			tf->tf_srr0 += (ksi->ksi_code == TRAP_TRACE) ? 0 : 4;
 			return 0;
 		}
 	}
@@ -494,7 +515,6 @@ pgm_exception(struct trapframe *tf, ksig
 		}
 	}
 
-	KSI_INIT_TRAP(ksi);
 	ksi->ksi_signo = SIGILL;
 	ksi->ksi_trap = EXC_PGM;
 	if (tf->tf_esr & ESR_PIL) {
@@ -503,7 +523,6 @@ pgm_exception(struct trapframe *tf, ksig
 		ksi->ksi_code = ILL_PRVOPC;
 	} else if (tf->tf_esr & ESR_PTR) {
 		ksi->ksi_signo = SIGTRAP;
-		ksi->ksi_code = TRAP_BRKPT;
 	} else {
 		ksi->ksi_code = 0;
 	}
@@ -511,6 +530,7 @@ pgm_exception(struct trapframe *tf, ksig
 	return rv;
 }
 
+#if 0
 static int
 debug_exception(struct trapframe *tf, ksiginfo_t *ksi)
 {
@@ -545,6 +565,7 @@ debug_exception(struct trapframe *tf, ks
 	ksi->ksi_code = TRAP_TRACE;
 	return rv;
 }
+#endif
 
 static int
 ali_exception(struct trapframe *tf, ksiginfo_t *ksi)
@@ -752,6 +773,7 @@ trap(enum ppc_booke_exceptions trap_code
 	switch (trap_code) {
 	case T_CRITIAL_INPUT:
 	case T_EXTERNAL_INPUT:
+	case T_DEBUG:
 	case T_DECREMENTER:
 	case T_FIXED_INTERVAL:
 	case T_WATCHDOG:
@@ -791,6 +813,7 @@ trap(enum ppc_booke_exceptions trap_code
 	case T_INSTRUCTION_TLB_ERROR:
 		rv = itlb_exception(tf, );
 		break;
+#if 0
 	case T_DEBUG:
 #ifdef DDB
 		if (!usertrap && ddb_exception(tf))
@@ -798,6 +821,7 @@ trap(enum ppc_booke_exceptions trap_code
 #endif
 		rv = debug_exception(tf, );
 		break;
+#endif
 	case T_EMBEDDED_FP_DATA:
 		rv = 

CVS commit: src/sys/arch/powerpc/pic

2021-03-05 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Mar  6 07:24:25 UTC 2021

Modified Files:
src/sys/arch/powerpc/pic: intr.c

Log Message:
Include PIC name to interrupt source, instead of just "irq", so that
it appears in "interrupt id" field of intrctl(8).

Should be useful when multiple PICs are simultaneously available as in
405EX (where uic[12] are cascaded to uic0).


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/powerpc/pic/intr.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/powerpc/pic/intr.c
diff -u src/sys/arch/powerpc/pic/intr.c:1.30 src/sys/arch/powerpc/pic/intr.c:1.31
--- src/sys/arch/powerpc/pic/intr.c:1.30	Tue Mar  2 07:37:27 2021
+++ src/sys/arch/powerpc/pic/intr.c	Sat Mar  6 07:24:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.30 2021/03/02 07:37:27 rin Exp $ */
+/*	$NetBSD: intr.c,v 1.31 2021/03/06 07:24:24 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -29,7 +29,7 @@
 #define __INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.30 2021/03/02 07:37:27 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.31 2021/03/06 07:24:24 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_interrupt.h"
@@ -200,8 +200,8 @@ intr_establish_xname(int hwirq, int type
 		break;
 	}
 	if (is->is_hand == NULL) {
-		snprintf(is->is_source, sizeof(is->is_source), "irq %d",
-		is->is_hwirq);
+		snprintf(is->is_source, sizeof(is->is_source), "%s %d",
+		pic->pic_name, is->is_hwirq);
 		evcnt_attach_dynamic(>is_ev, EVCNT_TYPE_INTR, NULL,
 		pic->pic_name, is->is_source);
 	}



CVS commit: src/sys/arch/powerpc

2021-03-05 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Mar  5 18:10:07 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: ofw_cons.h
src/sys/arch/powerpc/oea: ofw_consinit.c ofwoea_machdep.c

Log Message:
Separate probing for the console device and initializing it, so that
ofwoea_initppc() can have more control over which of those steps are
performed during initialization.  Probing happens before setting up
the exception vectors, initializing happens after.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/powerpc/include/ofw_cons.h
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/powerpc/oea/ofw_consinit.c
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/powerpc/oea/ofwoea_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/powerpc/include/ofw_cons.h
diff -u src/sys/arch/powerpc/include/ofw_cons.h:1.2 src/sys/arch/powerpc/include/ofw_cons.h:1.3
--- src/sys/arch/powerpc/include/ofw_cons.h:1.2	Wed Oct 17 19:56:41 2007
+++ src/sys/arch/powerpc/include/ofw_cons.h	Fri Mar  5 18:10:06 2021
@@ -1,9 +1,10 @@
-/* $NetBSD: ofw_cons.h,v 1.2 2007/10/17 19:56:41 garbled Exp $ */
+/* $NetBSD: ofw_cons.h,v 1.3 2021/03/05 18:10:06 thorpej Exp $ */
 
 #ifndef _POWERPC_OFW_CONS_H_
 #define _POWERPC_OFW_CONS_H_
 
-void ofwoea_consinit(void);
-int ofkbd_cngetc(dev_t dev);
+void	ofwoea_cnprobe(void);
+void	ofwoea_consinit(void);
+int	ofkbd_cngetc(dev_t dev);
 
 #endif /* _POWERPC_OFW_CONS_H_ */

Index: src/sys/arch/powerpc/oea/ofw_consinit.c
diff -u src/sys/arch/powerpc/oea/ofw_consinit.c:1.23 src/sys/arch/powerpc/oea/ofw_consinit.c:1.24
--- src/sys/arch/powerpc/oea/ofw_consinit.c:1.23	Fri Feb 19 18:05:42 2021
+++ src/sys/arch/powerpc/oea/ofw_consinit.c	Fri Mar  5 18:10:06 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_consinit.c,v 1.23 2021/02/19 18:05:42 thorpej Exp $ */
+/* $NetBSD: ofw_consinit.c,v 1.24 2021/03/05 18:10:06 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.23 2021/02/19 18:05:42 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.24 2021/03/05 18:10:06 thorpej Exp $");
 
 #include "adb.h"
 #include "adbkbd.h"
@@ -91,9 +91,9 @@ extern struct consdev consdev_zs;
 
 extern int console_node, console_instance;
 
-int ofkbd_ihandle;
+int ofkbd_ihandle = -1;
 
-static void cninit_kd(void);
+static void ofwoea_cnprobe_keyboard(void);
 
 /*#define OFDEBUG*/
 
@@ -117,39 +117,51 @@ void ofprint(const char *blah, ...)
 #define OFPRINTF while(0) printf
 #endif
 
+static bool use_serial_console;
+static struct consdev *selected_serial_consdev;
+
+static int (*selected_keyboard)(void);
+
+/* XXX Gross. */
+#if NPCKBC > 0
+static int
+ofwoea_pckbd_cnattach(void)
+{
+	return pckbc_cnattach(_isa_io_space_tag, IO_KBD, KBCMDP,
+	PCKBC_KBD_SLOT, 0);
+}
+#endif
+
 void
-cninit(void)
+ofwoea_cnprobe(void)
 {
 	char name[32];
 
 	OFPRINTF("console node: %08x\n", console_node);
 
 	if (console_node == -1)
-		goto nocons;
+		return;
 
 	memset(name, 0, sizeof(name));
 	if (OF_getprop(console_node, "device_type", name, sizeof(name)) == -1)
-		goto nocons;
+		return;
 
 	OFPRINTF("console type: %s\n", name);
 
 	if (strcmp(name, "serial") == 0) {
+		use_serial_console = true;
 #ifdef PMAC_G5
 		/* The MMU hasn't been initialized yet, use failsafe for now */
 		extern struct consdev failsafe_cons;
-		cn_tab = _cons;
-		(*cn_tab->cn_probe)(cn_tab);
-		(*cn_tab->cn_init)(cn_tab);
-		aprint_verbose("Early G5 console initialized\n");
+		selected_serial_consdev = _cons;
+		aprint_verbose("Early G5 console selected\n");
 		return;
 #endif /* PMAC_G5 */
 
 #if (NZSTTY > 0) && !defined(MAMBO)
 		OF_getprop(console_node, "name", name, sizeof(name));
 		if (strcmp(name, "ch-a") == 0 || strcmp(name, "ch-b") == 0) {
-			cn_tab = _zs;
-			(*cn_tab->cn_probe)(cn_tab);
-			(*cn_tab->cn_init)(cn_tab);
+			selected_serial_consdev = _zs;
 		}
 		return;
 #endif /* NZTTY */
@@ -157,17 +169,24 @@ cninit(void)
 		/* fallback to OFW boot console (already set) */
 		return;
 	}
-	else
-		cninit_kd();
-nocons:
-	return;
-}
 
+	/*
+	 * We're going to use a display console.  Probe for the keyboard
+	 * we'll use.
+	 */
+	ofwoea_cnprobe_keyboard();
+}
 
+/*
+ * XXX This routine is a complete disaster, filled with platform-specific
+ * XXX stuff.  Fix, plz.
+ */
 static void
-cninit_kd(void)
+ofwoea_cnprobe_keyboard(void)
 {
-	int kstdin, node;
+	extern int ofw_stdin;
+
+	int node, kstdin = ofw_stdin;
 	char name[16];
 #if (NAKBD > 0) || (NADBKBD > 0)
 	int akbd;
@@ -178,22 +197,8 @@ cninit_kd(void)
 #endif
 
 	/*
-	 * Attach the console output now (so we can see debugging messages,
-	 * if any).
-	 */
-#if NWSDISPLAY > 0
-	rascons_cnattach();
-#endif
-
-	/*
 	 * We must determine which keyboard type we have.
 	 */
-	if (OF_getprop(ofw_chosen, "stdin", , sizeof(kstdin))
-	!= sizeof(kstdin)) {
-		

CVS commit: src/sys/arch/powerpc/pic

2021-03-04 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Mar  5 07:16:33 UTC 2021

Modified Files:
src/sys/arch/powerpc/pic: ipi_openpic.c

Log Message:
Convert to intr_establish_xname().


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/powerpc/pic/ipi_openpic.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/powerpc/pic/ipi_openpic.c
diff -u src/sys/arch/powerpc/pic/ipi_openpic.c:1.9 src/sys/arch/powerpc/pic/ipi_openpic.c:1.10
--- src/sys/arch/powerpc/pic/ipi_openpic.c:1.9	Mon Jul  6 09:34:18 2020
+++ src/sys/arch/powerpc/pic/ipi_openpic.c	Fri Mar  5 07:16:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ipi_openpic.c,v 1.9 2020/07/06 09:34:18 rin Exp $ */
+/* $NetBSD: ipi_openpic.c,v 1.10 2021/03/05 07:16:33 rin Exp $ */
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipi_openpic.c,v 1.9 2020/07/06 09:34:18 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipi_openpic.c,v 1.10 2021/03/05 07:16:33 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_multiprocessor.h"
@@ -106,7 +106,8 @@ openpic_send_ipi(cpuid_t target, uint32_
 static void
 openpic_establish_ipi(int type, int level, void *ih_args)
 {
-	intr_establish(ipiops.ppc_ipi_vector, type, level, ipi_intr, ih_args);
+	intr_establish_xname(ipiops.ppc_ipi_vector, type, level, ipi_intr,
+	ih_args, "openpic ipi");
 }
 
 #endif /*MULTIPROCESSOR*/



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-03-04 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Mar  5 07:11:24 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: cpu.c

Log Message:
Show PVR as 8-digit hex.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/powerpc/ibm4xx/cpu.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/powerpc/ibm4xx/cpu.c
diff -u src/sys/arch/powerpc/ibm4xx/cpu.c:1.35 src/sys/arch/powerpc/ibm4xx/cpu.c:1.36
--- src/sys/arch/powerpc/ibm4xx/cpu.c:1.35	Fri Mar  5 07:10:27 2021
+++ src/sys/arch/powerpc/ibm4xx/cpu.c	Fri Mar  5 07:11:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.35 2021/03/05 07:10:27 rin Exp $	*/
+/*	$NetBSD: cpu.c,v 1.36 2021/03/05 07:11:24 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.35 2021/03/05 07:10:27 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.36 2021/03/05 07:11:24 rin Exp $");
 
 #include 
 #include 
@@ -292,7 +292,7 @@ cpuattach(device_t parent, device_t self
 	if (__predict_false(cp->name == NULL))
 		cpu_setmodel("Version 0x%x", pvr);
 
-	aprint_normal(": %uMHz %s (PVR 0x%x)\n",
+	aprint_normal(": %uMHz %s (PVR 0x%08x)\n",
 	(processor_freq + 50) / 100,
 	(cp->name != NULL ? cpu_getmodel() : "unknown model"),
 	pvr);



CVS commit: src/sys/arch/powerpc

2021-03-04 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Mar  5 07:10:27 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: cpu.c
src/sys/arch/powerpc/include/ibm4xx: spr.h

Log Message:
Add 403 family processors other than 403GCX.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/powerpc/ibm4xx/cpu.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/powerpc/include/ibm4xx/spr.h

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/powerpc/ibm4xx/cpu.c
diff -u src/sys/arch/powerpc/ibm4xx/cpu.c:1.34 src/sys/arch/powerpc/ibm4xx/cpu.c:1.35
--- src/sys/arch/powerpc/ibm4xx/cpu.c:1.34	Thu Mar  5 01:21:09 2020
+++ src/sys/arch/powerpc/ibm4xx/cpu.c	Fri Mar  5 07:10:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.34 2020/03/05 01:21:09 rin Exp $	*/
+/*	$NetBSD: cpu.c,v 1.35 2021/03/05 07:10:27 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.34 2020/03/05 01:21:09 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.35 2021/03/05 07:10:27 rin Exp $");
 
 #include 
 #include 
@@ -130,9 +130,39 @@ static const struct cputab models[] = {
 			.icache_line_size = 16,
 		}
 	}, {
-		.version = PVR_403, 
-		.mask = 0x,
-		.name = "403",
+		.version = PVR_403GA,	/* XXX no MMU */
+		.mask = 0xff00,
+		.name = "403GA",
+		.ci = {
+			.dcache_size = 1024,
+			.dcache_line_size = 16,
+			.icache_size = 2048,
+			.icache_line_size = 16,
+		}
+	}, {
+		.version = PVR_403GB,	/* XXX no MMU */
+		.mask = 0xff00,
+		.name = "403GB",
+		.ci = {
+			.dcache_size = 1024,
+			.dcache_line_size = 16,
+			.icache_size = 2048,
+			.icache_line_size = 16,
+		}
+	}, {
+		.version = PVR_403GC,
+		.mask = 0xff00,
+		.name = "403GC",
+		.ci = {
+			.dcache_size = 1024,
+			.dcache_line_size = 16,
+			.icache_size = 2048,
+			.icache_line_size = 16,
+		}
+	}, {
+		.version = PVR_403GCX,
+		.mask = 0xff00,
+		.name = "403GCX",
 		.ci = {
 			.dcache_size = 8192,
 			.dcache_line_size = 16,

Index: src/sys/arch/powerpc/include/ibm4xx/spr.h
diff -u src/sys/arch/powerpc/include/ibm4xx/spr.h:1.3 src/sys/arch/powerpc/include/ibm4xx/spr.h:1.4
--- src/sys/arch/powerpc/include/ibm4xx/spr.h:1.3	Sat Jun 18 17:06:52 2011
+++ src/sys/arch/powerpc/include/ibm4xx/spr.h	Fri Mar  5 07:10:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: spr.h,v 1.3 2011/06/18 17:06:52 matt Exp $	*/
+/*	$NetBSD: spr.h,v 1.4 2021/03/05 07:10:27 rin Exp $	*/
 
 #ifndef _POWERPC_IBM4XX_SPR_H_
 #define	_POWERPC_IBM4XX_SPR_H_
@@ -43,7 +43,10 @@
 #define	PVR_401F2		0x0026
 #define	PVR_401G2		0x0027
 
-#define	PVR_403			0x0020
+#define	PVR_403GA		0x0020	/* XXX no MMU */
+#define	PVR_403GB		0x00200100	/* XXX no MMU */
+#define	PVR_403GC		0x00200200
+#define	PVR_403GCX		0x00201400
 
 #define PVR_405GP		0x4011
 #define PVR_405GP_PASS1 	0x4011	/* RevA */



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-03-04 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Mar  5 05:35:50 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: pic_uic.c

Log Message:
Fix hard freeze in pic_handle_intr() for PPC_IBM403.

Not clearly documented in reference manual, but DCR_EXISR register is
not updated immediately after some bits are cleared by mtdcr, no matter
whether sync (= eieio) and/or isync are issued.

Therefore, we have to manage our own status mask in the interrupt handler.
This is what we did in obsoleted powerpc/ibm4xx/intr.c.

With this change, my Explora 451 works just fine with serial console!
Fix for framebuffer console will be committed soon.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/powerpc/ibm4xx/pic_uic.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/powerpc/ibm4xx/pic_uic.c
diff -u src/sys/arch/powerpc/ibm4xx/pic_uic.c:1.8 src/sys/arch/powerpc/ibm4xx/pic_uic.c:1.9
--- src/sys/arch/powerpc/ibm4xx/pic_uic.c:1.8	Sat Feb 27 20:43:58 2021
+++ src/sys/arch/powerpc/ibm4xx/pic_uic.c	Fri Mar  5 05:35:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic_uic.c,v 1.8 2021/02/27 20:43:58 rin Exp $	*/
+/*	$NetBSD: pic_uic.c,v 1.9 2021/03/05 05:35:50 rin Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic_uic.c,v 1.8 2021/02/27 20:43:58 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic_uic.c,v 1.9 2021/03/05 05:35:50 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ppcarch.h"
@@ -73,6 +73,19 @@ static void	uic_establish_irq(struct pic
 
 struct uic {
 	uint32_t uic_intr_enable;	/* cached intr enable mask */
+#ifdef PPC_IBM403
+	/*
+	 * Not clearly documented in reference manual, but DCR_EXISR
+	 * register is not updated immediately after some bits are
+	 * cleared by mtdcr, no matter whether sync (= eieio) and/or
+	 * isync are issued.
+	 *
+	 * Therefore, we have to manage our own status mask in the
+	 * interrupt handler; see uic_{ack,get}_irq() for more details.
+	 * This is what we did in obsoleted powerpc/ibm4xx/intr.c.
+	 */
+	uint32_t uic_intr_status;
+#endif
 	uint32_t (*uic_mf_intr_status)(void);
 	uint32_t (*uic_mf_intr_enable)(void);
 	void (*uic_mt_intr_enable)(uint32_t);
@@ -356,15 +369,26 @@ uic_ack_irq(struct pic_ops *pic, int irq
 	struct uic * const uic = pic->pic_cookie;
 	const uint32_t irqmask = IRQ_TO_MASK(irq);
 
+#ifdef PPC_IBM403
+	uic->uic_intr_status &= ~irqmask;
+#endif
+
 	(*uic->uic_mt_intr_ack)(irqmask);
 }
 
 static int
-uic_get_irq(struct pic_ops *pic, int dummy)
+uic_get_irq(struct pic_ops *pic, int req)
 {
 	struct uic * const uic = pic->pic_cookie;
 
+#ifdef PPC_IBM403
+	if (req == PIC_GET_IRQ)
+		uic->uic_intr_status = (*uic->uic_mf_intr_status)();
+	const uint32_t irqmask = uic->uic_intr_status;
+#else
 	const uint32_t irqmask = (*uic->uic_mf_intr_status)();
+#endif
+
 	if (irqmask == 0)
 		return 255;
 	return IRQ_OF_MASK(irqmask);



CVS commit: src/sys/arch/powerpc/oea

2021-03-04 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Mar  5 02:58:13 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofwoea_machdep.c

Log Message:
Split set_timebase() into get_timebase_frequency() and init_decrementer().
Call get_timebase_frequency() much earlier.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/powerpc/oea/ofwoea_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/powerpc/oea/ofwoea_machdep.c
diff -u src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.57 src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.58
--- src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.57	Fri Mar  5 01:33:33 2021
+++ src/sys/arch/powerpc/oea/ofwoea_machdep.c	Fri Mar  5 02:58:13 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofwoea_machdep.c,v 1.57 2021/03/05 01:33:33 thorpej Exp $ */
+/* $NetBSD: ofwoea_machdep.c,v 1.58 2021/03/05 02:58:13 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.57 2021/03/05 01:33:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.58 2021/03/05 02:58:13 thorpej Exp $");
 
 #include "ksyms.h"
 #include "wsdisplay.h"
@@ -136,8 +136,10 @@ extern uint32_t ticks_per_sec;
 extern uint32_t ns_per_tick;
 extern uint32_t ticks_per_intr;
 
+static void get_timebase_frequency(void);
+static void init_decrementer(void);
+
 static void restore_ofmap(void);
-static void set_timebase(void);
 
 void
 ofwoea_initppc(u_int startkernel, u_int endkernel, char *args)
@@ -172,6 +174,9 @@ ofwoea_initppc(u_int startkernel, u_int 
 			bootpath[len] = 0;
 	}
 
+	/* Get the timebase frequency from the firmware. */
+	get_timebase_frequency();
+
 	/* Initialize bus_space */
 	ofwoea_bus_space_init();
 
@@ -267,8 +272,8 @@ ofwoea_initppc(u_int startkernel, u_int 
 	ksyms_addsyms_elf((int)((uintptr_t)endsym - (uintptr_t)startsym), startsym, endsym);
 #endif
 
-	/* CPU clock stuff */
-	set_timebase();
+	/* Kick off the clock. */
+	init_decrementer();
 
 #ifdef DDB
 	if (boothowto & RB_KDB)
@@ -276,22 +281,22 @@ ofwoea_initppc(u_int startkernel, u_int 
 #endif
 }
 
-void
-set_timebase(void)
+static void
+get_timebase_frequency(void)
 {
-	int qhandle, phandle, msr, scratch, node;
+	int qhandle, phandle, node;
 	char type[32];
 
 	if (timebase_freq != 0) {
 		ticks_per_sec = timebase_freq;
-		goto found;
+		return;
 	}
 
 	node = OF_finddevice("/cpus/@0");
 	if (node != -1 &&
 	OF_getprop(node, "timebase-frequency", _per_sec,
 		   sizeof ticks_per_sec) > 0) {
-		goto found;
+		return;
 	}
 
 	node = OF_finddevice("/");
@@ -300,7 +305,7 @@ set_timebase(void)
 		&& strcmp(type, "cpu") == 0
 		&& OF_getprop(qhandle, "timebase-frequency",
 			_per_sec, sizeof ticks_per_sec) > 0) {
-			goto found;
+			return;
 		}
 		if ((phandle = OF_child(qhandle)))
 			continue;
@@ -311,8 +316,15 @@ set_timebase(void)
 		}
 	}
 	panic("no cpu node");
+}
+
+static void
+init_decrementer(void)
+{
+	int scratch, msr;
+
+	KASSERT(ticks_per_sec != 0);
 
-found:
 	__asm volatile ("mfmsr %0; andi. %1,%0,%2; mtmsr %1"
 		: "=r"(msr), "=r"(scratch) : "K"((u_short)~PSL_EE));
 	ns_per_tick = 10 / ticks_per_sec;
@@ -321,10 +333,10 @@ found:
 
 #ifdef PPC_OEA601
 	if ((mfpvr() >> 16) == MPC601)
-	curcpu()->ci_lasttb = rtc_nanosecs();
+		curcpu()->ci_lasttb = rtc_nanosecs();
 	else
 #endif
-	curcpu()->ci_lasttb = mftbl();
+		curcpu()->ci_lasttb = mftbl();
 
 	mtspr(SPR_DEC, ticks_per_intr);
 	mtmsr(msr);



CVS commit: src/sys/arch/powerpc

2021-03-01 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Mar  2 07:37:27 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: intr.h
src/sys/arch/powerpc/pic: intr.c

Log Message:
Turn imask into static.

XXX
Other macro etc. in powerpc/intr.h should also be moved into
powerpc/pic/intr.c, or protected by __INTR_PRIVATE.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/powerpc/include/intr.h
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/powerpc/pic/intr.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/powerpc/include/intr.h
diff -u src/sys/arch/powerpc/include/intr.h:1.17 src/sys/arch/powerpc/include/intr.h:1.18
--- src/sys/arch/powerpc/include/intr.h:1.17	Thu Apr 16 23:29:52 2020
+++ src/sys/arch/powerpc/include/intr.h	Tue Mar  2 07:37:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.17 2020/04/16 23:29:52 rin Exp $ */
+/*	$NetBSD: intr.h,v 1.18 2021/03/02 07:37:27 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -28,7 +28,7 @@
 
 #ifndef _LOCORE
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.h,v 1.17 2020/04/16 23:29:52 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.h,v 1.18 2021/03/02 07:37:27 rin Exp $");
 #endif
 
 #ifndef _POWERPC_INTR_MACHDEP_H_
@@ -103,8 +103,6 @@ typedef __IMASK_T imask_t;
 typedef uint32_t imask_t;
 #endif
 
-extern imask_t imask[];
-
 #define NVIRQ		(sizeof(imask_t)*8)	/* 32 virtual IRQs */
 #ifndef NIRQ
 #define NIRQ		256	/* up to 256 HW IRQs */

Index: src/sys/arch/powerpc/pic/intr.c
diff -u src/sys/arch/powerpc/pic/intr.c:1.29 src/sys/arch/powerpc/pic/intr.c:1.30
--- src/sys/arch/powerpc/pic/intr.c:1.29	Mon Jul  6 10:31:23 2020
+++ src/sys/arch/powerpc/pic/intr.c	Tue Mar  2 07:37:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.c,v 1.29 2020/07/06 10:31:23 rin Exp $ */
+/*	$NetBSD: intr.c,v 1.30 2021/03/02 07:37:27 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -29,7 +29,7 @@
 #define __INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.29 2020/07/06 10:31:23 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.30 2021/03/02 07:37:27 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_interrupt.h"
@@ -75,7 +75,7 @@ int num_pics = 0;
 int max_base = 0;
 uint8_t	virq_map[NIRQ];
 imask_t virq_mask = HWIRQ_MASK;
-imask_t	imask[NIPL];
+static imask_t imask[NIPL];
 int	primary_pic = 0;
 
 static int	fakeintr(void *);



CVS commit: src/sys/arch/powerpc

2021-03-01 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue Mar  2 02:28:45 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: ofw_machdep.h
src/sys/arch/powerpc/powerpc: ofw_machdep.c

Log Message:
- Add a boolean "ofwbootcons_suppress" that, when true, suppresses
  ofwbootcons I/O (i.e. "doesn't call into OFW").  This allows
  platform code to ensure that early console I/O doesn't occur in certain
  critical sections.
- When printing the translations, put phys next to virt for easier
  visual comparisons.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/powerpc/include/ofw_machdep.h
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/powerpc/powerpc/ofw_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/powerpc/include/ofw_machdep.h
diff -u src/sys/arch/powerpc/include/ofw_machdep.h:1.3 src/sys/arch/powerpc/include/ofw_machdep.h:1.4
--- src/sys/arch/powerpc/include/ofw_machdep.h:1.3	Sun Feb 28 20:31:32 2021
+++ src/sys/arch/powerpc/include/ofw_machdep.h	Tue Mar  2 02:28:45 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_machdep.h,v 1.3 2021/02/28 20:31:32 thorpej Exp $ */
+/* $NetBSD: ofw_machdep.h,v 1.4 2021/03/02 02:28:45 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -54,6 +54,8 @@ struct OF_translation {
 
 #define	OFW_MAX_TRANSLATIONS	48
 
+extern bool ofwbootcons_suppress; /* supporess OF console I/O */
+
 extern int ofw_chosen;		/* cached handle for "/chosen" */
 extern struct OF_translation ofw_translations[OFW_MAX_TRANSLATIONS];
 

Index: src/sys/arch/powerpc/powerpc/ofw_machdep.c
diff -u src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.29 src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.30
--- src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.29	Sat Feb 20 01:57:54 2021
+++ src/sys/arch/powerpc/powerpc/ofw_machdep.c	Tue Mar  2 02:28:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_machdep.c,v 1.29 2021/02/20 01:57:54 thorpej Exp $	*/
+/*	$NetBSD: ofw_machdep.c,v 1.30 2021/03/02 02:28:45 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2021 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.29 2021/02/20 01:57:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.30 2021/03/02 02:28:45 thorpej Exp $");
 
 #include 
 #include 
@@ -99,6 +99,8 @@ bool	ofw_real_mode;
 
 int	console_node = -1, console_instance = -1;
 int	ofw_stdin, ofw_stdout;
+bool	ofwbootcons_suppress;
+
 int	ofw_address_cells;
 int	ofw_size_cells;
 
@@ -108,6 +110,10 @@ ofwbootcons_cngetc(dev_t dev)
 	unsigned char ch = '\0';
 	int l;
 
+	if (ofwbootcons_suppress) {
+		return ch;
+	}
+
 	while ((l = OF_read(ofw_stdin, , 1)) != 1) {
 		if (l != -2 && l != 0) {
 			return -1;
@@ -121,6 +127,10 @@ ofwbootcons_cnputc(dev_t dev, int c)
 {
 	char ch = c;
 
+	if (ofwbootcons_suppress) {
+		return;
+	}
+
 	OF_write(ofw_stdout, , 1);
 }
 
@@ -394,8 +404,8 @@ ofw_bootstrap_get_translations(void)
 		}
 
 		aprint_normal("translation %d virt=%#"PRIx32
-		" size=%#"PRIx32" phys=%#"PRIx64" mode=%#"PRIx32"\n",
-		idx, virt, size, phys, mode);
+		" phys=%#"PRIx64" size=%#"PRIx32" mode=%#"PRIx32"\n",
+		idx, virt, phys, size, mode);
 		
 		if (sizeof(paddr_t) < 8 && phys >= 0x1ULL) {
 			panic("translation phys out of range");



CVS commit: src/sys/arch/powerpc

2021-03-01 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue Mar  2 01:47:45 UTC 2021

Modified Files:
src/sys/arch/powerpc/include/oea: pmap.h
src/sys/arch/powerpc/oea: pmap.c pmap_kernel.c

Log Message:
Complete the pmap symbol renaming shenanigans for pmap_bootstrap[12]().


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/powerpc/include/oea/pmap.h
cvs rdiff -u -r1.100 -r1.101 src/sys/arch/powerpc/oea/pmap.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/powerpc/oea/pmap_kernel.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/powerpc/include/oea/pmap.h
diff -u src/sys/arch/powerpc/include/oea/pmap.h:1.33 src/sys/arch/powerpc/include/oea/pmap.h:1.34
--- src/sys/arch/powerpc/include/oea/pmap.h:1.33	Mon Mar  1 01:53:46 2021
+++ src/sys/arch/powerpc/include/oea/pmap.h	Tue Mar  2 01:47:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.33 2021/03/01 01:53:46 thorpej Exp $	*/
+/*	$NetBSD: pmap.h,v 1.34 2021/03/02 01:47:44 thorpej Exp $	*/
 
 /*-
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -107,6 +107,8 @@ struct pmap_ops {
 	void (*pmapop_pvo_verify)(void);
 	vaddr_t (*pmapop_steal_memory)(vsize_t, vaddr_t *, vaddr_t *);
 	void (*pmapop_bootstrap)(paddr_t, paddr_t);
+	void (*pmapop_bootstrap1)(paddr_t, paddr_t);
+	void (*pmapop_bootstrap2)(void);
 };
 
 #ifdef	_KERNEL

Index: src/sys/arch/powerpc/oea/pmap.c
diff -u src/sys/arch/powerpc/oea/pmap.c:1.100 src/sys/arch/powerpc/oea/pmap.c:1.101
--- src/sys/arch/powerpc/oea/pmap.c:1.100	Tue Mar  2 00:28:55 2021
+++ src/sys/arch/powerpc/oea/pmap.c	Tue Mar  2 01:47:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.100 2021/03/02 00:28:55 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.101 2021/03/02 01:47:44 thorpej Exp $	*/
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.100 2021/03/02 00:28:55 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.101 2021/03/02 01:47:44 thorpej Exp $");
 
 #define	PMAP_NOOPNAMES
 
@@ -284,6 +284,8 @@ const struct pmap_ops PMAPNAME(ops) = {
 #endif
 	.pmapop_steal_memory = pmap_steal_memory,
 	.pmapop_bootstrap = pmap_bootstrap,
+	.pmapop_bootstrap1 = pmap_bootstrap1,
+	.pmapop_bootstrap2 = pmap_bootstrap2,
 };
 #endif /* !PMAPNAME */
 

Index: src/sys/arch/powerpc/oea/pmap_kernel.c
diff -u src/sys/arch/powerpc/oea/pmap_kernel.c:1.11 src/sys/arch/powerpc/oea/pmap_kernel.c:1.12
--- src/sys/arch/powerpc/oea/pmap_kernel.c:1.11	Mon Jul  6 09:34:17 2020
+++ src/sys/arch/powerpc/oea/pmap_kernel.c	Tue Mar  2 01:47:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_kernel.c,v 1.11 2020/07/06 09:34:17 rin Exp $	*/
+/*	$NetBSD: pmap_kernel.c,v 1.12 2021/03/02 01:47:44 thorpej Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -30,7 +30,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: pmap_kernel.c,v 1.11 2020/07/06 09:34:17 rin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: pmap_kernel.c,v 1.12 2021/03/02 01:47:44 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altivec.h"
@@ -109,6 +109,8 @@ void	pmap_pvo_verify(void)	__stub;
 #endif
 vaddr_t	pmap_steal_memory(vsize_t, vaddr_t *, vaddr_t *)	__stub;
 void	pmap_bootstrap(paddr_t, paddr_t)			__stub;
+void	pmap_bootstrap1(paddr_t, paddr_t)			__stub;
+void	pmap_bootstrap2(void)	__stub;
 
 int
 pmap_pte_spill(struct pmap *pm, vaddr_t va, bool exec)
@@ -300,4 +302,16 @@ pmap_bootstrap(paddr_t startkernel, padd
 {
 	(*pmapops->pmapop_bootstrap)(startkernel, endkernel);
 }
+
+void
+pmap_bootstrap1(paddr_t startkernel, paddr_t endkernel)
+{
+	(*pmapops->pmapop_bootstrap1)(startkernel, endkernel);
+}
+
+void
+pmap_bootstrap2(void)
+{
+	(*pmapops->pmapop_bootstrap2)();
+}
 #endif



CVS commit: src/sys/arch/powerpc/oea

2021-03-01 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Mar  2 00:28:55 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: pmap.c

Log Message:
Apply PMAPNAME() to pmap_bootstrap[12](); fix build for ofppc, which has
both pmap32 and pmap64bridge in a single kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/sys/arch/powerpc/oea/pmap.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/powerpc/oea/pmap.c
diff -u src/sys/arch/powerpc/oea/pmap.c:1.99 src/sys/arch/powerpc/oea/pmap.c:1.100
--- src/sys/arch/powerpc/oea/pmap.c:1.99	Mon Mar  1 01:53:46 2021
+++ src/sys/arch/powerpc/oea/pmap.c	Tue Mar  2 00:28:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.99 2021/03/01 01:53:46 thorpej Exp $	*/
+/*	$NetBSD: pmap.c,v 1.100 2021/03/02 00:28:55 rin Exp $	*/
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.99 2021/03/01 01:53:46 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.100 2021/03/02 00:28:55 rin Exp $");
 
 #define	PMAP_NOOPNAMES
 
@@ -191,6 +191,8 @@ static u_int mem_cnt, avail_cnt;
 #endif
 #define pmap_steal_memory	PMAPNAME(steal_memory)
 #define pmap_bootstrap		PMAPNAME(bootstrap)
+#define pmap_bootstrap1		PMAPNAME(bootstrap1)
+#define pmap_bootstrap2		PMAPNAME(bootstrap2)
 #else
 #define	STATIC			/* nothing */
 #endif /* PMAPNAME */
@@ -234,6 +236,8 @@ STATIC void pmap_pvo_verify(void);
 #endif
 STATIC vaddr_t pmap_steal_memory(vsize_t, vaddr_t *, vaddr_t *);
 STATIC void pmap_bootstrap(paddr_t, paddr_t);
+STATIC void pmap_bootstrap1(paddr_t, paddr_t);
+STATIC void pmap_bootstrap2(void);
 
 #ifdef PMAPNAME
 const struct pmap_ops PMAPNAME(ops) = {



CVS commit: src/sys/arch/powerpc

2021-02-28 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Mar  1 01:53:46 UTC 2021

Modified Files:
src/sys/arch/powerpc/include/oea: pmap.h
src/sys/arch/powerpc/oea: pmap.c

Log Message:
Split pmap_bootstrap() into 2 functions:
- pmap_bootstrap1(), which sets up the low-level pmap data structures.
- pmap_bootstrap2(), which actually programs the MMU hardware based on
  pmap_bootstrap1()'s work.

pmap_bootstrap() is still provided as a wrapper around the two, but this
provides flexibility to platforms that might need to do additional work
between these two phases.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/powerpc/include/oea/pmap.h
cvs rdiff -u -r1.98 -r1.99 src/sys/arch/powerpc/oea/pmap.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/powerpc/include/oea/pmap.h
diff -u src/sys/arch/powerpc/include/oea/pmap.h:1.32 src/sys/arch/powerpc/include/oea/pmap.h:1.33
--- src/sys/arch/powerpc/include/oea/pmap.h:1.32	Mon Jul  6 10:57:03 2020
+++ src/sys/arch/powerpc/include/oea/pmap.h	Mon Mar  1 01:53:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.32 2020/07/06 10:57:03 rin Exp $	*/
+/*	$NetBSD: pmap.h,v 1.33 2021/03/01 01:53:46 thorpej Exp $	*/
 
 /*-
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -145,6 +145,8 @@ extern unsigned int pmap_pteg_cnt;
 extern unsigned int pmap_pteg_mask;
 
 void pmap_bootstrap(vaddr_t, vaddr_t);
+void pmap_bootstrap1(vaddr_t, vaddr_t);
+void pmap_bootstrap2(void);
 bool pmap_extract(pmap_t, vaddr_t, paddr_t *);
 bool pmap_query_bit(struct vm_page *, int);
 bool pmap_clear_bit(struct vm_page *, int);

Index: src/sys/arch/powerpc/oea/pmap.c
diff -u src/sys/arch/powerpc/oea/pmap.c:1.98 src/sys/arch/powerpc/oea/pmap.c:1.99
--- src/sys/arch/powerpc/oea/pmap.c:1.98	Mon Jul  6 09:34:17 2020
+++ src/sys/arch/powerpc/oea/pmap.c	Mon Mar  1 01:53:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.98 2020/07/06 09:34:17 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.99 2021/03/01 01:53:46 thorpej Exp $	*/
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.98 2020/07/06 09:34:17 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.99 2021/03/01 01:53:46 thorpej Exp $");
 
 #define	PMAP_NOOPNAMES
 
@@ -3145,12 +3145,11 @@ pmap_setup_segment0_map(int use_large_pa
 #endif /* PMAP_OEA64_BRIDGE */
 
 /*
- * This is not part of the defined PMAP interface and is specific to the
- * PowerPC architecture.  This is called during initppc, before the system
- * is really initialized.
+ * Set up the bottom level of the data structures necessary for the kernel
+ * to manage memory.  MMU hardware is programmed in pmap_bootstrap2().
  */
 void
-pmap_bootstrap(paddr_t kernelstart, paddr_t kernelend)
+pmap_bootstrap1(paddr_t kernelstart, paddr_t kernelend)
 {
 	struct mem_region *mp, tmp;
 	paddr_t s, e;
@@ -3413,34 +3412,20 @@ pmap_bootstrap(paddr_t kernelstart, padd
 		continue;
 #endif
  		pmap_kernel()->pm_sr[i] = KERNELN_SEGMENT(i)|SR_PRKEY;
-		__asm volatile ("mtsrin %0,%1"
- 			  :: "r"(KERNELN_SEGMENT(i)|SR_PRKEY), "r"(i << ADDR_SR_SHFT));
 	}
 
 	pmap_kernel()->pm_sr[KERNEL_SR] = KERNEL_SEGMENT|SR_SUKEY|SR_PRKEY;
-	__asm volatile ("mtsr %0,%1"
-		  :: "n"(KERNEL_SR), "r"(KERNEL_SEGMENT));
 #ifdef KERNEL2_SR
 	pmap_kernel()->pm_sr[KERNEL2_SR] = KERNEL2_SEGMENT|SR_SUKEY|SR_PRKEY;
-	__asm volatile ("mtsr %0,%1"
-		  :: "n"(KERNEL2_SR), "r"(KERNEL2_SEGMENT));
 #endif
 #endif /* PMAP_OEA || PMAP_OEA64_BRIDGE */
 #if defined (PMAP_OEA)
 	for (i = 0; i < 16; i++) {
 		if (iosrtable[i] & SR601_T) {
 			pmap_kernel()->pm_sr[i] = iosrtable[i];
-			__asm volatile ("mtsrin %0,%1"
-			:: "r"(iosrtable[i]), "r"(i << ADDR_SR_SHFT));
 		}
 	}
-	__asm volatile ("sync; mtsdr1 %0; isync"
-		  :: "r"((uintptr_t)pmap_pteg_table | (pmap_pteg_mask >> 10)));
-#elif defined (PMAP_OEA64) || defined (PMAP_OEA64_BRIDGE)
- 	__asm __volatile ("sync; mtsdr1 %0; isync"
- 		  :: "r"((uintptr_t)pmap_pteg_table | (32 - __builtin_clz(pmap_pteg_mask >> 11;
 #endif
-	tlbia();
 
 #ifdef ALTIVEC
 	pmap_use_altivec = cpu_altivec;
@@ -3537,14 +3522,54 @@ pmap_bootstrap(paddr_t kernelstart, padd
 			pmap_pte_insert(ptegidx, );
 		}
 #endif
+	}
+#endif
+}
 
-		__asm volatile ("mtsrin %0,%1"
- 			  :: "r"(sr), "r"(kernelstart));
+/*
+ * Using the data structures prepared in pmap_bootstrap1(), program
+ * the MMU hardware.
+ */
+void
+pmap_bootstrap2(void)
+{
+/* PMAP_OEA64_BRIDGE does support these instructions */
+#if defined (PMAP_OEA) || defined (PMAP_OEA64_BRIDGE)
+	for (int i = 0; i < 16; i++) {
+#if defined(PPC_OEA601)
+		/* XXX wedges for segment register 0xf , so set later */
+		if ((iosrtable[i] & SR601_T) && ((MFPVR() >> 16) == MPC601))
+			continue;
+#endif /* PPC_OEA601 */
+		__asm volatile("mtsrin %0,%1"
+			:: "r"(pmap_kernel()->pm_sr[i]),
+			   

CVS commit: src/sys/arch/powerpc/include

2021-02-28 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Feb 28 20:31:33 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: ofw_machdep.h

Log Message:
Bump OFW_MAX_TRANSLATIONS from 32 -> 48.  32 was already tight (at least
on my Macs), and having having translations for the kernel itself present
in the firmware's translation table bumped it over the 32-entry limit.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/powerpc/include/ofw_machdep.h

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/powerpc/include/ofw_machdep.h
diff -u src/sys/arch/powerpc/include/ofw_machdep.h:1.2 src/sys/arch/powerpc/include/ofw_machdep.h:1.3
--- src/sys/arch/powerpc/include/ofw_machdep.h:1.2	Fri Feb 19 05:21:39 2021
+++ src/sys/arch/powerpc/include/ofw_machdep.h	Sun Feb 28 20:31:32 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_machdep.h,v 1.2 2021/02/19 05:21:39 thorpej Exp $ */
+/* $NetBSD: ofw_machdep.h,v 1.3 2021/02/28 20:31:32 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@ struct OF_translation {
 	uint32_t	mode;
 };
 
-#define	OFW_MAX_TRANSLATIONS	32
+#define	OFW_MAX_TRANSLATIONS	48
 
 extern int ofw_chosen;		/* cached handle for "/chosen" */
 extern struct OF_translation ofw_translations[OFW_MAX_TRANSLATIONS];



CVS commit: src/sys/arch/powerpc/oea

2021-02-28 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Feb 28 19:01:11 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofw_subr.S

Log Message:
Minor re-ordering of a few things, and issue an isync barrier at all
critical MMU on/off transitions.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/powerpc/oea/ofw_subr.S

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/powerpc/oea/ofw_subr.S
diff -u src/sys/arch/powerpc/oea/ofw_subr.S:1.19 src/sys/arch/powerpc/oea/ofw_subr.S:1.20
--- src/sys/arch/powerpc/oea/ofw_subr.S:1.19	Wed Feb 24 17:35:39 2021
+++ src/sys/arch/powerpc/oea/ofw_subr.S	Sun Feb 28 19:01:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_subr.S,v 1.19 2021/02/24 17:35:39 thorpej Exp $	*/
+/*	$NetBSD: ofw_subr.S,v 1.20 2021/02/28 19:01:11 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -148,10 +148,6 @@ ENTRY_NOPROFILE(openfirmware_trampoline)
 	 */
 	stwu	%r1,-48(%r1)
 
-	lis	%r4,ofentry@ha		/* get firmware entry point */
-	lwz	%r4,ofentry@l(%r4)
-	mtlr	%r4
-
 #ifdef FIRMWORKSBUGS
 	lis	%r4,ofwreal_incharge@ha
 	lwz	%r4,ofwreal_incharge@l(%r4)
@@ -164,9 +160,12 @@ ENTRY_NOPROFILE(openfirmware_trampoline)
 	mfmsr	%r4			/* save msr */
 	stw	%r4,8(%r1)
 
-	li	%r0,0			/* clear battable translations */
+	li	%r0,0			/* disable MMU */
 	mtmsr	%r0
+	isync
+
 #if defined (PPC_OEA) || defined (PPC_OEA64_BRIDGE)
+	/* clear BAT translations */
 	mtdbatu	2,%r0
 	mtdbatu	3,%r0
 	mtibatu	2,%r0
@@ -202,13 +201,21 @@ ENTRY_NOPROFILE(openfirmware_trampoline)
 	addi	%r5,%r5,_C_LABEL(ofw_battable)@l
 	stw	%r5,CI_BATTABLE(%r4)
 
-	lis	%r4,ofwmsr@ha		/* Open Firmware msr */
+	lis	%r4,ofentry@ha		/* get firmware entry point */
+	lwz	%r4,ofentry@l(%r4)
+	mtlr	%r4
+
+	lis	%r4,ofwmsr@ha		/* load Open Firmware MSR */
 	lwz	%r5,ofwmsr@l(%r4)
 	mtmsr	%r5
 	isync
 
 	blrl/* call Open Firmware */
 
+	li	%r0,0			/* ensure disable MMU is disabled */
+	mtmsr	%r0
+	isync
+
 	/* curcpu()->ci_battable =  */
 	GET_CPUINFO(%r4)
 	lis	%r5,_C_LABEL(battable)@ha



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-02-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Feb 27 20:43:58 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: pic_uic.c
src/sys/arch/powerpc/ibm4xx/dev: com_opb.c dwctwo_plb.c ecc_plb.c
if_emac.c mal.c

Log Message:
Switch to intr_establish_xname().


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/powerpc/ibm4xx/pic_uic.c
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/powerpc/ibm4xx/dev/com_opb.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/powerpc/ibm4xx/dev/dwctwo_plb.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/powerpc/ibm4xx/dev/ecc_plb.c
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/powerpc/ibm4xx/dev/if_emac.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/powerpc/ibm4xx/dev/mal.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/powerpc/ibm4xx/pic_uic.c
diff -u src/sys/arch/powerpc/ibm4xx/pic_uic.c:1.7 src/sys/arch/powerpc/ibm4xx/pic_uic.c:1.8
--- src/sys/arch/powerpc/ibm4xx/pic_uic.c:1.7	Mon Jul  6 10:35:28 2020
+++ src/sys/arch/powerpc/ibm4xx/pic_uic.c	Sat Feb 27 20:43:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pic_uic.c,v 1.7 2020/07/06 10:35:28 rin Exp $	*/
+/*	$NetBSD: pic_uic.c,v 1.8 2021/02/27 20:43:58 rin Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pic_uic.c,v 1.7 2020/07/06 10:35:28 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pic_uic.c,v 1.8 2021/02/27 20:43:58 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ppcarch.h"
@@ -217,7 +217,8 @@ extern struct pic_ops pic_uic1;
 static void
 uic1_finish_setup(struct pic_ops *pic)
 {
-	intr_establish(30, IST_LEVEL, IPL_HIGH, pic_handle_intr, _uic1);
+	intr_establish_xname(30, IST_LEVEL, IPL_HIGH, pic_handle_intr,
+	_uic1, "uic1");
 }
 
 struct uic uic1 = {
@@ -272,7 +273,8 @@ extern struct pic_ops pic_uic2;
 static void
 uic2_finish_setup(struct pic_ops *pic)
 {
-	intr_establish(28, IST_LEVEL, IPL_HIGH, pic_handle_intr, _uic2);
+	intr_establish_xname(28, IST_LEVEL, IPL_HIGH, pic_handle_intr,
+	_uic2, "uic2");
 }
 
 static struct uic uic2 = {

Index: src/sys/arch/powerpc/ibm4xx/dev/com_opb.c
diff -u src/sys/arch/powerpc/ibm4xx/dev/com_opb.c:1.24 src/sys/arch/powerpc/ibm4xx/dev/com_opb.c:1.25
--- src/sys/arch/powerpc/ibm4xx/dev/com_opb.c:1.24	Mon Jul  6 09:34:17 2020
+++ src/sys/arch/powerpc/ibm4xx/dev/com_opb.c	Sat Feb 27 20:43:58 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: com_opb.c,v 1.24 2020/07/06 09:34:17 rin Exp $ */
+/* $NetBSD: com_opb.c,v 1.25 2021/02/27 20:43:58 rin Exp $ */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com_opb.c,v 1.24 2020/07/06 09:34:17 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com_opb.c,v 1.25 2021/02/27 20:43:58 rin Exp $");
 
 #include "com.h"
 
@@ -133,7 +133,8 @@ com_opb_attach(device_t parent, device_t
 
 	com_attach_subr(sc);
 
-	intr_establish(oaa->opb_irq, IST_LEVEL, IPL_SERIAL, comintr, sc);
+	intr_establish_xname(oaa->opb_irq, IST_LEVEL, IPL_SERIAL, comintr, sc,
+	device_xname(self));
 }
 
 /*

Index: src/sys/arch/powerpc/ibm4xx/dev/dwctwo_plb.c
diff -u src/sys/arch/powerpc/ibm4xx/dev/dwctwo_plb.c:1.5 src/sys/arch/powerpc/ibm4xx/dev/dwctwo_plb.c:1.6
--- src/sys/arch/powerpc/ibm4xx/dev/dwctwo_plb.c:1.5	Sat Apr 23 10:15:30 2016
+++ src/sys/arch/powerpc/ibm4xx/dev/dwctwo_plb.c	Sat Feb 27 20:43:58 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwctwo_plb.c,v 1.5 2016/04/23 10:15:30 skrll Exp $ */
+/* $NetBSD: dwctwo_plb.c,v 1.6 2021/02/27 20:43:58 rin Exp $ */
 /*
  * Copyright (c) 2013 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwctwo_plb.c,v 1.5 2016/04/23 10:15:30 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwctwo_plb.c,v 1.6 2021/02/27 20:43:58 rin Exp $");
 
 #include 
 #include 
@@ -112,7 +112,8 @@ dwctwo_plb_attach(device_t parent, devic
 	bus_space_map(sc->sc_iot, paa->plb_addr, DWCTWO_SIZE, 0, >sc_ioh);
 	sc->sc_bus.ub_dmatag = paa->plb_dmat;
 
-	intr_establish(paa->plb_irq, IST_LEVEL, IPL_VM, dwc2_intr, sc);
+	intr_establish_xname(paa->plb_irq, IST_LEVEL, IPL_VM, dwc2_intr, sc,
+	device_xname(self));
 
 	/* Enable the USB interface. */
 	mtsdr(DCR_SDR0_PFC1, mfsdr(DCR_SDR0_PFC1) | SDR0_PFC1_USBEN);

Index: src/sys/arch/powerpc/ibm4xx/dev/ecc_plb.c
diff -u src/sys/arch/powerpc/ibm4xx/dev/ecc_plb.c:1.15 src/sys/arch/powerpc/ibm4xx/dev/ecc_plb.c:1.16
--- src/sys/arch/powerpc/ibm4xx/dev/ecc_plb.c:1.15	Tue Feb 25 14:09:13 2014
+++ src/sys/arch/powerpc/ibm4xx/dev/ecc_plb.c	Sat Feb 27 20:43:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ecc_plb.c,v 1.15 2014/02/25 14:09:13 martin Exp $	*/
+/*	$NetBSD: ecc_plb.c,v 1.16 2021/02/27 20:43:58 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ecc_plb.c,v 1.15 2014/02/25 14:09:13 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ecc_plb.c,v 1.16 2021/02/27 20:43:58 rin Exp $");
 
 

CVS commit: src/sys/arch/powerpc/oea

2021-02-26 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Feb 27 01:22:18 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofwoea_machdep.c

Log Message:
In ofwoea_initppc(), call oea_init() after getting the bootpath, etc.
Also, add a comment explaining why it's actually necessary to clear
PSL_IP after installing the kernel's exception vectors.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/arch/powerpc/oea/ofwoea_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/powerpc/oea/ofwoea_machdep.c
diff -u src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.54 src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.55
--- src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.54	Wed Feb 24 16:53:00 2021
+++ src/sys/arch/powerpc/oea/ofwoea_machdep.c	Sat Feb 27 01:22:18 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofwoea_machdep.c,v 1.54 2021/02/24 16:53:00 thorpej Exp $ */
+/* $NetBSD: ofwoea_machdep.c,v 1.55 2021/02/27 01:22:18 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.54 2021/02/24 16:53:00 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.55 2021/02/27 01:22:18 thorpej Exp $");
 
 #include "ksyms.h"
 #include "wsdisplay.h"
@@ -215,15 +215,6 @@ ofwoea_initppc(u_int startkernel, u_int 
 	}
 #endif
 
-	oea_init(pic_ext_intr);
-
-/*
- * XXX
- * we need to do this here instead of earlier on in ofwinit() for some reason
- * At least some versions of Apple OF 2.0.1 hang if we do this earlier
- */ 
-	ofwmsr &= ~PSL_IP;
-
 	/* Parse the args string */
 	if (args) {
 		strcpy(bootpath, args);
@@ -243,6 +234,15 @@ ofwoea_initppc(u_int startkernel, u_int 
 			bootpath[len] = 0;
 	}
 
+	oea_init(pic_ext_intr);
+
+	/*
+	 * Now that we've installed our own exception vectors,
+	 * ensure that exceptions that happen while running
+	 * firmware code fall into ours.
+	 */
+	ofwmsr &= ~PSL_IP;
+
 	uvm_md_init();
 
 	pmap_bootstrap(startkernel, endkernel);



CVS commit: src/sys/arch/powerpc

2021-02-26 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Feb 27 01:16:52 UTC 2021

Modified Files:
src/sys/arch/powerpc/include/oea: sr_601.h
src/sys/arch/powerpc/oea: oea_machdep.c

Log Message:
Rather than putting it on the caller, just let oea_iobat_add() decide
whether to call mpc601_ioseg_add().


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/powerpc/include/oea/sr_601.h
cvs rdiff -u -r1.81 -r1.82 src/sys/arch/powerpc/oea/oea_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/powerpc/include/oea/sr_601.h
diff -u src/sys/arch/powerpc/include/oea/sr_601.h:1.5 src/sys/arch/powerpc/include/oea/sr_601.h:1.6
--- src/sys/arch/powerpc/include/oea/sr_601.h:1.5	Mon Apr 28 20:23:32 2008
+++ src/sys/arch/powerpc/include/oea/sr_601.h	Sat Feb 27 01:16:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sr_601.h,v 1.5 2008/04/28 20:23:32 martin Exp $	*/
+/*	$NetBSD: sr_601.h,v 1.6 2021/02/27 01:16:52 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2004 The NetBSD Foundation, Inc.
@@ -64,8 +64,4 @@
 #define	SR601_PA_MATCH_P(sr, pa) \
 	 (((sr) & SR601_PACKET1) == ((pa) >> ADDR_SR_SHFT))
 
-#ifdef _KERNEL
-void mpc601_ioseg_add(paddr_t, register_t);
-#endif
-
 #endif /* !_POWERPC_OEA_SR_601_H_ */

Index: src/sys/arch/powerpc/oea/oea_machdep.c
diff -u src/sys/arch/powerpc/oea/oea_machdep.c:1.81 src/sys/arch/powerpc/oea/oea_machdep.c:1.82
--- src/sys/arch/powerpc/oea/oea_machdep.c:1.81	Mon Jul  6 10:34:23 2020
+++ src/sys/arch/powerpc/oea/oea_machdep.c	Sat Feb 27 01:16:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: oea_machdep.c,v 1.81 2020/07/06 10:34:23 rin Exp $	*/
+/*	$NetBSD: oea_machdep.c,v 1.82 2021/02/27 01:16:52 thorpej Exp $	*/
 
 /*
  * Copyright (C) 2002 Matt Thomas
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: oea_machdep.c,v 1.81 2020/07/06 10:34:23 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: oea_machdep.c,v 1.82 2021/02/27 01:16:52 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altivec.h"
@@ -480,7 +480,7 @@ oea_init(void (*handler)(void))
 }
 
 #ifdef PPC_OEA601
-void
+static void
 mpc601_ioseg_add(paddr_t pa, register_t len)
 {
 	const u_int i = pa >> ADDR_SR_SHFT;
@@ -531,6 +531,14 @@ oea_iobat_add(paddr_t pa, register_t len
 
 	KASSERT(len >= BAT_BL_8M);
 
+#ifdef PPC_OEA601
+	if (mfpvr() >> 16 == MPC601) {
+		/* Use I/O segments on the BAT-starved 601. */
+		mpc601_ioseg_add(pa, len);
+		return;
+	}
+#endif /* PPC_OEA601 */
+
 	/*
 	 * If the caller wanted a bigger BAT than the hardware supports,
 	 * split it into smaller BATs.
@@ -778,29 +786,15 @@ oea_batinit(paddr_t pa, ...)
 	 * registers were cleared above.
 	 */
 
-	va_start(ap, pa);
-
 	/*
 	 * Add any I/O BATs specificed;
-	 * use I/O segments on the BAT-starved 601.
 	 */
-#ifdef PPC_OEA601
-	if (cpuvers == MPC601) {
-		while (pa != 0) {
-			register_t len = va_arg(ap, register_t);
-			mpc601_ioseg_add(pa, len);
-			pa = va_arg(ap, paddr_t);
-		}
-	} else
-#endif
-	{
-		while (pa != 0) {
-			register_t len = va_arg(ap, register_t);
-			oea_iobat_add(pa, len);
-			pa = va_arg(ap, paddr_t);
-		}
+	va_start(ap, pa);
+	while (pa != 0) {
+		register_t len = va_arg(ap, register_t);
+		oea_iobat_add(pa, len);
+		pa = va_arg(ap, paddr_t);
 	}
-
 	va_end(ap);
 
 	/*



CVS commit: src/sys/arch/powerpc

2021-02-26 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb 26 21:15:20 UTC 2021

Modified Files:
src/sys/arch/powerpc/include/oea: cpufeat.h
src/sys/arch/powerpc/oea: cpu_subr.c

Log Message:
Split cpu_model_init() into cpu_features_probe() and cpu_features_enable()
so that early bootstrap can do those two steps independently, if needed.

Continue to provide a cpu_model_init() wrapper for now.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/powerpc/include/oea/cpufeat.h
cvs rdiff -u -r1.106 -r1.107 src/sys/arch/powerpc/oea/cpu_subr.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/powerpc/include/oea/cpufeat.h
diff -u src/sys/arch/powerpc/include/oea/cpufeat.h:1.5 src/sys/arch/powerpc/include/oea/cpufeat.h:1.6
--- src/sys/arch/powerpc/include/oea/cpufeat.h:1.5	Thu Mar 22 21:26:27 2018
+++ src/sys/arch/powerpc/include/oea/cpufeat.h	Fri Feb 26 21:15:20 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufeat.h,v 1.5 2018/03/22 21:26:27 macallan Exp $ */
+/* $NetBSD: cpufeat.h,v 1.6 2021/02/26 21:15:20 thorpej Exp $ */
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -30,7 +30,8 @@
 
 #ifndef _POWERPC_OEA_OEAFEAT_H_
 
-/* Cpu features for OEA Cpus.
+/*
+ * Cpu features for OEA Cpus.
  * These are only features that affect early bootstrap, and decisions
  * that need to be made very early on, like what pmap to use, if bats are
  * available, etc etc.  More can be added later. Some are not yet utilized.
@@ -48,7 +49,9 @@
 #define OEACPU_XBSEN		(1 << 7)	/* BATS > 256MB */
 
 #ifdef _KERNEL
-void cpu_model_init(void);
+void	cpu_features_probe(void);
+void	cpu_features_enable(void);
+void	cpu_model_init(void);
 extern unsigned long oeacpufeat;
 
 #define oea_mapiodev(addr, size) ((oeacpufeat & OEACPU_NOBAT) ? \

Index: src/sys/arch/powerpc/oea/cpu_subr.c
diff -u src/sys/arch/powerpc/oea/cpu_subr.c:1.106 src/sys/arch/powerpc/oea/cpu_subr.c:1.107
--- src/sys/arch/powerpc/oea/cpu_subr.c:1.106	Fri Feb 26 02:18:57 2021
+++ src/sys/arch/powerpc/oea/cpu_subr.c	Fri Feb 26 21:15:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu_subr.c,v 1.106 2021/02/26 02:18:57 thorpej Exp $	*/
+/*	$NetBSD: cpu_subr.c,v 1.107 2021/02/26 21:15:20 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2001 Matt Thomas.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.106 2021/02/26 02:18:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.107 2021/02/26 21:15:20 thorpej Exp $");
 
 #include "sysmon_envsys.h"
 
@@ -267,20 +267,22 @@ register_t cpu_pslusermask = 0x;
 
 unsigned long oeacpufeat;
 
-/* This is to be called from locore.S, and nowhere else. */
-
 void
-cpu_model_init(void)
+cpu_features_probe(void)
 {
+	static bool feature_probe_done;
+
 	u_int pvr, vers;
 
+	if (feature_probe_done) {
+		return;
+	}
+
 	pvr = mfpvr();
 	vers = pvr >> 16;
 
-	oeacpufeat = 0;
-
 	if ((vers >= IBMRS64II && vers <= IBM970GX) || vers == MPC620 ||
-		vers == IBMCELL || vers == IBMPOWER6P5) {
+	vers == IBMCELL || vers == IBMPOWER6P5) {
 		oeacpufeat |= OEACPU_64;
 		oeacpufeat |= OEACPU_64_BRIDGE;
 		oeacpufeat |= OEACPU_NOBAT;
@@ -289,22 +291,53 @@ cpu_model_init(void)
 		oeacpufeat |= OEACPU_601;
 
 	} else if (MPC745X_P(vers)) {
-		register_t hid1 = mfspr(SPR_HID1);
-
 		if (vers != MPC7450) {
-			register_t hid0 = mfspr(SPR_HID0);
-
 			/* Enable more SPRG registers */
 			oeacpufeat |= OEACPU_HIGHSPRG;
 
 			/* Enable more BAT registers */
 			oeacpufeat |= OEACPU_HIGHBAT;
-			hid0 |= HID0_HIGH_BAT_EN;
 
 			/* Enable larger BAT registers */
 			oeacpufeat |= OEACPU_XBSEN;
+		}
+
+	} else if (vers == IBM750FX || vers == IBM750GX) {
+		oeacpufeat |= OEACPU_HIGHBAT;
+	}
+
+	feature_probe_done = true;
+}
+
+void
+cpu_features_enable(void)
+{
+	static bool feature_enable_done;
+
+	if (feature_enable_done) {
+		return;
+	}
+
+	u_int pvr, vers;
+
+	pvr = mfpvr();
+	vers = pvr >> 16;
+
+	if (MPC745X_P(vers)) {
+		register_t hid0 = mfspr(SPR_HID0);
+		register_t hid1 = mfspr(SPR_HID1);
+
+		const register_t ohid0 = hid0;
+
+		if (oeacpufeat & OEACPU_HIGHBAT) {
+			hid0 |= HID0_HIGH_BAT_EN;
+		}
+
+		if (oeacpufeat & OEACPU_XBSEN) {
 			hid0 |= HID0_XBSEN;
+		}
 
+		if (hid0 != ohid0) {
 			mtspr(SPR_HID0, hid0);
 			__asm volatile("sync;isync");
 		}
@@ -314,10 +347,22 @@ cpu_model_init(void)
 
 		mtspr(SPR_HID1, hid1);
 		__asm volatile("sync;isync");
-
-	} else if (vers == IBM750FX || vers == IBM750GX) {
-		oeacpufeat |= OEACPU_HIGHBAT;
 	}
+
+	feature_enable_done = true;
+}
+
+/* This is to be called from locore.S, and nowhere else. */
+
+void
+cpu_model_init(void)
+{
+	/*
+	 * This is just a wrapper for backwards-compatibility, and will
+	 * probably be garbage-collected in the near future.
+	 */
+	cpu_features_probe();
+	cpu_features_enable();
 }
 
 void



CVS commit: src/sys/arch/powerpc/oea

2021-02-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Feb 24 17:35:40 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofw_subr.S

Log Message:
- Fix a comment.
- rename ofwsrsave to clsrsave; we're saving / restoring the client's
  (i.e. kernel's) SRs there, not the firmware's.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/powerpc/oea/ofw_subr.S

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/powerpc/oea/ofw_subr.S
diff -u src/sys/arch/powerpc/oea/ofw_subr.S:1.18 src/sys/arch/powerpc/oea/ofw_subr.S:1.19
--- src/sys/arch/powerpc/oea/ofw_subr.S:1.18	Wed Feb 24 16:53:00 2021
+++ src/sys/arch/powerpc/oea/ofw_subr.S	Wed Feb 24 17:35:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_subr.S,v 1.18 2021/02/24 16:53:00 thorpej Exp $	*/
+/*	$NetBSD: ofw_subr.S,v 1.19 2021/02/24 17:35:39 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -47,10 +47,10 @@
 	/* Entry trampoline used by openfirmware(). */
 	.lcomm	oftramp,4,4
 
-	/* OpenFirmware SR save area */
-	.lcomm	ofwsrsave,64,4
+	/* Client SR save area */
+	.lcomm	clsrsave,64,4
 
-	/* MSR and SPRG[0-3] used in OpenFirmware */
+	/* MSR used in OpenFirmware */
 	.globl	ofwmsr
 	.comm	ofwmsr,4,4
 
@@ -173,8 +173,8 @@ ENTRY_NOPROFILE(openfirmware_trampoline)
 	mtibatu	3,%r0
 #endif /* PPC_OEA */
 
-	lis	%r4,ofwsrsave@ha		/* save current SRs */
-	addi	%r4,%r4,ofwsrsave@l
+	lis	%r4,clsrsave@ha		/* save current SRs */
+	addi	%r4,%r4,clsrsave@l
 	li	%r5,0
 1:	mfsrin	%r0,%r5
 	stw	%r0,0(%r4)
@@ -215,8 +215,8 @@ ENTRY_NOPROFILE(openfirmware_trampoline)
 	addi	%r5,%r5,_C_LABEL(battable)@l
 	stw	%r5,CI_BATTABLE(%r4)
 
-	lis	%r4,ofwsrsave@ha	/* restore saved SRs */
-	addi	%r4,%r4,ofwsrsave@l
+	lis	%r4,clsrsave@ha		/* restore saved SRs */
+	addi	%r4,%r4,clsrsave@l
 	li	%r5,0
 1:	lwz	%r0,0(%r4)
 	mtsrin	%r0,%r5



CVS commit: src/sys/arch/powerpc/oea

2021-02-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Feb 24 16:53:00 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofw_subr.S ofwoea_machdep.c

Log Message:
Don't save the firmware's copy of SPRG[0-3], and don't fiddle with
SPRG[0-3] in the firmware trampoline.  Section 7.1 of the OpenFirmware
PowerPC CPU bindings says that firmware "client interface shall not modify"
when in virtual-mode, and "client interface shall preserve" in real-mode.

This is important because in vritual-mode, DSI exceptions will land in
the kernel's DSI exception handler, and that handler depends on the
kernel's SPRG0 value (it contains the pointer to the cpu_info for that
CPU).

Additionally, in the firmware trampoline, point curcpu at an empty
ofw_battable.  This ensures that the DSI exception handler won't
load a BAT register with a kernel block translation that clobbers
a segment translation owned by the firmware.  Eventually, this ofw_battable
might contain some of the larger translations owned by the firmware.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/powerpc/oea/ofw_subr.S
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/powerpc/oea/ofwoea_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/powerpc/oea/ofw_subr.S
diff -u src/sys/arch/powerpc/oea/ofw_subr.S:1.17 src/sys/arch/powerpc/oea/ofw_subr.S:1.18
--- src/sys/arch/powerpc/oea/ofw_subr.S:1.17	Fri Feb 19 18:03:21 2021
+++ src/sys/arch/powerpc/oea/ofw_subr.S	Wed Feb 24 16:53:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_subr.S,v 1.17 2021/02/19 18:03:21 thorpej Exp $	*/
+/*	$NetBSD: ofw_subr.S,v 1.18 2021/02/24 16:53:00 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -52,7 +52,7 @@
 
 	/* MSR and SPRG[0-3] used in OpenFirmware */
 	.globl	ofwmsr
-	.comm	ofwmsr,20,4
+	.comm	ofwmsr,4,4
 
 #ifdef FIRMWORKSBUGS
 	.lcomm	ofwreal_incharge,4,4
@@ -101,16 +101,7 @@ ENTRY_NOPROFILE(ofwinit)
 	/* Save the MSR that OpenFirmware is using. */
 	mfmsr	%r0
 	lis	%r9,ofwmsr@ha
-	stwu	%r0,ofwmsr@l(%r9)
-
-	mfsprg0	%r0/* save SPRGs */
-	stw	%r0,4(%r9)
-	mfsprg1	%r0
-	stw	%r0,8(%r9)
-	mfsprg2	%r0
-	stw	%r0,12(%r9)
-	mfsprg3	%r0
-	stw	%r0,16(%r9)
+	stw	%r0,ofwmsr@l(%r9)
 
 	lis	%r8,OF_buffer@ha
 	addi	%r8,%r8,OF_buffer@l
@@ -161,15 +152,6 @@ ENTRY_NOPROFILE(openfirmware_trampoline)
 	lwz	%r4,ofentry@l(%r4)
 	mtlr	%r4
 
-	mfsprg0	%r5			/* save current sprg0 (curcpu) */
-	stw	%r5,16(%r1)
-	mfsprg1	%r5			/* save current sprg1 */
-	stw	%r5,20(%r1)
-	mfsprg2	%r5			/* save current sprg1 */
-	stw	%r5,24(%r1)
-	mfsprg3	%r5			/* save current sprg3 */
-	stw	%r5,28(%r1)
-
 #ifdef FIRMWORKSBUGS
 	lis	%r4,ofwreal_incharge@ha
 	lwz	%r4,ofwreal_incharge@l(%r4)
@@ -214,21 +196,25 @@ ENTRY_NOPROFILE(openfirmware_trampoline)
 	cmpwi	%r5,0
 	bne	1b
 2:
-	lis	%r4,ofwmsr+16@ha	/* Open Firmware msr + sprg[0-3] */
-	lwzu	%r5,ofwmsr+16@l(%r4)
-	mtsprg3	%r5
-	lwz	%r5,-4(%r4)
-	mtsprg2	%r5
-	lwz	%r5,-8(%r4)
-	mtsprg1	%r5
-	lwz	%r5,-12(%r4)
-	mtsprg0	%r5
-	lwz	%r5,-16(%r4)
+	/* curcpu()->ci_battable = _battable */
+	GET_CPUINFO(%r4)
+	lis	%r5,_C_LABEL(ofw_battable)@ha
+	addi	%r5,%r5,_C_LABEL(ofw_battable)@l
+	stw	%r5,CI_BATTABLE(%r4)
+
+	lis	%r4,ofwmsr@ha		/* Open Firmware msr */
+	lwz	%r5,ofwmsr@l(%r4)
 	mtmsr	%r5
 	isync
 
 	blrl/* call Open Firmware */
 
+	/* curcpu()->ci_battable =  */
+	GET_CPUINFO(%r4)
+	lis	%r5,_C_LABEL(battable)@ha
+	addi	%r5,%r5,_C_LABEL(battable)@l
+	stw	%r5,CI_BATTABLE(%r4)
+
 	lis	%r4,ofwsrsave@ha	/* restore saved SRs */
 	addi	%r4,%r4,ofwsrsave@l
 	li	%r5,0
@@ -243,15 +229,6 @@ ENTRY_NOPROFILE(openfirmware_trampoline)
 	mtmsr	%r4
 	isync
 4:	
-	lwz	%r5,16(%r1)		/* restore saved sprgs (curcpu) */
-	mtsprg0	%r5
-	lwz	%r5,20(%r1)
-	mtsprg1	%r5
-	lwz	%r5,24(%r1)
-	mtsprg2	%r5
-	lwz	%r5,28(%r1)
-	mtsprg3	%r5
-
 	addi	%r1,%r1,48		/* pop stack frame and save area */
 	lwz	%r0,4(%r1)		/* return address */
 	mtlr	%r0

Index: src/sys/arch/powerpc/oea/ofwoea_machdep.c
diff -u src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.53 src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.54
--- src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.53	Fri Feb 19 18:10:51 2021
+++ src/sys/arch/powerpc/oea/ofwoea_machdep.c	Wed Feb 24 16:53:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofwoea_machdep.c,v 1.53 2021/02/19 18:10:51 thorpej Exp $ */
+/* $NetBSD: ofwoea_machdep.c,v 1.54 2021/02/24 16:53:00 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.53 2021/02/19 18:10:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.54 2021/02/24 16:53:00 thorpej Exp $");
 
 #include "ksyms.h"
 #include "wsdisplay.h"
@@ -100,7 +100,19 @@ typedef struct _rangemap {
 
 struct OF_translation ofw_translations[OFW_MAX_TRANSLATIONS];
 
+/*
+ * Data structures holding OpenFirmware's translations when running
+ * in virtual-mode.
+ *
+ * When we call 

CVS commit: src/sys/arch/powerpc

2021-02-24 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Feb 24 16:42:38 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: cpu.h
src/sys/arch/powerpc/oea: cpu_subr.c genassym.cf
src/sys/arch/powerpc/powerpc: trap_subr.S

Log Message:
Add a provision for a per-cpu battable.  Each CPU starts with the global
one, but this allows CPUs to temporarily switch to an alternate battable
if needed.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/arch/powerpc/include/cpu.h
cvs rdiff -u -r1.104 -r1.105 src/sys/arch/powerpc/oea/cpu_subr.c
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/powerpc/oea/genassym.cf
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/powerpc/powerpc/trap_subr.S

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/powerpc/include/cpu.h
diff -u src/sys/arch/powerpc/include/cpu.h:1.116 src/sys/arch/powerpc/include/cpu.h:1.117
--- src/sys/arch/powerpc/include/cpu.h:1.116	Wed Feb  3 10:37:05 2021
+++ src/sys/arch/powerpc/include/cpu.h	Wed Feb 24 16:42:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.116 2021/02/03 10:37:05 rin Exp $	*/
+/*	$NetBSD: cpu.h,v 1.117 2021/02/24 16:42:38 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1999 Wolfgang Solfrank.
@@ -94,6 +94,10 @@ struct cpu_info {
 	struct lwp *ci_onproc;		/* current user LWP / kthread */
 	struct pcb *ci_curpcb;
 	struct pmap *ci_curpm;
+#if defined(PPC_OEA) || defined(PPC_OEA601) || defined(PPC_OEA64) || \
+defined(PPC_OEA64_BRIDGE) || defined(MODULAR) || defined(_MODULE)
+	void *ci_battable;		/* BAT table in use by this CPU */
+#endif
 	struct lwp *ci_softlwps[SOFTINT_COUNT];
 	int ci_cpuid;			/* from SPR_PIR */
 

Index: src/sys/arch/powerpc/oea/cpu_subr.c
diff -u src/sys/arch/powerpc/oea/cpu_subr.c:1.104 src/sys/arch/powerpc/oea/cpu_subr.c:1.105
--- src/sys/arch/powerpc/oea/cpu_subr.c:1.104	Mon Jul  6 10:31:23 2020
+++ src/sys/arch/powerpc/oea/cpu_subr.c	Wed Feb 24 16:42:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu_subr.c,v 1.104 2020/07/06 10:31:23 rin Exp $	*/
+/*	$NetBSD: cpu_subr.c,v 1.105 2021/02/24 16:42:38 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2001 Matt Thomas.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.104 2020/07/06 10:31:23 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.105 2021/02/24 16:42:38 thorpej Exp $");
 
 #include "sysmon_envsys.h"
 
@@ -235,24 +235,27 @@ static const struct cputab models[] = {
 	{ "",		0,		REVFMT_HEX }
 };
 
+#include 
+extern struct bat battable[];
+
 #ifdef MULTIPROCESSOR
 struct cpu_info cpu_info[CPU_MAXNUM] = {
 [0] = {
 	.ci_curlwp = ,
+	.ci_battable = battable,
 },
 };
 volatile struct cpu_hatch_data *cpu_hatch_data;
 volatile int cpu_hatch_stack;
 #define HATCH_STACK_SIZE 0x1000
 extern int ticks_per_intr;
-#include 
 #include 
 #include 
-extern struct bat battable[];
 #else
 struct cpu_info cpu_info[1] = {
 [0] = {
 	.ci_curlwp = ,
+	.ci_battable = battable,
 },
 };
 #endif /*MULTIPROCESSOR*/
@@ -1329,6 +1332,7 @@ cpu_spinup(device_t self, struct cpu_inf
 	ci->ci_curlwp = ci->ci_data.cpu_idlelwp;
 	ci->ci_curpcb = lwp_getpcb(ci->ci_curlwp);
 	ci->ci_curpm = ci->ci_curpcb->pcb_pm;
+	ci->ci_battable = battable;
 
 	cpu_hatch_data = h;
 	h->hatch_running = 0;

Index: src/sys/arch/powerpc/oea/genassym.cf
diff -u src/sys/arch/powerpc/oea/genassym.cf:1.28 src/sys/arch/powerpc/oea/genassym.cf:1.29
--- src/sys/arch/powerpc/oea/genassym.cf:1.28	Mon Jul  6 09:34:17 2020
+++ src/sys/arch/powerpc/oea/genassym.cf	Wed Feb 24 16:42:38 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: genassym.cf,v 1.28 2020/07/06 09:34:17 rin Exp $
+#	$NetBSD: genassym.cf,v 1.29 2021/02/24 16:42:38 thorpej Exp $
 
 #
 # Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -66,6 +66,7 @@ define	PM_USRSR	offsetof(struct pmap, pm
 define	PM_KERNELSR	offsetof(struct pmap, pm_sr[KERNEL_SR])
 endif
 
+define	CI_BATTABLE	offsetof(struct cpu_info, ci_battable)
 define	CI_TEMPSAVE	offsetof(struct cpu_info, ci_savearea[CI_SAVETEMP])
 define	CI_DDBSAVE	offsetof(struct cpu_info, ci_savearea[CI_SAVEDDB])
 define	CI_DISISAVE	offsetof(struct cpu_info, ci_savearea[CI_SAVEMMU])

Index: src/sys/arch/powerpc/powerpc/trap_subr.S
diff -u src/sys/arch/powerpc/powerpc/trap_subr.S:1.84 src/sys/arch/powerpc/powerpc/trap_subr.S:1.85
--- src/sys/arch/powerpc/powerpc/trap_subr.S:1.84	Sun Jul 12 21:18:01 2020
+++ src/sys/arch/powerpc/powerpc/trap_subr.S	Wed Feb 24 16:42:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap_subr.S,v 1.84 2020/07/12 21:18:01 rin Exp $	*/
+/*	$NetBSD: trap_subr.S,v 1.85 2021/02/24 16:42:38 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -268,14 +268,20 @@ _C_LABEL(dsitrap):
 	rlwinm	%r31,%r31,3+(32-BAT_ADDR_SHIFT),BAT_ADDR_SHIFT-3,28
 	/* get segment * 8 */
 
+	/* Get address of this CPU's current battable */
+	GET_CPUINFO(%r30)
+	ldreg	%r30,CI_BATTABLE(%r30)
+
+	/* Add offset to the slot we care about. */
+	add	%r31,%r31,%r30
+
 	

CVS commit: src/sys/arch/powerpc/powerpc

2021-02-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Feb 20 01:57:54 UTC 2021

Modified Files:
src/sys/arch/powerpc/powerpc: ofw_machdep.c

Log Message:
Query real-mode? at startup and cache the result.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/powerpc/powerpc/ofw_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/powerpc/powerpc/ofw_machdep.c
diff -u src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.28 src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.29
--- src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.28	Fri Feb 19 05:21:39 2021
+++ src/sys/arch/powerpc/powerpc/ofw_machdep.c	Sat Feb 20 01:57:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_machdep.c,v 1.28 2021/02/19 05:21:39 thorpej Exp $	*/
+/*	$NetBSD: ofw_machdep.c,v 1.29 2021/02/20 01:57:54 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2021 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.28 2021/02/19 05:21:39 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.29 2021/02/20 01:57:54 thorpej Exp $");
 
 #include 
 #include 
@@ -91,6 +91,8 @@ __KERNEL_RCSID(0, "$NetBSD: ofw_machdep.
 int	ofw_root;
 int	ofw_chosen;
 
+bool	ofw_real_mode;
+
 /*
  * Bootstrap console support functions.
  */
@@ -411,6 +413,21 @@ ofw_bootstrap_get_translations(void)
 	}
 }
 
+static bool
+ofw_option_truefalse(const char *prop, int proplen)
+{
+	/* These are all supposed to be strings. */
+	switch (prop[0]) {
+	case 'y':
+	case 'Y':
+	case 't':
+	case 'T':
+	case '1':
+		return true;
+	}
+	return false;
+}
+
 /*
  * Called from ofwinit() very early in bootstrap.  We are still
  * running on the stack provided by OpenFirmware and in the same
@@ -421,6 +438,9 @@ ofw_bootstrap_get_translations(void)
 void
 ofw_bootstrap(void)
 {
+	char prop[32];
+	int handle, proplen;
+
 	/* Stash the handles for "/" and "/chosen" for convenience later. */
 	ofw_root = OF_finddevice("/");
 	ofw_chosen = OF_finddevice("/chosen");
@@ -428,6 +448,19 @@ ofw_bootstrap(void)
 	/* Initialize the early bootstrap console. */
 	ofw_bootstrap_console();
 
+	/* Check to see if we're running in real-mode. */
+	handle = OF_finddevice("/options");
+	if (handle != -1) {
+		proplen = OF_getprop(handle, "real-mode?", prop, sizeof(prop));
+		if (proplen > 0) {
+			ofw_real_mode = ofw_option_truefalse(prop, proplen);
+		} else {
+			ofw_real_mode = false;
+		}
+	}
+	aprint_normal("OpenFirmware running in %s-mode\n",
+	ofw_real_mode ? "real" : "virtual");
+
 	/* Get #address-cells and #size-cells to fething memory info. */
 	if (OF_getprop(ofw_root, "#address-cells", _address_cells,
 		   sizeof(ofw_address_cells)) <= 0)



CVS commit: src/sys/arch/powerpc/oea

2021-02-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb 19 18:10:51 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofwoea_machdep.c

Log Message:
Update some #ifdef PMAC_G5 for previous change that I missed before.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/arch/powerpc/oea/ofwoea_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/powerpc/oea/ofwoea_machdep.c
diff -u src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.52 src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.53
--- src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.52	Fri Feb 19 05:21:39 2021
+++ src/sys/arch/powerpc/oea/ofwoea_machdep.c	Fri Feb 19 18:10:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofwoea_machdep.c,v 1.52 2021/02/19 05:21:39 thorpej Exp $ */
+/* $NetBSD: ofwoea_machdep.c,v 1.53 2021/02/19 18:10:51 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.52 2021/02/19 05:21:39 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.53 2021/02/19 18:10:51 thorpej Exp $");
 
 #include "ksyms.h"
 #include "wsdisplay.h"
@@ -242,6 +242,7 @@ ofwoea_initppc(u_int startkernel, u_int 
 	if (oeacpufeat & OEACPU_64_BRIDGE) {
 		vaddr_t va;
 		paddr_t pa;
+		vsize_t size;
 		int i;
 
 		pmap_setup_segment0_map(0, msgbuf_paddr, msgbuf_paddr,
@@ -249,12 +250,22 @@ ofwoea_initppc(u_int startkernel, u_int 
 
 		/* Map OFW code+data */
 
-		for (i = 0; i < ofmaplen / sizeof(struct ofw_translations); i++) {
-			if (ofmap[i].va < 0xff80)
+		for (i = 0; i < __arraycount(ofw_translations); i++) {
+			va = ofw_translations[i].virt;
+			size = ofw_translations[i].size;
+			pa = ofw_translations[i].phys;
+			/* XXX mode */
+
+			if (size == 0) {
+/* No more, all done! */
+break;
+			}
+
+			if (va < 0xff80)
 continue;
 
-			for (va = ofmap[i].va, pa = ofmap[i].pa;
-			va < ofmap[i].va + ofmap[i].len;
+
+			for (; va < (ofw_translations[i].virt + size);
 			va += PAGE_SIZE, pa += PAGE_SIZE) {
 pmap_enter(pmap_kernel(), va, pa, VM_PROT_ALL,
 VM_PROT_ALL | PMAP_WIRED);



CVS commit: src/sys/arch/powerpc/oea

2021-02-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb 19 18:05:42 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofw_consinit.c

Log Message:
Fix the previously differently.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/powerpc/oea/ofw_consinit.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/powerpc/oea/ofw_consinit.c
diff -u src/sys/arch/powerpc/oea/ofw_consinit.c:1.22 src/sys/arch/powerpc/oea/ofw_consinit.c:1.23
--- src/sys/arch/powerpc/oea/ofw_consinit.c:1.22	Fri Feb 19 17:58:43 2021
+++ src/sys/arch/powerpc/oea/ofw_consinit.c	Fri Feb 19 18:05:42 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_consinit.c,v 1.22 2021/02/19 17:58:43 thorpej Exp $ */
+/* $NetBSD: ofw_consinit.c,v 1.23 2021/02/19 18:05:42 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.22 2021/02/19 17:58:43 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.23 2021/02/19 18:05:42 thorpej Exp $");
 
 #include "adb.h"
 #include "adbkbd.h"
@@ -137,10 +137,9 @@ cninit(void)
 #ifdef PMAC_G5
 		/* The MMU hasn't been initialized yet, use failsafe for now */
 		extern struct consdev failsafe_cons;
-		struct consdev *cp = _cons;
-		cn_tab = cp;
-		(*cp->cn_probe)(cp);
-		(*cp->cn_init)(cp);
+		cn_tab = _cons;
+		(*cn_tab->cn_probe)(cn_tab);
+		(*cn_tab->cn_init)(cn_tab);
 		aprint_verbose("Early G5 console initialized\n");
 		return;
 #endif /* PMAC_G5 */
@@ -148,10 +147,9 @@ cninit(void)
 #if (NZSTTY > 0) && !defined(MAMBO)
 		OF_getprop(console_node, "name", name, sizeof(name));
 		if (strcmp(name, "ch-a") == 0 || strcmp(name, "ch-b") == 0) {
-			struct consdev *cp = _zs;
-			(*cp->cn_probe)(cp);
-			(*cp->cn_init)(cp);
-			cn_tab = cp;
+			cn_tab = _zs;
+			(*cn_tab->cn_probe)(cn_tab);
+			(*cn_tab->cn_init)(cn_tab);
 		}
 		return;
 #endif /* NZTTY */



CVS commit: src/sys/arch/powerpc/oea

2021-02-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb 19 18:03:21 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofw_subr.S

Log Message:
ofwreal_incharge does not need to be global.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/powerpc/oea/ofw_subr.S

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/powerpc/oea/ofw_subr.S
diff -u src/sys/arch/powerpc/oea/ofw_subr.S:1.16 src/sys/arch/powerpc/oea/ofw_subr.S:1.17
--- src/sys/arch/powerpc/oea/ofw_subr.S:1.16	Fri Feb 19 18:02:45 2021
+++ src/sys/arch/powerpc/oea/ofw_subr.S	Fri Feb 19 18:03:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_subr.S,v 1.16 2021/02/19 18:02:45 thorpej Exp $	*/
+/*	$NetBSD: ofw_subr.S,v 1.17 2021/02/19 18:03:21 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -55,7 +55,7 @@
 	.comm	ofwmsr,20,4
 
 #ifdef FIRMWORKSBUGS
-	.comm	ofwreal_incharge,4,4
+	.lcomm	ofwreal_incharge,4,4
 #endif
 
 /*



CVS commit: src/sys/arch/powerpc/oea

2021-02-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb 19 18:02:45 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofw_subr.S

Log Message:
Put back accidental removal of "ofwreal_incharge".


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/powerpc/oea/ofw_subr.S

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/powerpc/oea/ofw_subr.S
diff -u src/sys/arch/powerpc/oea/ofw_subr.S:1.15 src/sys/arch/powerpc/oea/ofw_subr.S:1.16
--- src/sys/arch/powerpc/oea/ofw_subr.S:1.15	Thu Feb 18 18:31:22 2021
+++ src/sys/arch/powerpc/oea/ofw_subr.S	Fri Feb 19 18:02:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_subr.S,v 1.15 2021/02/18 18:31:22 thorpej Exp $	*/
+/*	$NetBSD: ofw_subr.S,v 1.16 2021/02/19 18:02:45 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -54,6 +54,10 @@
 	.globl	ofwmsr
 	.comm	ofwmsr,20,4
 
+#ifdef FIRMWORKSBUGS
+	.comm	ofwreal_incharge,4,4
+#endif
+
 /*
  * Called by start to save the initial OFW state so we can restore it
  * when call back to OFW.



CVS commit: src/sys/arch/powerpc/oea

2021-02-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb 19 17:58:43 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofw_consinit.c

Log Message:
Avoid an unused variable warning for the not-building-macppc case.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/powerpc/oea/ofw_consinit.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/powerpc/oea/ofw_consinit.c
diff -u src/sys/arch/powerpc/oea/ofw_consinit.c:1.21 src/sys/arch/powerpc/oea/ofw_consinit.c:1.22
--- src/sys/arch/powerpc/oea/ofw_consinit.c:1.21	Fri Feb 19 05:23:53 2021
+++ src/sys/arch/powerpc/oea/ofw_consinit.c	Fri Feb 19 17:58:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_consinit.c,v 1.21 2021/02/19 05:23:53 thorpej Exp $ */
+/* $NetBSD: ofw_consinit.c,v 1.22 2021/02/19 17:58:43 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.21 2021/02/19 05:23:53 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.22 2021/02/19 17:58:43 thorpej Exp $");
 
 #include "adb.h"
 #include "adbkbd.h"
@@ -134,12 +134,10 @@ cninit(void)
 	OFPRINTF("console type: %s\n", name);
 
 	if (strcmp(name, "serial") == 0) {
-		struct consdev *cp;
-
 #ifdef PMAC_G5
 		/* The MMU hasn't been initialized yet, use failsafe for now */
 		extern struct consdev failsafe_cons;
-		cp = _cons;
+		struct consdev *cp = _cons;
 		cn_tab = cp;
 		(*cp->cn_probe)(cp);
 		(*cp->cn_init)(cp);
@@ -150,7 +148,7 @@ cninit(void)
 #if (NZSTTY > 0) && !defined(MAMBO)
 		OF_getprop(console_node, "name", name, sizeof(name));
 		if (strcmp(name, "ch-a") == 0 || strcmp(name, "ch-b") == 0) {
-			cp = _zs;
+			struct consdev *cp = _zs;
 			(*cp->cn_probe)(cp);
 			(*cp->cn_init)(cp);
 			cn_tab = cp;



CVS commit: src/sys/arch/powerpc/oea

2021-02-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb 19 05:23:53 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofw_consinit.c

Log Message:
Revert unintended change.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/powerpc/oea/ofw_consinit.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/powerpc/oea/ofw_consinit.c
diff -u src/sys/arch/powerpc/oea/ofw_consinit.c:1.20 src/sys/arch/powerpc/oea/ofw_consinit.c:1.21
--- src/sys/arch/powerpc/oea/ofw_consinit.c:1.20	Fri Feb 19 05:21:39 2021
+++ src/sys/arch/powerpc/oea/ofw_consinit.c	Fri Feb 19 05:23:53 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_consinit.c,v 1.20 2021/02/19 05:21:39 thorpej Exp $ */
+/* $NetBSD: ofw_consinit.c,v 1.21 2021/02/19 05:23:53 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.20 2021/02/19 05:21:39 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.21 2021/02/19 05:23:53 thorpej Exp $");
 
 #include "adb.h"
 #include "adbkbd.h"
@@ -124,7 +124,7 @@ cninit(void)
 
 	OFPRINTF("console node: %08x\n", console_node);
 
-	if (console_node <= 0)
+	if (console_node == -1)
 		goto nocons;
 
 	memset(name, 0, sizeof(name));



CVS commit: src/sys/arch/powerpc

2021-02-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb 19 05:21:39 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: ofw_machdep.h
src/sys/arch/powerpc/oea: ofw_consinit.c ofwoea_machdep.c
src/sys/arch/powerpc/powerpc: ofw_machdep.c

Log Message:
Shuffle around a couple of things that aren't particularly OEA-specific:

- Early bootstrap console initialization moves to ofw_machdep.c, and
  is called a bit earlier, from ofw_bootstrap().

- Decoding the "translations" property from /chosen/mmu is specified
  in the general OpenFirmware PowerPC bindings, and is not specific to
  any particular PowerPC flavor.  It's now decoded a bit earlier in
  ofw_bootstrap().

The *interpretation* of the mode field of a translation is, however,
implementation-specific, so that remains in ofwoea_machdep.c.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/powerpc/include/ofw_machdep.h
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/powerpc/oea/ofw_consinit.c
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/powerpc/oea/ofwoea_machdep.c
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/powerpc/powerpc/ofw_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/powerpc/include/ofw_machdep.h
diff -u src/sys/arch/powerpc/include/ofw_machdep.h:1.1 src/sys/arch/powerpc/include/ofw_machdep.h:1.2
--- src/sys/arch/powerpc/include/ofw_machdep.h:1.1	Thu Feb 18 18:31:22 2021
+++ src/sys/arch/powerpc/include/ofw_machdep.h	Fri Feb 19 05:21:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_machdep.h,v 1.1 2021/02/18 18:31:22 thorpej Exp $ */
+/* $NetBSD: ofw_machdep.h,v 1.2 2021/02/19 05:21:39 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -32,6 +32,31 @@
 #ifdef _KERNEL
 #include 
 
+/*
+ * The general format of an OpenFirmware virtual translation record is:
+ *
+ *	cell(s)		virt
+ *	cell(s)		size
+ *	cell(s)		phys
+ *	cell		mode
+ *
+ * "mode" contains PTE WIMG bits.
+ *
+ * We define this structure to describe these translations that's independent
+ * of the number of cells each field consumes.
+ */
+struct OF_translation {
+	vaddr_t		virt;
+	vsize_t		size;
+	paddr_t		phys;
+	uint32_t	mode;
+};
+
+#define	OFW_MAX_TRANSLATIONS	32
+
+extern int ofw_chosen;		/* cached handle for "/chosen" */
+extern struct OF_translation ofw_translations[OFW_MAX_TRANSLATIONS];
+
 void	ofw_bootstrap(void);
 #endif /* _KERNEL */
 

Index: src/sys/arch/powerpc/oea/ofw_consinit.c
diff -u src/sys/arch/powerpc/oea/ofw_consinit.c:1.19 src/sys/arch/powerpc/oea/ofw_consinit.c:1.20
--- src/sys/arch/powerpc/oea/ofw_consinit.c:1.19	Mon Jul  6 09:34:17 2020
+++ src/sys/arch/powerpc/oea/ofw_consinit.c	Fri Feb 19 05:21:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_consinit.c,v 1.19 2020/07/06 09:34:17 rin Exp $ */
+/* $NetBSD: ofw_consinit.c,v 1.20 2021/02/19 05:21:39 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.19 2020/07/06 09:34:17 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.20 2021/02/19 05:21:39 thorpej Exp $");
 
 #include "adb.h"
 #include "adbkbd.h"
@@ -54,6 +54,7 @@ __KERNEL_RCSID(0, "$NetBSD: ofw_consinit
 #include 
 
 #include 
+#include 
 
 #include 
 #include 
@@ -88,26 +89,14 @@ extern struct consdev consdev_zs;
 #include 
 #endif
 
-int console_node = 0, console_instance = 0;
+extern int console_node, console_instance;
 
-int chosen, stdin, stdout;
 int ofkbd_ihandle;
 
 static void cninit_kd(void);
-static void ofwoea_bootstrap_console(void);
-static int ofwbootcons_cngetc(dev_t);
-static void ofwbootcons_cnputc(dev_t, int);
 
 /*#define OFDEBUG*/
 
-struct consdev consdev_ofwbootcons = {
-	NULL, NULL,
-	ofwbootcons_cngetc,
-	ofwbootcons_cnputc,
-	nullcnpollc,
-	NULL, NULL, NULL, NODEV, CN_INTERNAL,
-};
-
 #ifdef OFDEBUG
 void ofprint(const char *, ...);
 
@@ -133,11 +122,9 @@ cninit(void)
 {
 	char name[32];
 
-	ofwoea_bootstrap_console();
-
 	OFPRINTF("console node: %08x\n", console_node);
 
-	if (console_node == -1)
+	if (console_node <= 0)
 		goto nocons;
 
 	memset(name, 0, sizeof(name));
@@ -171,9 +158,7 @@ cninit(void)
 		return;
 #endif /* NZTTY */
 
-		/* fallback to OFW boot console */
-		cp = _ofwbootcons;
-		cn_tab = cp;
+		/* fallback to OFW boot console (already set) */
 		return;
 	}
 	else
@@ -207,7 +192,7 @@ cninit_kd(void)
 	/*
 	 * We must determine which keyboard type we have.
 	 */
-	if (OF_getprop(chosen, "stdin", , sizeof(kstdin))
+	if (OF_getprop(ofw_chosen, "stdin", , sizeof(kstdin))
 	!= sizeof(kstdin)) {
 		printf("WARNING: no `stdin' property in /chosen\n");
 		return;
@@ -324,7 +309,7 @@ cninit_kd(void)
 	 */
 
 #if NUKBD > 0
-	if (OF_call_method("`usb-kbd-ihandles", stdin, 0, 1, ) >= 0 &&
+	if (OF_call_method("`usb-kbd-ihandles", kstdin, 0, 1, ) >= 0 &&
 	ukbds != NULL && ukbds->ihandle != 0 &&
 	

CVS commit: src/sys/arch/powerpc

2021-02-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Feb 18 18:31:22 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofw_subr.S
src/sys/arch/powerpc/powerpc: ofw_machdep.c
Added Files:
src/sys/arch/powerpc/include: ofw_machdep.h

Log Message:
Add an ofw_bootstrap() function, called during early bootstrap from
ofwinit() to perform additional early initialization in C code.  Use
this to get the memory config while we're still running in the OpenFirmware
client environment, rather than waiting until we've started fiddling with
the system state.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/powerpc/include/ofw_machdep.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/powerpc/oea/ofw_subr.S
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/powerpc/powerpc/ofw_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/powerpc/oea/ofw_subr.S
diff -u src/sys/arch/powerpc/oea/ofw_subr.S:1.14 src/sys/arch/powerpc/oea/ofw_subr.S:1.15
--- src/sys/arch/powerpc/oea/ofw_subr.S:1.14	Thu Feb 18 16:29:12 2021
+++ src/sys/arch/powerpc/oea/ofw_subr.S	Thu Feb 18 18:31:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_subr.S,v 1.14 2021/02/18 16:29:12 thorpej Exp $	*/
+/*	$NetBSD: ofw_subr.S,v 1.15 2021/02/18 18:31:22 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -113,7 +113,13 @@ ENTRY_NOPROFILE(ofwinit)
 	lis	%r9,_C_LABEL(OF_buf)@ha
 	stw	%r8,_C_LABEL(OF_buf)@l(%r9)
 
-	/* XXX Do other stuff in C code. */
+	/*
+	 * Call into C code to perform additional early initialization.
+	 */
+	lis	%r8,_C_LABEL(ofw_bootstrap)@ha
+	addi	%r8,%r8,_C_LABEL(ofw_bootstrap)@l
+	mtctr	%r8
+	bctrl
 
 	/*
 	 * Jump off the trampoline for all subsequent calls

Index: src/sys/arch/powerpc/powerpc/ofw_machdep.c
diff -u src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.26 src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.27
--- src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.26	Wed Jan 27 03:17:24 2021
+++ src/sys/arch/powerpc/powerpc/ofw_machdep.c	Thu Feb 18 18:31:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_machdep.c,v 1.26 2021/01/27 03:17:24 thorpej Exp $	*/
+/*	$NetBSD: ofw_machdep.c,v 1.27 2021/02/18 18:31:22 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.26 2021/01/27 03:17:24 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.27 2021/02/18 18:31:22 thorpej Exp $");
 
 #include 
 #include 
@@ -50,6 +50,8 @@ __KERNEL_RCSID(0, "$NetBSD: ofw_machdep.
 #include 
 #include 
 
+#include 
+
 #ifdef DEBUG
 #define DPRINTF aprint_error
 #else
@@ -59,15 +61,8 @@ __KERNEL_RCSID(0, "$NetBSD: ofw_machdep.
 #define	OFMEM_REGIONS	32
 static struct mem_region OFmem[OFMEM_REGIONS + 1], OFavail[OFMEM_REGIONS + 3];
 
-/*
- * This is called during initppc, before the system is really initialized.
- * It shall provide the total and the available regions of RAM.
- * Both lists must have a zero-size entry as terminator.
- * The available regions need not take the kernel into account, but needs
- * to provide space for two additional entry beyond the terminating one.
- */
-void
-mem_regions(struct mem_region **memp, struct mem_region **availp)
+static void
+ofw_bootstrap_get_memory(void)
 {
 	const char *macrisc[] = {"MacRISC", "MacRISC2", "MacRISC4", NULL};
 	int hroot, hmem, i, cnt, memcnt, regcnt, acells, scells;
@@ -225,8 +220,6 @@ mem_regions(struct mem_region **memp, st
 		}
 	}
 
-	*memp = OFmem;
-	*availp = OFavail;
 	return;
 
 error:
@@ -239,14 +232,40 @@ error:
 	OFavail[0].start = 0x3000;
 	OFavail[0].size = 0x2000 - 0x3000;
 
-	*memp = OFmem;
-	*availp = OFavail;
 #else
 	panic("no memory?");
 #endif
 	return;
 }
 
+/*
+ * Called from ofwinit() very early in bootstrap.  We are still
+ * running on the stack provided by OpenFirmware and in the same
+ * OpenFirmware client environment as the boot loader.  Our calls
+ * to OpenFirmware are direct, and not via the trampoline that
+ * saves / restores kernel state.
+ */
+void
+ofw_bootstrap(void)
+{
+	/* Get the system memory configuration. */
+	ofw_bootstrap_get_memory();
+}
+
+/*
+ * This is called during initppc, before the system is really initialized.
+ * It shall provide the total and the available regions of RAM.
+ * Both lists must have a zero-size entry as terminator.
+ * The available regions need not take the kernel into account, but needs
+ * to provide space for two additional entry beyond the terminating one.
+ */
+void
+mem_regions(struct mem_region **memp, struct mem_region **availp)
+{
+	*memp = OFmem;
+	*availp = OFavail;
+}
+
 void
 ppc_exit(void)
 {

Added files:

Index: src/sys/arch/powerpc/include/ofw_machdep.h
diff -u /dev/null src/sys/arch/powerpc/include/ofw_machdep.h:1.1
--- /dev/null	Thu Feb 18 18:31:22 2021
+++ src/sys/arch/powerpc/include/ofw_machdep.h	Thu Feb 18 18:31:22 2021
@@ -0,0 +1,38 @@
+/* $NetBSD: 

CVS commit: src/sys/arch/powerpc/oea

2021-02-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Feb 18 16:29:12 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofw_subr.S

Log Message:
- Tidy up some comments.
- Use correct stack frame linkage everywhere so that if something goes
  wrong, we can get a meaningful back trace.
- Use an additional layer of indirection so that, when we're very
  early in bootstrap, we can just call OpenFirmware directly, rather
  than using our trampoline that saves/restores kernel state.
- Carve out a space for ofwinit() to call into C code to do additional
  initialization.  (This is not done yet.)


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/powerpc/oea/ofw_subr.S

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/powerpc/oea/ofw_subr.S
diff -u src/sys/arch/powerpc/oea/ofw_subr.S:1.13 src/sys/arch/powerpc/oea/ofw_subr.S:1.14
--- src/sys/arch/powerpc/oea/ofw_subr.S:1.13	Sat Feb 13 01:48:33 2021
+++ src/sys/arch/powerpc/oea/ofw_subr.S	Thu Feb 18 16:29:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_subr.S,v 1.13 2021/02/13 01:48:33 thorpej Exp $	*/
+/*	$NetBSD: ofw_subr.S,v 1.14 2021/02/18 16:29:12 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -35,25 +35,43 @@
 #include "opt_ppcarch.h"
 #endif
 
-	.local	firmstk
-	.globl	openfirmware_entry
-	.globl	ofwmsr
-	.local	ofwsrsave
-	.local	OF_buffer
-
+	/* Stack used to call into OpenFirmware. */
 	.lcomm	firmstk,NBPG,16
+
+	/* Buffer used to pass data to/from OpenFirmware. */
 	.lcomm	OF_buffer,NBPG + 36,4
-	.comm	openfirmware_entry,4,4	/* openfirmware entry point */
-	.lcomm	ofwsrsave,64,4		/* openfirmware SR savearea */
-	.comm	ofwmsr,20,4		/* msr & sprg[0-3] used in OF */
-	.comm	ofwreal_incharge,4,4
+
+	/* The OpenFirmware entry point, provided by OpenFirmware. */
+	.lcomm	ofentry,4,4
+
+	/* Entry trampoline used by openfirmware(). */
+	.lcomm	oftramp,4,4
+
+	/* OpenFirmware SR save area */
+	.lcomm	ofwsrsave,64,4
+
+	/* MSR and SPRG[0-3] used in OpenFirmware */
+	.globl	ofwmsr
+	.comm	ofwmsr,20,4
 
 /*
  * Called by start to save the initial OFW state so we can restore it
  * when call back to OFW.
+ *
+ * We expect the registers to be as for the entry point into the kernel:
+ *
+ *	%r1	Stack provided by OpenFirmware / boot loader
+ *	%r5	OpenFirmware client entry point
+ *
+ * (others -- don't care)
  */
 ENTRY_NOPROFILE(ofwinit)
-#ifdef	FIRMWORKSBUGS
+	/* Save return address, Push a stack frame. */
+	mflr	%r0
+	stw	%r0,4(%r1)
+	stwu	%r1,-16(%r1)
+
+#ifdef FIRMWORKSBUGS
 	mfmsr	%r0
 	andi.	%r0,%r0,PSL_IR|PSL_DR
 	beq	1f
@@ -62,25 +80,24 @@ ENTRY_NOPROFILE(ofwinit)
 	lis	%r9,ofwreal_incharge@ha
 	stw	%r8,ofwreal_incharge@l(%r9)
 
-	mflr	%r30
 	bl	_C_LABEL(ofwr_init)
-	mtlr	%r30
 1:
 #endif
-	lis	%r8,openfirmware_entry@ha
-	stw	%r5,openfirmware_entry@l(%r8) /* save client interface handler*/
 
+	lis	%r8,ofentry@ha
+	stw	%r5,ofentry@l(%r8)	/* save client interface handler */
+
+	/*
+	 * Call directly into OpenFirmware until we're ready to use
+	 * the trampoline.
+	 */
+	lis	%r8,oftramp@ha
+	stw	%r5,oftramp@l(%r8)
+
+	/* Save the MSR that OpenFirmware is using. */
 	mfmsr	%r0
-/*
- * XXX
- * doing this here instead of later on in ofwoea_initppc() after setting
- * up the console and such makes my PowerBook 3400c hang.
- * Probably just another OF 2.0 weirdness
- */
-	/*li	%r8,PSL_IP*/
-	/*andc	%r0,%r0,%r8*/			/* make sure PSL_IP is off */
 	lis	%r9,ofwmsr@ha
-	stwu	%r0,ofwmsr@l(%r9)		/* save initial MSR value */
+	stwu	%r0,ofwmsr@l(%r9)
 
 	mfsprg0	%r0/* save SPRGs */
 	stw	%r0,4(%r9)
@@ -96,28 +113,42 @@ ENTRY_NOPROFILE(ofwinit)
 	lis	%r9,_C_LABEL(OF_buf)@ha
 	stw	%r8,_C_LABEL(OF_buf)@l(%r9)
 
+	/* XXX Do other stuff in C code. */
+
+	/*
+	 * Jump off the trampoline for all subsequent calls
+	 * into OpenFirmware.
+	 */
+	lis	%r5,_C_LABEL(openfirmware_trampoline)@ha
+	addi	%r5,%r5,_C_LABEL(openfirmware_trampoline)@l
+	lis	%r8,oftramp@ha
+	stw	%r5,oftramp@l(%r8)
+
+	/* Retrieve LR, pop stack frame. */
+	addi	%r1,%r1,16
+	lwz	%r0,4(%r1)
+	mtlr	%r0
+
 	blr
 
 /*
- * OpenFirmware entry point
+ * OpenFirmware trampoline.  We are already on the OpenFirmware stack.
  */
-	.text
-ENTRY(openfirmware)
+ENTRY_NOPROFILE(openfirmware_trampoline)
 	mflr	%r0
 	stw	%r0,4(%r1)		/* save return address */
 
 	/*
-	 * Switch to OpenFirmware stack.
+	 * Push stack frame and save area:
 	 *
-	 * -48 == -16 to stack old SP and align, -32 for save area
+	 * [SP+8 save area]
+	 * [SP+4 slot for saved LR in callee]
+	 * [SP+0 saved SP]
 	 */
-	lis	%r7,firmstk+NBPG-48@ha
-	addi	%r7,%r7,firmstk+NBPG-48@l
-	stw	%r1,32(%r7)		/* stash away prev stack pointer */
-	mr	%r1,%r7
+	stwu	%r1,-48(%r1)
 
-	lis	%r4,openfirmware_entry@ha	/* get firmware entry point */
-	lwz	%r4,openfirmware_entry@l(%r4)
+	lis	%r4,ofentry@ha		/* get firmware entry point */
+	lwz	%r4,ofentry@l(%r4)
 	mtlr	%r4
 
 	mfsprg0	%r5			/* save current sprg0 

CVS commit: src/sys/arch/powerpc

2021-02-12 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Feb 13 01:48:33 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofw_subr.S
src/sys/arch/powerpc/powerpc: openfirm.c

Log Message:
- Don't change to the OFW stack in C code; instead, switch to the OFW
  stack in the openfirmware() wrapper itself.  Inspired by a similar
  change in OpenBSD designed to appease clang.
- The OF_*() entry firmware interfaces use several global resources;
  protect those global resources with a __cpu_simple_lock_t.
- Make ofbcopy() static -- it's no longer referenced outside openfirm.c


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/powerpc/oea/ofw_subr.S
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/powerpc/powerpc/openfirm.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/powerpc/oea/ofw_subr.S
diff -u src/sys/arch/powerpc/oea/ofw_subr.S:1.12 src/sys/arch/powerpc/oea/ofw_subr.S:1.13
--- src/sys/arch/powerpc/oea/ofw_subr.S:1.12	Mon Jul  6 10:31:23 2020
+++ src/sys/arch/powerpc/oea/ofw_subr.S	Sat Feb 13 01:48:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_subr.S,v 1.12 2020/07/06 10:31:23 rin Exp $	*/
+/*	$NetBSD: ofw_subr.S,v 1.13 2021/02/13 01:48:33 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -103,9 +103,18 @@ ENTRY_NOPROFILE(ofwinit)
  */
 	.text
 ENTRY(openfirmware)
-	mflr	%r0			/* save return address */
-	stw	%r0,4(%r1)
-	stwu	%r1,-32(%r1)		/* setup stack frame */
+	mflr	%r0
+	stw	%r0,4(%r1)		/* save return address */
+
+	/*
+	 * Switch to OpenFirmware stack.
+	 *
+	 * -48 == -16 to stack old SP and align, -32 for save area
+	 */
+	lis	%r7,firmstk+NBPG-48@ha
+	addi	%r7,%r7,firmstk+NBPG-48@l
+	stw	%r1,32(%r7)		/* stash away prev stack pointer */
+	mr	%r1,%r7
 
 	lis	%r4,openfirmware_entry@ha	/* get firmware entry point */
 	lwz	%r4,openfirmware_entry@l(%r4)
@@ -202,77 +211,7 @@ ENTRY(openfirmware)
 	lwz	%r5,28(%r1)
 	mtsprg3	%r5
 
-	lwz	%r1,0(%r1)		/* and return */
-	lwz	%r0,4(%r1)
-	mtlr	%r0
-	blr
-
-/*
- * Switch to/from OpenFirmware real mode stack
- *
- * Note: has to be called as the very first thing in OpenFirmware interface
- * routines.
- * E.g.:
- * int
- * OF_xxx(arg1, arg2)
- * type arg1, arg2;
- * {
- *	static struct {
- *		char *name;
- *		int nargs;
- *		int nreturns;
- *		char *method;
- *		int arg1;
- *		int arg2;
- *		int ret;
- *	} args = {
- *		"xxx",
- *		2,
- *		1,
- *	};
- *
- *	ofw_stack();
- *	args.arg1 = arg1;
- *	args.arg2 = arg2;
- *	if (openfirmware() < 0)
- *		return -1;
- *	return args.ret;
- * }
- */
-
-ENTRY(ofw_stack)
-	mfmsr	%r8			/* turn off interrupts */
-	andi.	%r0,%r8,~(PSL_EE|PSL_RI)@l
-	mtmsr	%r0
-	stw	%r8,4(%r1)		/* abuse return address slot */
-
-	lwz	%r5,0(%r1)		/* get length of stack frame */
-	subf	%r5,%r1,%r5
-
-	lis	%r7,firmstk+NBPG-8@ha
-	addi	%r7,%r7,firmstk+NBPG-8@l
-	lis	%r6,ofw_back@ha
-	addi	%r6,%r6,ofw_back@l
-	subf	%r4,%r5,%r7		/* make room for stack frame on
-	   new stack */
-	stw	%r6,-4(%r7)		/* setup return pointer */
-	stwu	%r1,-8(%r7)
-
-	stw	%r7,-8(%r4)
-
-	addi	%r3,%r1,8
-	addi	%r1,%r4,-8
-	subi	%r5,%r5,8
-
-	b	_C_LABEL(ofbcopy)	/* and copy it */
-
-ofw_back:
-	lwz	%r1,0(%r1)		/* get callers original stack pointer */
-
-	lwz	%r0,4(%r1)		/* get saved msr from abused slot */
-	mtmsr	%r0
-
-	lwz	%r1,0(%r1)		/* return */
-	lwz	%r0,4(%r1)
+	lwz	%r1,32(%r1)		/* restore previous stack pointer */
+	lwz	%r0,4(%r1)		/* return address */
 	mtlr	%r0
 	blr

Index: src/sys/arch/powerpc/powerpc/openfirm.c
diff -u src/sys/arch/powerpc/powerpc/openfirm.c:1.32 src/sys/arch/powerpc/powerpc/openfirm.c:1.33
--- src/sys/arch/powerpc/powerpc/openfirm.c:1.32	Fri Feb  5 00:06:11 2021
+++ src/sys/arch/powerpc/powerpc/openfirm.c	Sat Feb 13 01:48:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: openfirm.c,v 1.32 2021/02/05 00:06:11 thorpej Exp $	*/
+/*	$NetBSD: openfirm.c,v 1.33 2021/02/13 01:48:33 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: openfirm.c,v 1.32 2021/02/05 00:06:11 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: openfirm.c,v 1.33 2021/02/13 01:48:33 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_multiprocessor.h"
@@ -50,11 +50,37 @@ __KERNEL_RCSID(0, "$NetBSD: openfirm.c,v
 
 char *OF_buf;
 
-void ofw_stack(void);
-void ofbcopy(const void *, void *, size_t);
+static void ofbcopy(const void *, void *, size_t);
+
 #ifdef MULTIPROCESSOR
 void OF_start_cpu(int, u_int, int);
-#endif
+
+
+static __cpu_simple_lock_t ofw_mutex = __SIMPLELOCK_UNLOCKED;
+#endif /* MULTIPROCESSOR */
+
+static inline register_t
+ofw_lock(void)
+{
+	const register_t s = mfmsr();
+
+	mtmsr(s & ~(PSL_EE|PSL_RI));	/* disable interrupts */
+
+#ifdef MULTIPROCESSOR
+	__cpu_simple_lock(_mutex);
+#endif /* MULTIPROCESSOR */
+
+	return s;
+}
+
+static inline void
+ofw_unlock(register_t s)
+{
+#ifdef MULTIPROCESSOR
+	__cpu_simple_unlock(_mutex);

CVS commit: src/sys/arch/powerpc/oea

2021-02-12 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb 12 23:40:02 UTC 2021

Modified Files:
src/sys/arch/powerpc/oea: ofwoea_machdep.c

Log Message:
Add some comments to help visually track the nested #ifdef blocks in
ofwoea_batinit().


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/powerpc/oea/ofwoea_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/powerpc/oea/ofwoea_machdep.c
diff -u src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.50 src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.51
--- src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.50	Tue Jul  7 02:33:54 2020
+++ src/sys/arch/powerpc/oea/ofwoea_machdep.c	Fri Feb 12 23:40:02 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofwoea_machdep.c,v 1.50 2020/07/07 02:33:54 rin Exp $ */
+/* $NetBSD: ofwoea_machdep.c,v 1.51 2021/02/12 23:40:02 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.50 2020/07/07 02:33:54 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.51 2021/02/12 23:40:02 thorpej Exp $");
 
 #include "ksyms.h"
 #include "wsdisplay.h"
@@ -510,7 +510,7 @@ ofwoea_batinit(void)
 		0xf000, BAT_BL_256M,
 		0);
 	else
-#endif
+#endif /* PPC_OEA601 */
 	/*
 	 * map to bats
 	 */
@@ -519,7 +519,7 @@ ofwoea_batinit(void)
 		0xf800, BAT_BL_64M,
 		0xfe00, BAT_BL_8M,	/* Grackle IO */
 		0);
-#else
+#else /* ! macppc */
 	uint16_t bitmap;
 	int node, i;
 
@@ -537,7 +537,7 @@ ofwoea_batinit(void)
 			DPRINTF("Batmapped 256M at 0x%x\n", 0x1000 * i);
 		}
 	}
-#endif
+#endif /* macppc */
 #endif /* OEA */
 }
 



CVS commit: src/sys/arch/powerpc/powerpc

2021-02-04 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb  5 00:06:12 UTC 2021

Modified Files:
src/sys/arch/powerpc/powerpc: openfirm.c

Log Message:
s/bootspec/bstr/g to avoid shadowing a global.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/powerpc/powerpc/openfirm.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/powerpc/powerpc/openfirm.c
diff -u src/sys/arch/powerpc/powerpc/openfirm.c:1.31 src/sys/arch/powerpc/powerpc/openfirm.c:1.32
--- src/sys/arch/powerpc/powerpc/openfirm.c:1.31	Mon Jul  6 09:34:18 2020
+++ src/sys/arch/powerpc/powerpc/openfirm.c	Fri Feb  5 00:06:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: openfirm.c,v 1.31 2020/07/06 09:34:18 rin Exp $	*/
+/*	$NetBSD: openfirm.c,v 1.32 2021/02/05 00:06:11 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: openfirm.c,v 1.31 2020/07/06 09:34:18 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: openfirm.c,v 1.32 2021/02/05 00:06:11 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_multiprocessor.h"
@@ -603,7 +603,7 @@ OF_start_cpu(int phandle, u_int pc, int 
 #endif
 
 void
-OF_boot(const char *bootspec)
+OF_boot(const char *bstr)
 {
 	static struct {
 		const char *name;
@@ -617,10 +617,10 @@ OF_boot(const char *bootspec)
 	};
 	int l;
 
-	if ((l = strlen(bootspec)) >= PAGE_SIZE)
+	if ((l = strlen(bstr)) >= PAGE_SIZE)
 		panic("OF_boot");
 	ofw_stack();
-	ofbcopy(bootspec, OF_buf, l + 1);
+	ofbcopy(bstr, OF_buf, l + 1);
 	args.bootspec = OF_buf;
 	openfirmware();
 	panic("OF_boot didn't");



CVS commit: src/sys/arch/powerpc/include

2021-02-03 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Feb  3 10:37:05 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: cpu.h

Log Message:
Pull out constant definitions inside struct declaration.

Enable CTASSERT(9) for CPUSAVE_SIZE.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/powerpc/include/cpu.h

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/powerpc/include/cpu.h
diff -u src/sys/arch/powerpc/include/cpu.h:1.115 src/sys/arch/powerpc/include/cpu.h:1.116
--- src/sys/arch/powerpc/include/cpu.h:1.115	Wed Jul 15 08:58:51 2020
+++ src/sys/arch/powerpc/include/cpu.h	Wed Feb  3 10:37:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.115 2020/07/15 08:58:51 rin Exp $	*/
+/*	$NetBSD: cpu.h,v 1.116 2021/02/03 10:37:05 rin Exp $	*/
 
 /*
  * Copyright (C) 1999 Wolfgang Solfrank.
@@ -60,6 +60,31 @@ struct cache_info {
 
 #include 
 
+#ifdef _KERNEL
+#define	CI_SAVETEMP	(0*CPUSAVE_LEN)
+#define	CI_SAVEDDB	(1*CPUSAVE_LEN)
+#define	CI_SAVEIPKDB	(2*CPUSAVE_LEN)	/* obsolete */
+#define	CI_SAVEMMU	(3*CPUSAVE_LEN)
+#define	CI_SAVEMAX	(4*CPUSAVE_LEN)
+#define	CPUSAVE_LEN	8
+#if defined(PPC_BOOKE) && !defined(MODULAR) && !defined(_MODULE)
+#define	CPUSAVE_SIZE	128
+#else
+#define	CPUSAVE_SIZE	(CI_SAVEMAX*CPUSAVE_LEN)
+CTASSERT(CPUSAVE_SIZE >= 128);
+#endif
+#define	CPUSAVE_R28	0		/* where r28 gets saved */
+#define	CPUSAVE_R29	1		/* where r29 gets saved */
+#define	CPUSAVE_R30	2		/* where r30 gets saved */
+#define	CPUSAVE_R31	3		/* where r31 gets saved */
+#define	CPUSAVE_DEAR	4		/* where IBM4XX SPR_DEAR gets saved */
+#define	CPUSAVE_DAR	4		/* where OEA SPR_DAR gets saved */
+#define	CPUSAVE_ESR	5		/* where IBM4XX SPR_ESR gets saved */
+#define	CPUSAVE_DSISR	5		/* where OEA SPR_DSISR gets saved */
+#define	CPUSAVE_SRR0	6		/* where SRR0 gets saved */
+#define	CPUSAVE_SRR1	7		/* where SRR1 gets saved */
+#endif /* _KERNEL */
+
 struct cpu_info {
 	struct cpu_data ci_data;	/* MI per-cpu data */
 #ifdef _KERNEL
@@ -92,28 +117,7 @@ struct cpu_info {
 #if defined(PPC_IBM4XX) || defined(MODULAR) || defined(_MODULE)
 	char *ci_intstk;
 #endif
-#define	CI_SAVETEMP	(0*CPUSAVE_LEN)
-#define	CI_SAVEDDB	(1*CPUSAVE_LEN)
-#define	CI_SAVEIPKDB	(2*CPUSAVE_LEN)	/* obsolete */
-#define	CI_SAVEMMU	(3*CPUSAVE_LEN)
-#define	CI_SAVEMAX	(4*CPUSAVE_LEN)
-#define	CPUSAVE_LEN	8
-#if defined(PPC_BOOKE) && !defined(MODULAR) && !defined(_MODULE)
-#define	CPUSAVE_SIZE	128
-#else
-#define	CPUSAVE_SIZE	(CI_SAVEMAX*CPUSAVE_LEN)
-// XXX CTASSERT(CPUSAVE_SIZE >= 128);
-#endif
-#define	CPUSAVE_R28	0		/* where r28 gets saved */
-#define	CPUSAVE_R29	1		/* where r29 gets saved */
-#define	CPUSAVE_R30	2		/* where r30 gets saved */
-#define	CPUSAVE_R31	3		/* where r31 gets saved */
-#define	CPUSAVE_DEAR	4		/* where IBM4XX SPR_DEAR gets saved */
-#define	CPUSAVE_DAR	4		/* where OEA SPR_DAR gets saved */
-#define	CPUSAVE_ESR	5		/* where IBM4XX SPR_ESR gets saved */
-#define	CPUSAVE_DSISR	5		/* where OEA SPR_DSISR gets saved */
-#define	CPUSAVE_SRR0	6		/* where SRR0 gets saved */
-#define	CPUSAVE_SRR1	7		/* where SRR1 gets saved */
+
 	register_t ci_savearea[CPUSAVE_SIZE];
 #if defined(PPC_BOOKE) || defined(MODULAR) || defined(_MODULE)
 	uint32_t ci_pmap_asid_cur;



CVS commit: src/sys/arch/powerpc/powerpc

2021-01-26 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 27 03:17:24 UTC 2021

Modified Files:
src/sys/arch/powerpc/powerpc: ofw_machdep.c

Log Message:
There is not much point in of_compatible() returning -1 for "no match"
and >= 0 for "match".  Just make it return 0 for "no match" and >0 for
"match" so it can be treated like a boolean expression.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/powerpc/powerpc/ofw_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/powerpc/powerpc/ofw_machdep.c
diff -u src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.25 src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.26
--- src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.25	Fri Feb 28 05:44:39 2014
+++ src/sys/arch/powerpc/powerpc/ofw_machdep.c	Wed Jan 27 03:17:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_machdep.c,v 1.25 2014/02/28 05:44:39 matt Exp $	*/
+/*	$NetBSD: ofw_machdep.c,v 1.26 2021/01/27 03:17:24 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.25 2014/02/28 05:44:39 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.26 2021/01/27 03:17:24 thorpej Exp $");
 
 #include 
 #include 
@@ -151,7 +151,7 @@ mem_regions(struct mem_region **memp, st
 	 * according to comments in FreeBSD all Apple OF has 32bit values in
 	 * "available", no matter what the cell sizes are
 	 */
-	if (of_compatible(hroot, macrisc) != -1) {
+	if (of_compatible(hroot, macrisc)) {
 		DPRINTF("this appears to be a mac...\n");
 		acells = 1;
 		scells = 1;



CVS commit: src/sys/arch/powerpc/ibm4xx/dev

2021-01-23 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Jan 24 05:22:22 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx/dev: if_emac.c

Log Message:
Add rnd(9) support.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/powerpc/ibm4xx/dev/if_emac.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/powerpc/ibm4xx/dev/if_emac.c
diff -u src/sys/arch/powerpc/ibm4xx/dev/if_emac.c:1.53 src/sys/arch/powerpc/ibm4xx/dev/if_emac.c:1.54
--- src/sys/arch/powerpc/ibm4xx/dev/if_emac.c:1.53	Mon Jul  6 09:34:17 2020
+++ src/sys/arch/powerpc/ibm4xx/dev/if_emac.c	Sun Jan 24 05:22:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_emac.c,v 1.53 2020/07/06 09:34:17 rin Exp $	*/
+/*	$NetBSD: if_emac.c,v 1.54 2021/01/24 05:22:21 rin Exp $	*/
 
 /*
  * Copyright 2001, 2002 Wasabi Systems, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_emac.c,v 1.53 2020/07/06 09:34:17 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_emac.c,v 1.54 2021/01/24 05:22:21 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_emac.h"
@@ -67,6 +67,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_emac.c,v 
 #include 
 #include 
 
+#include 
+
 #include 		/* for PAGE_SIZE */
 
 #include 
@@ -210,6 +212,8 @@ struct emac_softc {
 
 	int sc_rxptr;			/* next ready RX descriptor/descsoft */
 
+	krndsource_t rnd_source;	/* random source */
+
 	void (*sc_rmii_enable)(device_t, int);		/* reduced MII enable */
 	void (*sc_rmii_disable)(device_t, int);		/* reduced MII disable*/
 	void (*sc_rmii_speed)(device_t, int, int);	/* reduced MII speed */
@@ -555,6 +559,9 @@ emac_attach(device_t parent, device_t se
 	if_deferred_start_init(ifp, NULL);
 	ether_ifattach(ifp, enaddr);
 
+	rnd_attach_source(>rnd_source, xname, RND_TYPE_NET,
+	RND_FLAG_DEFAULT);
+
 #ifdef EMAC_EVENT_COUNTERS
 	/*
 	 * Attach the event counters.
@@ -1254,13 +1261,14 @@ emac_txreap(struct emac_softc *sc)
 	struct ifnet *ifp = >sc_ethercom.ec_if;
 	struct emac_txsoft *txs;
 	int handled, i;
-	uint32_t txstat;
+	uint32_t txstat, count;
 
 	EMAC_EVCNT_INCR(>sc_ev_txreap);
 	handled = 0;
 
 	ifp->if_flags &= ~IFF_OACTIVE;
 
+	count = 0;
 	/*
 	 * Go through our Tx list and free mbufs for those
 	 * frames that have been transmitted.
@@ -1317,6 +1325,8 @@ emac_txreap(struct emac_softc *sc)
 		bus_dmamap_unload(sc->sc_dmat, txs->txs_dmamap);
 		m_freem(txs->txs_mbuf);
 		txs->txs_mbuf = NULL;
+
+		count++;
 	}
 
 	/* Update the dirty transmit buffer pointer. */
@@ -1329,6 +1339,9 @@ emac_txreap(struct emac_softc *sc)
 	if (sc->sc_txsfree == EMAC_TXQUEUELEN)
 		ifp->if_timer = 0;
 
+	if (count != 0)
+		rnd_add_uint32(>rnd_source, count);
+
 	return handled;
 }
 
@@ -1582,11 +1595,12 @@ emac_rxeob_intr(void *arg)
 	struct ifnet *ifp = >sc_ethercom.ec_if;
 	struct emac_rxsoft *rxs;
 	struct mbuf *m;
-	uint32_t rxstat;
+	uint32_t rxstat, count;
 	int i, len;
 
 	EMAC_EVCNT_INCR(>sc_ev_rxintr);
 
+	count = 0;
 	for (i = sc->sc_rxptr; ; i = EMAC_NEXTRX(i)) {
 		rxs = >sc_rxsoft[i];
 
@@ -1681,11 +1695,16 @@ emac_rxeob_intr(void *arg)
 
 		/* Pass it on. */
 		if_percpuq_enqueue(ifp->if_percpuq, m);
+
+		count++;
 	}
 
 	/* Update the receive pointer. */
 	sc->sc_rxptr = i;
 
+	if (count != 0)
+		rnd_add_uint32(>rnd_source, count);
+
 	return 1;
 }
 



CVS commit: src/sys/arch/powerpc/booke/dev

2021-01-23 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Jan 24 05:16:57 UTC 2021

Modified Files:
src/sys/arch/powerpc/booke/dev: pq3etsec.c

Log Message:
Add rnd(9) support.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/powerpc/booke/dev/pq3etsec.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/powerpc/booke/dev/pq3etsec.c
diff -u src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.51 src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.52
--- src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.51	Sun Jan 24 05:14:55 2021
+++ src/sys/arch/powerpc/booke/dev/pq3etsec.c	Sun Jan 24 05:16:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pq3etsec.c,v 1.51 2021/01/24 05:14:55 rin Exp $	*/
+/*	$NetBSD: pq3etsec.c,v 1.52 2021/01/24 05:16:56 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.51 2021/01/24 05:14:55 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.52 2021/01/24 05:16:56 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -58,6 +58,8 @@ __KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v
 #include 
 #include 
 
+#include 
+
 #include 
 #include 
 #include 
@@ -237,6 +239,8 @@ struct pq3etsec_softc {
 	int sc_ic_rx_count;
 	int sc_ic_tx_time;
 	int sc_ic_tx_count;
+
+	krndsource_t rnd_source;
 };
 
 #define	ETSEC_IC_RX_ENABLED(sc)		\
@@ -808,6 +812,9 @@ pq3etsec_attach(device_t parent, device_
 	if_deferred_start_init(ifp, NULL);
 	ether_ifattach(ifp, enaddr);
 
+	rnd_attach_source(>rnd_source, xname, RND_TYPE_NET,
+	RND_FLAG_DEFAULT);
+
 	pq3etsec_ifstop(ifp, true);
 
 	evcnt_attach_dynamic(>sc_ev_rx_stall, EVCNT_TYPE_MISC,
@@ -1714,6 +1721,9 @@ pq3etsec_rxq_consume(
 		KASSERT(rxq->rxq_mbufs[consumer - rxq->rxq_first] == rxq->rxq_mconsumer);
 #endif
 	}
+
+	if (rxconsumed != 0)
+		rnd_add_uint32(>rnd_source, rxconsumed);
 }
 
 static void
@@ -2261,6 +2271,9 @@ pq3etsec_txq_consume(
 			KASSERT(consumer < txq->txq_last);
 		}
 	}
+
+	if (txfree != 0)
+		rnd_add_uint32(>rnd_source, txfree);
 }
 
 static void



CVS commit: src/sys/arch/powerpc/booke/dev

2021-01-23 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Jan 24 05:14:55 UTC 2021

Modified Files:
src/sys/arch/powerpc/booke/dev: pq3etsec.c

Log Message:
Switch to if_percpuq_enqueue() from if_input().


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/arch/powerpc/booke/dev/pq3etsec.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/powerpc/booke/dev/pq3etsec.c
diff -u src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.50 src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.51
--- src/sys/arch/powerpc/booke/dev/pq3etsec.c:1.50	Mon Jul  6 09:34:16 2020
+++ src/sys/arch/powerpc/booke/dev/pq3etsec.c	Sun Jan 24 05:14:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pq3etsec.c,v 1.50 2020/07/06 09:34:16 rin Exp $	*/
+/*	$NetBSD: pq3etsec.c,v 1.51 2021/01/24 05:14:55 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.50 2020/07/06 09:34:16 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pq3etsec.c,v 1.51 2021/01/24 05:14:55 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -804,8 +804,9 @@ pq3etsec_attach(device_t parent, device_
 		goto fail_10;
 	}
 	pq3etsec_sysctl_setup(NULL, sc);
+	if_attach(ifp);
+	if_deferred_start_init(ifp, NULL);
 	ether_ifattach(ifp, enaddr);
-	if_register(ifp);
 
 	pq3etsec_ifstop(ifp, true);
 
@@ -1613,9 +1614,7 @@ pq3etsec_rx_input(
 	/*
 	 * Let's give it to the network subsystm to deal with.
 	 */
-	int s = splnet();
-	if_input(ifp, m);
-	splx(s);
+	if_percpuq_enqueue(ifp->if_percpuq, m);
 }
 
 static void



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-01-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Jan 18 04:35:05 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: clock.c

Log Message:
Invoke hardclock() and statclock() in the interrupt context.

Otherwise, entropy_enter() is used instead of entropy_enter_intr() in
statclock(), which results in KASSERT() failure.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/powerpc/ibm4xx/clock.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/powerpc/ibm4xx/clock.c
diff -u src/sys/arch/powerpc/ibm4xx/clock.c:1.30 src/sys/arch/powerpc/ibm4xx/clock.c:1.31
--- src/sys/arch/powerpc/ibm4xx/clock.c:1.30	Mon Jan 18 04:30:12 2021
+++ src/sys/arch/powerpc/ibm4xx/clock.c	Mon Jan 18 04:35:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.30 2021/01/18 04:30:12 rin Exp $	*/
+/*	$NetBSD: clock.c,v 1.31 2021/01/18 04:35:04 rin Exp $	*/
 /*  $OpenBSD: clock.c,v 1.3 1997/10/13 13:42:53 pefo Exp $  */
 
 /*
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.30 2021/01/18 04:30:12 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.31 2021/01/18 04:35:04 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ppcarch.h"
@@ -104,8 +104,11 @@ stat_intr(struct clockframe *frame)
 	 */
 	__asm volatile ("wrteei 1");
 
-	if (IPL_CLOCK > s)
+	if (IPL_CLOCK > s) {
+		ci->ci_idepth++;
   		statclock(frame);
+		ci->ci_idepth--;
+	}
 	splx(s);
 }
 
@@ -156,8 +159,10 @@ decr_intr(struct clockframe *frame)
 		/*
 		 * Do standard timer interrupt stuff.
 		 */
+		ci->ci_idepth++;
 		while (nticks-- > 0)
 			hardclock(frame);
+		ci->ci_idepth--;
 	}
 	splx(pcpl);
 }



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-01-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Jan 18 04:30:13 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: clock.c

Log Message:
Simplify and correct stale comment; nticks-th hardclock() had no longer
been special since rev 1.24:

http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/arch/powerpc/ibm4xx/clock.c#rev1.24

No functional changes intended.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/powerpc/ibm4xx/clock.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/powerpc/ibm4xx/clock.c
diff -u src/sys/arch/powerpc/ibm4xx/clock.c:1.29 src/sys/arch/powerpc/ibm4xx/clock.c:1.30
--- src/sys/arch/powerpc/ibm4xx/clock.c:1.29	Mon Jul  6 10:31:23 2020
+++ src/sys/arch/powerpc/ibm4xx/clock.c	Mon Jan 18 04:30:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.29 2020/07/06 10:31:23 rin Exp $	*/
+/*	$NetBSD: clock.c,v 1.30 2021/01/18 04:30:12 rin Exp $	*/
 /*  $OpenBSD: clock.c,v 1.3 1997/10/13 13:42:53 pefo Exp $  */
 
 /*
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.29 2020/07/06 10:31:23 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.30 2021/01/18 04:30:12 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ppcarch.h"
@@ -155,11 +155,9 @@ decr_intr(struct clockframe *frame)
 
 		/*
 		 * Do standard timer interrupt stuff.
-		 * Do softclock stuff only on the last iteration.
 		 */
-		while (--nticks > 0)
+		while (nticks-- > 0)
 			hardclock(frame);
-		hardclock(frame);
 	}
 	splx(pcpl);
 }



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-01-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Jan 18 02:43:27 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: ibm4xx_machdep.c

Log Message:
white space --> tab


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/powerpc/ibm4xx/ibm4xx_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/powerpc/ibm4xx/ibm4xx_machdep.c
diff -u src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c:1.33 src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c:1.34
--- src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c:1.33	Wed Jan  6 08:07:36 2021
+++ src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c	Mon Jan 18 02:43:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ibm4xx_machdep.c,v 1.33 2021/01/06 08:07:36 rin Exp $	*/
+/*	$NetBSD: ibm4xx_machdep.c,v 1.34 2021/01/18 02:43:27 rin Exp $	*/
 /*	Original: ibm40x_machdep.c,v 1.3 2005/01/17 17:19:36 shige Exp $ */
 
 /*
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ibm4xx_machdep.c,v 1.33 2021/01/06 08:07:36 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibm4xx_machdep.c,v 1.34 2021/01/18 02:43:27 rin Exp $");
 
 #include "ksyms.h"
 
@@ -208,7 +208,7 @@ ibm4xx_init(vaddr_t startkernel, vaddr_t
 	 * external interrupt handler install
 	 */
 	if (handler)
-	ibm4xx_install_extint(handler);
+		ibm4xx_install_extint(handler);
 
 	/*
 	 * Now enable translation (and machine checks/recoverable interrupts).



CVS commit: src/sys/arch/powerpc

2021-01-06 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jan  6 08:17:46 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: vmparam.h
src/sys/arch/powerpc/pci: pciconf_indirect.c pciconf_ofmethod.c

Log Message:
Drop unused headers. No functional changes intended.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/powerpc/include/vmparam.h
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/powerpc/pci/pciconf_indirect.c \
src/sys/arch/powerpc/pci/pciconf_ofmethod.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/powerpc/include/vmparam.h
diff -u src/sys/arch/powerpc/include/vmparam.h:1.24 src/sys/arch/powerpc/include/vmparam.h:1.25
--- src/sys/arch/powerpc/include/vmparam.h:1.24	Mon Jul  6 08:26:10 2020
+++ src/sys/arch/powerpc/include/vmparam.h	Wed Jan  6 08:17:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmparam.h,v 1.24 2020/07/06 08:26:10 rin Exp $	*/
+/*	$NetBSD: vmparam.h,v 1.25 2021/01/06 08:17:46 rin Exp $	*/
 
 #ifndef _POWERPC_VMPARAM_H_
 #define _POWERPC_VMPARAM_H_
@@ -6,7 +6,6 @@
 #ifdef _KERNEL_OPT
 #include "opt_modular.h"
 #include "opt_ppcarch.h"
-#include "opt_uvm.h"
 #endif
 
 /*

Index: src/sys/arch/powerpc/pci/pciconf_indirect.c
diff -u src/sys/arch/powerpc/pci/pciconf_indirect.c:1.6 src/sys/arch/powerpc/pci/pciconf_indirect.c:1.7
--- src/sys/arch/powerpc/pci/pciconf_indirect.c:1.6	Fri Oct  2 05:22:52 2015
+++ src/sys/arch/powerpc/pci/pciconf_indirect.c	Wed Jan  6 08:17:46 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pciconf_indirect.c,v 1.6 2015/10/02 05:22:52 msaitoh Exp $ */
+/* $NetBSD: pciconf_indirect.c,v 1.7 2021/01/06 08:17:46 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pciconf_indirect.c,v 1.6 2015/10/02 05:22:52 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pciconf_indirect.c,v 1.7 2021/01/06 08:17:46 rin Exp $");
 
 #define _POWERPC_BUS_DMA_PRIVATE
 
@@ -52,10 +52,6 @@ __KERNEL_RCSID(0, "$NetBSD: pciconf_indi
 
 #include 
 
-#if NISA > 0
-#include 
-#endif
-
 #include 
 #include 
 #include 
Index: src/sys/arch/powerpc/pci/pciconf_ofmethod.c
diff -u src/sys/arch/powerpc/pci/pciconf_ofmethod.c:1.6 src/sys/arch/powerpc/pci/pciconf_ofmethod.c:1.7
--- src/sys/arch/powerpc/pci/pciconf_ofmethod.c:1.6	Mon Jul  6 09:34:17 2020
+++ src/sys/arch/powerpc/pci/pciconf_ofmethod.c	Wed Jan  6 08:17:46 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pciconf_ofmethod.c,v 1.6 2020/07/06 09:34:17 rin Exp $ */
+/* $NetBSD: pciconf_ofmethod.c,v 1.7 2021/01/06 08:17:46 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 #define _POWERPC_BUS_DMA_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pciconf_ofmethod.c,v 1.6 2020/07/06 09:34:17 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pciconf_ofmethod.c,v 1.7 2021/01/06 08:17:46 rin Exp $");
 
 #include 
 #include 
@@ -55,10 +55,6 @@ __KERNEL_RCSID(0, "$NetBSD: pciconf_ofme
 #include 
 #include 
 
-#if NISA > 0
-#include 
-#endif
-
 #include 
 #include 
 #include 



CVS commit: src/sys/arch/powerpc/include

2021-01-06 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jan  6 08:14:35 UTC 2021

Modified Files:
src/sys/arch/powerpc/include: db_machdep.h

Log Message:
Switch DDB for powerpc/booke into SOFTWARE_SSTEP.

SR_SINGLESTEP aka PSL_SE bit in MSR is only available for oea, and HW
debug facilities for booke are significantly different from oea.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/powerpc/include/db_machdep.h

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/powerpc/include/db_machdep.h
diff -u src/sys/arch/powerpc/include/db_machdep.h:1.28 src/sys/arch/powerpc/include/db_machdep.h:1.29
--- src/sys/arch/powerpc/include/db_machdep.h:1.28	Mon Jul  6 09:34:17 2020
+++ src/sys/arch/powerpc/include/db_machdep.h	Wed Jan  6 08:14:34 2021
@@ -1,5 +1,5 @@
 /*	$OpenBSD: db_machdep.h,v 1.2 1997/03/21 00:48:48 niklas Exp $	*/
-/*	$NetBSD: db_machdep.h,v 1.28 2020/07/06 09:34:17 rin Exp $	*/
+/*	$NetBSD: db_machdep.h,v 1.29 2021/01/06 08:14:34 rin Exp $	*/
 
 /* 
  * Mach Operating System
@@ -71,8 +71,8 @@ extern	db_regs_t	ddb_regs;		/* register 
 #define	BKPT_SIZE	(4)		/* size of breakpoint inst */
 #define	BKPT_SET(inst, addr)	(BKPT_INST)
 
-#ifndef PPC_IBM4XX
-#define SR_SINGLESTEP	0x400
+#if !defined(PPC_BOOKE) && !defined(PPC_IBM4XX)
+#define	SR_SINGLESTEP	0x400		/* PSL_SE, available only for oea */
 #define	db_clear_single_step(regs)	((regs)->msr &= ~SR_SINGLESTEP)
 #define	db_set_single_step(regs)	((regs)->msr |=  SR_SINGLESTEP)
 #else



CVS commit: src/sys/arch/powerpc/ibm4xx

2021-01-06 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jan  6 08:07:36 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: ibm4xx_machdep.c

Log Message:
Sort headers. No functional changes intended.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/powerpc/ibm4xx/ibm4xx_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/powerpc/ibm4xx/ibm4xx_machdep.c
diff -u src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c:1.32 src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c:1.33
--- src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c:1.32	Mon Jul  6 13:10:19 2020
+++ src/sys/arch/powerpc/ibm4xx/ibm4xx_machdep.c	Wed Jan  6 08:07:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ibm4xx_machdep.c,v 1.32 2020/07/06 13:10:19 rin Exp $	*/
+/*	$NetBSD: ibm4xx_machdep.c,v 1.33 2021/01/06 08:07:36 rin Exp $	*/
 /*	Original: ibm40x_machdep.c,v 1.3 2005/01/17 17:19:36 shige Exp $ */
 
 /*
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ibm4xx_machdep.c,v 1.32 2020/07/06 13:10:19 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibm4xx_machdep.c,v 1.33 2021/01/06 08:07:36 rin Exp $");
 
 #include "ksyms.h"
 
@@ -79,10 +79,10 @@ __KERNEL_RCSID(0, "$NetBSD: ibm4xx_machd
 #endif
 
 #include 
-#include 
-#include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 
@@ -96,13 +96,13 @@ __KERNEL_RCSID(0, "$NetBSD: ibm4xx_machd
 #endif
 
 #include 
-#include 
 #include 
 
+#include 
 #include 
-#include 
 
 #include 
+#include 
 
 /*
  * Global variables used here and there



CVS commit: src/sys/arch/powerpc/booke

2021-01-06 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jan  6 08:04:58 UTC 2021

Modified Files:
src/sys/arch/powerpc/booke: trap.c

Log Message:
Sort headers. Also, use  instead of db_interface.h and
db_machdep.h in order not to be bothered by subtle include order.

No functional changes intended.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/powerpc/booke/trap.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/powerpc/booke/trap.c
diff -u src/sys/arch/powerpc/booke/trap.c:1.35 src/sys/arch/powerpc/booke/trap.c:1.36
--- src/sys/arch/powerpc/booke/trap.c:1.35	Thu Sep 10 02:45:28 2020
+++ src/sys/arch/powerpc/booke/trap.c	Wed Jan  6 08:04:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.35 2020/09/10 02:45:28 rin Exp $	*/
+/*	$NetBSD: trap.c,v 1.36 2021/01/06 08:04:57 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.35 2020/09/10 02:45:28 rin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.36 2021/01/06 08:04:57 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altivec.h"
@@ -43,34 +43,32 @@ __KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.3
 #endif
 
 #include 
-#include 
-#include 
-#include 
-#include 
 #include 
 #include 
+#include 
+#include 
 #include 
+#include 
+#include 
+
+#include 
 
 #include 
 
+#include 		/* use same interface for SPE */
+#include 
 #include 
-#include 
 #include 
-#include 
-#include 		/* use same interface for SPE */
-
 #include 
-#include 
-#include 
+#include 
+#include 
 
 #include 
 
-#include 
-#include 
-
-#include 
-#include 
+#include 
 #include 
+#include 
+#include 
 
 void trap(enum ppc_booke_exceptions, struct trapframe *);
 



CVS commit: src/sys/arch/powerpc/booke

2021-01-05 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jan  6 07:56:20 UTC 2021

Modified Files:
src/sys/arch/powerpc/booke: booke_pmap.c

Log Message:
Fix pmap_procwr() for powerpc/booke:

- Use PAGE_MASK, not PAGE_SIZE, to calculate page offset.
- Do not drop page offset of target address.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/powerpc/booke/booke_pmap.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/powerpc/booke/booke_pmap.c
diff -u src/sys/arch/powerpc/booke/booke_pmap.c:1.30 src/sys/arch/powerpc/booke/booke_pmap.c:1.31
--- src/sys/arch/powerpc/booke/booke_pmap.c:1.30	Sun Dec 20 16:38:25 2020
+++ src/sys/arch/powerpc/booke/booke_pmap.c	Wed Jan  6 07:56:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: booke_pmap.c,v 1.30 2020/12/20 16:38:25 skrll Exp $	*/
+/*	$NetBSD: booke_pmap.c,v 1.31 2021/01/06 07:56:19 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -37,7 +37,7 @@
 #define __PMAP_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: booke_pmap.c,v 1.30 2020/12/20 16:38:25 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: booke_pmap.c,v 1.31 2021/01/06 07:56:19 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_multiprocessor.h"
@@ -62,7 +62,7 @@ void
 pmap_procwr(struct proc *p, vaddr_t va, size_t len)
 {
 	struct pmap * const pmap = p->p_vmspace->vm_map.pmap;
-	vsize_t off = va & PAGE_SIZE;
+	vsize_t off = va & PAGE_MASK;
 
 	kpreempt_disable();
 	for (const vaddr_t eva = va + len; va < eva; off = 0) {
@@ -78,8 +78,8 @@ pmap_procwr(struct proc *p, vaddr_t va, 
 			continue;
 		}
 		kpreempt_enable();
-		dcache_wb(pte_to_paddr(pt_entry), segeva - va);
-		icache_inv(pte_to_paddr(pt_entry), segeva - va);
+		dcache_wb(pte_to_paddr(pt_entry) + off, segeva - va);
+		icache_inv(pte_to_paddr(pt_entry) + off, segeva - va);
 		kpreempt_disable();
 		va = segeva;
 	}



CVS commit: src/sys/arch/powerpc/booke/pci

2020-11-11 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Nov 12 00:44:22 UTC 2020

Modified Files:
src/sys/arch/powerpc/booke/pci: pq3pci.c

Log Message:
pq3pci_msi_claim(): remove KASSERT that is valid when allocating MSI
vectors, while apparently invalid when freeing them.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/powerpc/booke/pci/pq3pci.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/powerpc/booke/pci/pq3pci.c
diff -u src/sys/arch/powerpc/booke/pci/pq3pci.c:1.26 src/sys/arch/powerpc/booke/pci/pq3pci.c:1.27
--- src/sys/arch/powerpc/booke/pci/pq3pci.c:1.26	Thu Nov 12 00:37:51 2020
+++ src/sys/arch/powerpc/booke/pci/pq3pci.c	Thu Nov 12 00:44:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pq3pci.c,v 1.26 2020/11/12 00:37:51 rin Exp $	*/
+/*	$NetBSD: pq3pci.c,v 1.27 2020/11/12 00:44:22 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -39,7 +39,7 @@
 #define	__INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pq3pci.c,v 1.26 2020/11/12 00:37:51 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pq3pci.c,v 1.27 2020/11/12 00:44:22 rin Exp $");
 
 #include "locators.h"
 
@@ -1196,7 +1196,6 @@ pq3pci_msi_claim(pci_intr_handle_t handl
 	KASSERT(msig != NULL);
 	struct pq3pci_msihand * const msih = >msig_ihands[irq & 31];
 	mutex_spin_enter(>msig_lock);
-	KASSERT(msig->msig_free_mask & irq_mask);
 	msig->msig_free_mask ^= irq_mask;
 	mutex_spin_exit(>msig_lock);
 	return msih;



CVS commit: src/sys/arch/powerpc/booke/pci

2020-11-11 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Nov 12 00:37:51 UTC 2020

Modified Files:
src/sys/arch/powerpc/booke/pci: pq3pci.c

Log Message:
Oops, forget to commit local change necessary to support nvme(4) on RB800;
provide pci_intr_setattr(9) (no-op).


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/arch/powerpc/booke/pci/pq3pci.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/powerpc/booke/pci/pq3pci.c
diff -u src/sys/arch/powerpc/booke/pci/pq3pci.c:1.25 src/sys/arch/powerpc/booke/pci/pq3pci.c:1.26
--- src/sys/arch/powerpc/booke/pci/pq3pci.c:1.25	Tue Jul  7 03:38:48 2020
+++ src/sys/arch/powerpc/booke/pci/pq3pci.c	Thu Nov 12 00:37:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pq3pci.c,v 1.25 2020/07/07 03:38:48 thorpej Exp $	*/
+/*	$NetBSD: pq3pci.c,v 1.26 2020/11/12 00:37:51 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -39,7 +39,7 @@
 #define	__INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pq3pci.c,v 1.25 2020/07/07 03:38:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pq3pci.c,v 1.26 2020/11/12 00:37:51 rin Exp $");
 
 #include "locators.h"
 
@@ -1753,6 +1753,7 @@ pq3pci_pci_chipset_init(struct pq3pci_so
 	pc->pc_intr_type = pq3pci_intr_type;
 	pc->pc_intr_alloc = pq3pci_intr_alloc;
 	pc->pc_intr_release = pq3pci_intr_release;
+	pc->pc_intr_setattr = genppc_pci_intr_setattr;
 	pc->pc_intx_alloc = genppc_pci_intx_alloc;
 
 	pc->pc_msi_v = sc;



CVS commit: src/sys/arch/powerpc/powerpc

2020-10-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Oct 15 18:57:16 UTC 2020

Modified Files:
src/sys/arch/powerpc/powerpc: process_machdep.c

Log Message:
Add missing 'error' declaration


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/powerpc/powerpc/process_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/powerpc/powerpc/process_machdep.c
diff -u src/sys/arch/powerpc/powerpc/process_machdep.c:1.40 src/sys/arch/powerpc/powerpc/process_machdep.c:1.41
--- src/sys/arch/powerpc/powerpc/process_machdep.c:1.40	Thu Oct 15 17:37:36 2020
+++ src/sys/arch/powerpc/powerpc/process_machdep.c	Thu Oct 15 18:57:16 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: process_machdep.c,v 1.40 2020/10/15 17:37:36 mgorny Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.41 2020/10/15 18:57:16 martin Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.40 2020/10/15 17:37:36 mgorny Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.41 2020/10/15 18:57:16 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altivec.h"
@@ -193,7 +193,7 @@ ptrace_machdep_dorequest(struct lwp *l, 
 {
 	struct uio uio;
 	struct iovec iov;
-	int write = 0;
+	int write = 0, error;
 
 	switch (req) {
 	case PT_SETVECREGS:



CVS commit: src/sys/arch/powerpc/ibm4xx

2020-09-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Sep 10 04:36:24 UTC 2020

Modified Files:
src/sys/arch/powerpc/ibm4xx: pmap.c

Log Message:
Tiny cosmetic fix for previous. No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/arch/powerpc/ibm4xx/pmap.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/powerpc/ibm4xx/pmap.c
diff -u src/sys/arch/powerpc/ibm4xx/pmap.c:1.94 src/sys/arch/powerpc/ibm4xx/pmap.c:1.95
--- src/sys/arch/powerpc/ibm4xx/pmap.c:1.94	Thu Sep 10 04:31:55 2020
+++ src/sys/arch/powerpc/ibm4xx/pmap.c	Thu Sep 10 04:36:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.94 2020/09/10 04:31:55 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.95 2020/09/10 04:36:24 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.94 2020/09/10 04:31:55 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.95 2020/09/10 04:36:24 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1160,9 +1160,9 @@ pmap_deactivate(struct lwp *l)
 void
 pmap_procwr(struct proc *p, vaddr_t va, size_t len)
 {
+	struct pmap *pm = p->p_vmspace->vm_map.pmap;
 
 	if (__predict_true(p == curproc)) {
-		struct pmap *pm = p->p_vmspace->vm_map.pmap;
 		int msr, ctx, opid;
 
 		/*
@@ -1203,7 +1203,6 @@ pmap_procwr(struct proc *p, vaddr_t va, 
 			: "=" (msr), "=" (opid)
 			: "r" (ctx), "r" (va), "r" (len), "r" (CACHELINESIZE));
 	} else {
-		struct pmap *pm = p->p_vmspace->vm_map.pmap;
 		paddr_t pa;
 		vaddr_t tva, eva;
 		int tlen;



CVS commit: src/sys/arch/powerpc/ibm4xx

2020-09-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Sep 10 04:31:55 UTC 2020

Modified Files:
src/sys/arch/powerpc/ibm4xx: pmap.c

Log Message:
Real fix for pmap_procwr(), attempted in revs 1.85 and 1.87:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/arch/powerpc/ibm4xx/pmap.c#rev1.85
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/arch/powerpc/ibm4xx/pmap.c#rev1.87

ibm4xx has VIPT icache and operations in pmap_procwr() should be done with
DMMU enabled (write back dcache into memory and invalidate icache).

When p == curproc, this is trivial. However, p != curproc needs a special
care; we cannot rely upon TLB miss handler in user context. Therefore,
extract pa and operate against it.

Note that va below VM_MIN_KERNEL_ADDRESS (== 2GB at the moment) is reserved
for direct mapping.

Tested by gdb with WIP software single stepping for ibm4xx.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/arch/powerpc/ibm4xx/pmap.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/powerpc/ibm4xx/pmap.c
diff -u src/sys/arch/powerpc/ibm4xx/pmap.c:1.93 src/sys/arch/powerpc/ibm4xx/pmap.c:1.94
--- src/sys/arch/powerpc/ibm4xx/pmap.c:1.93	Thu Sep 10 03:32:46 2020
+++ src/sys/arch/powerpc/ibm4xx/pmap.c	Thu Sep 10 04:31:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.93 2020/09/10 03:32:46 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.94 2020/09/10 04:31:55 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.93 2020/09/10 03:32:46 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.94 2020/09/10 04:31:55 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1160,42 +1160,72 @@ pmap_deactivate(struct lwp *l)
 void
 pmap_procwr(struct proc *p, vaddr_t va, size_t len)
 {
-	struct pmap *pm = p->p_vmspace->vm_map.pmap;
-	int msr, ctx, opid, step;
 
-	step = CACHELINESIZE;
+	if (__predict_true(p == curproc)) {
+		struct pmap *pm = p->p_vmspace->vm_map.pmap;
+		int msr, ctx, opid;
 
-	/*
-	 * Need to turn off IMMU and switch to user context.
-	 * (icbi uses DMMU).
-	 */
-	if (!(ctx = pm->pm_ctx)) {
-		/* No context -- assign it one */
-		ctx_alloc(pm);
-		ctx = pm->pm_ctx;
-	}
-	__asm volatile(
-		"mfmsr %0;"
-		"li %1, %7;"
-		"andc %1,%0,%1;"
-		"mtmsr %1;"
-		"isync;"
-		"mfpid %1;"
-		"mtpid %2;"
-		"isync;"
+		/*
+		 * Take it easy! TLB miss handler takes care of us.
+		 */
+
+		/*
+	 	 * Need to turn off IMMU and switch to user context.
+		 * (icbi uses DMMU).
+		 */
+
+		if (!(ctx = pm->pm_ctx)) {
+			/* No context -- assign it one */
+			ctx_alloc(pm);
+			ctx = pm->pm_ctx;
+		}
+
+		__asm volatile(
+			"mfmsr %0;"
+			"li %1,0x20;"		/* Turn off IMMU */
+			"andc %1,%0,%1;"
+			"ori %1,%1,0x10;"	/* Turn on DMMU for sure */
+			"mtmsr %1;"
+			"isync;"
+			"mfpid %1;"
+			"mtpid %2;"
+			"isync;"
 		"1:"
-		"dcbst 0,%3;"
-		"icbi 0,%3;"
-		"add %3,%3,%5;"
-		"addc. %4,%4,%6;"
-		"bge 1b;"
-		"sync;"
-		"mtpid %1;"
-		"mtmsr %0;"
-		"isync;"
-		: "=" (msr), "=" (opid)
-		: "r" (ctx), "r" (va), "r" (len), "r" (step), "r" (-step),
-		  "K" (PSL_IR | PSL_DR));
+			"dcbst 0,%3;"
+			"icbi 0,%3;"
+			"add %3,%3,%5;"
+			"sub. %4,%4,%5;"
+			"bge 1b;"
+			"sync;"
+			"mtpid %1;"
+			"mtmsr %0;"
+			"isync;"
+			: "=" (msr), "=" (opid)
+			: "r" (ctx), "r" (va), "r" (len), "r" (CACHELINESIZE));
+	} else {
+		struct pmap *pm = p->p_vmspace->vm_map.pmap;
+		paddr_t pa;
+		vaddr_t tva, eva;
+		int tlen;
+
+		/*
+		 * For p != curproc, we cannot rely upon TLB miss handler in
+		 * user context. Therefore, extract pa and operate againt it.
+		 *
+		 * Note that va below VM_MIN_KERNEL_ADDRESS is reserved for
+		 * direct mapping.
+		 */
+
+		for (tva = va; len > 0; tva = eva, len -= tlen) {
+			eva = uimin(tva + len, trunc_page(tva + PAGE_SIZE));
+			tlen = eva - tva;
+			if (!pmap_extract(pm, tva, )) {
+/* XXX should be already unmapped */
+continue;
+			}
+			__syncicache((void *)pa, tlen);
+		}
+	}
 }
 
 static inline void



CVS commit: src/sys/arch/powerpc

2020-09-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Sep 10 03:32:46 UTC 2020

Modified Files:
src/sys/arch/powerpc/conf: files.powerpc
src/sys/arch/powerpc/ibm4xx: pmap.c

Log Message:
Introduce PMAP_TLBDEBUG option for ibm4xx: clear only TLBHI[V] bit when
TLB entry is invalidated, instead of clearing entire TLBHI register.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/arch/powerpc/conf/files.powerpc
cvs rdiff -u -r1.92 -r1.93 src/sys/arch/powerpc/ibm4xx/pmap.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/powerpc/conf/files.powerpc
diff -u src/sys/arch/powerpc/conf/files.powerpc:1.94 src/sys/arch/powerpc/conf/files.powerpc:1.95
--- src/sys/arch/powerpc/conf/files.powerpc:1.94	Tue Jun 30 16:20:01 2020
+++ src/sys/arch/powerpc/conf/files.powerpc	Thu Sep 10 03:32:46 2020
@@ -1,11 +1,11 @@
-#	$NetBSD: files.powerpc,v 1.94 2020/06/30 16:20:01 maxv Exp $
+#	$NetBSD: files.powerpc,v 1.95 2020/09/10 03:32:46 rin Exp $
 
 defflag	opt_altivec.h	ALTIVEC K_ALTIVEC PPC_HAVE_SPE
 defflag	opt_openpic.h	OPENPIC_DISTRIBUTE
 defparam opt_ppcparam.h	L2CR_CONFIG L3CR_CONFIG INTSTK CLOCKBASE VERBOSE_INITPPC
 defflag	opt_ppcarch.h	PPC_OEA PPC_OEA601 PPC_OEA64 PPC_OEA64_BRIDGE PPC_MPC8XX PPC_IBM4XX PPC_IBM403 PPC_IBM440 PPC_BOOKE
 defflag opt_ppccache.h	CACHE_PROTO_MEI
-defflag opt_pmap.h	PMAPDEBUG PMAPCHECK PMAPCOUNTERS PMAP_MINIMALTLB
+defflag opt_pmap.h	PMAPDEBUG PMAPCHECK PMAPCOUNTERS PMAP_MINIMALTLB PMAP_TLBDEBUG
 defparam opt_pmap.h	PTEGCOUNT PMAP_MEMLIMIT
 
 file	arch/powerpc/powerpc/core_machdep.c		coredump

Index: src/sys/arch/powerpc/ibm4xx/pmap.c
diff -u src/sys/arch/powerpc/ibm4xx/pmap.c:1.92 src/sys/arch/powerpc/ibm4xx/pmap.c:1.93
--- src/sys/arch/powerpc/ibm4xx/pmap.c:1.92	Thu Sep 10 03:23:55 2020
+++ src/sys/arch/powerpc/ibm4xx/pmap.c	Thu Sep 10 03:32:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.92 2020/09/10 03:23:55 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.93 2020/09/10 03:32:46 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,10 +67,11 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.92 2020/09/10 03:23:55 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.93 2020/09/10 03:32:46 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
+#include "opt_pmap.h"
 #endif
 
 #include 
@@ -193,6 +194,8 @@ static inline int pte_enter(struct pmap 
 static inline int pmap_enter_pv(struct pmap *, vaddr_t, paddr_t, int);
 static void pmap_remove_pv(struct pmap *, vaddr_t, paddr_t);
 
+static inline void tlb_invalidate_entry(int);
+
 static int ppc4xx_tlb_size_mask(size_t, int *, int *);
 
 
@@ -1195,6 +1198,43 @@ pmap_procwr(struct proc *p, vaddr_t va, 
 		  "K" (PSL_IR | PSL_DR));
 }
 
+static inline void
+tlb_invalidate_entry(int i)
+{
+#ifdef PMAP_TLBDEBUG
+	/*
+	 * Clear only TLBHI[V] bit so that we can track invalidated entry.
+	 */
+	register_t msr, pid, hi;
+
+	KASSERT(mfspr(SPR_PID) == KERNEL_PID);
+
+	__asm volatile(
+		"mfmsr	%0;"
+		"li	%1,0;"
+		"mtmsr	%1;"
+		"mfpid	%1;"
+		"tlbre	%2,%3,0;"
+		"andc	%2,%2,%4;"
+		"tlbwe	%2,%3,0;"
+		"mtpid	%1;"
+		"mtmsr	%0;"
+		"isync;"
+		: "=" (msr), "=" (pid), "=" (hi)
+		: "r" (i), "r" (TLB_VALID));
+#else
+	/*
+	 * Just clear entire TLBHI register.
+	 */
+	__asm volatile(
+		"tlbwe %0,%1,0;"
+		"isync;"
+		: : "r" (0), "r" (i));
+#endif
+
+	tlb_info[i].ti_ctx = 0;
+	tlb_info[i].ti_flags = 0;
+}
 
 /* This has to be done in real mode !!! */
 void
@@ -1228,13 +1268,7 @@ ppc4xx_tlb_flush(vaddr_t va, int pid)
 		: "r" (va), "r" (pid));
 	if (found && !TLB_LOCKED(i)) {
 		/* Now flush translation */
-		__asm volatile(
-			"tlbwe %0,%1,0;"
-			"isync;"
-			: : "r" (0), "r" (i));
-
-		tlb_info[i].ti_ctx = 0;
-		tlb_info[i].ti_flags = 0;
+		tlb_invalidate_entry(i);
 		tlbnext = i;
 		/* Successful flushes */
 		tlbflush_ev.ev_count++;
@@ -1247,12 +1281,8 @@ ppc4xx_tlb_flush_all(void)
 	u_long i;
 
 	for (i = 0; i < NTLB; i++)
-		if (!TLB_LOCKED(i)) {
-			__asm volatile(
-"tlbwe %0,%1,0;" : : "r" (0), "r" (i));
-			tlb_info[i].ti_ctx = 0;
-			tlb_info[i].ti_flags = 0;
-		}
+		if (!TLB_LOCKED(i))
+			tlb_invalidate_entry(i);
 
 	__asm volatile("isync");
 }
@@ -1526,10 +1556,11 @@ ctx_flush(int cnum)
 			if (i < tlb_nreserved)
 panic("TLB entry %d not locked", i);
 #endif
-			/* Invalidate particular TLB entry regardless of locked status */
-			__asm volatile("tlbwe %0,%1,0" : :"r"(0),"r"(i));
-			tlb_info[i].ti_ctx = 0;
-			tlb_info[i].ti_flags = 0;
+			/*
+			 * Invalidate particular TLB entry regardless of
+			 * locked status
+			 */
+			tlb_invalidate_entry(i);
 		}
 	}
 	return (0);



CVS commit: src/sys/arch/powerpc/ibm4xx

2020-09-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Sep 10 03:23:55 UTC 2020

Modified Files:
src/sys/arch/powerpc/ibm4xx: pmap.c

Log Message:
pmap_kenter_pa: Remove comment which says ``Have to remove any existing
mapping first.'' Contrary to this comment, pmap_kremove(9) has never
been called there since rev 1.1, and we don't for other ports also.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/arch/powerpc/ibm4xx/pmap.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/powerpc/ibm4xx/pmap.c
diff -u src/sys/arch/powerpc/ibm4xx/pmap.c:1.91 src/sys/arch/powerpc/ibm4xx/pmap.c:1.92
--- src/sys/arch/powerpc/ibm4xx/pmap.c:1.91	Thu Sep 10 03:02:36 2020
+++ src/sys/arch/powerpc/ibm4xx/pmap.c	Thu Sep 10 03:23:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.91 2020/09/10 03:02:36 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.92 2020/09/10 03:23:55 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.91 2020/09/10 03:02:36 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.92 2020/09/10 03:23:55 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -931,10 +931,6 @@ pmap_kenter_pa(vaddr_t va, paddr_t pa, v
 	struct pmap *pm = pmap_kernel();
 
 	/*
-	 * Have to remove any existing mapping first.
-	 */
-
-	/*
 	 * Generate TTE.
 	 *
 	 * 



CVS commit: src/sys/arch/powerpc/ibm4xx

2020-09-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Sep 10 03:02:36 UTC 2020

Modified Files:
src/sys/arch/powerpc/ibm4xx: pmap.c

Log Message:
Introduce PV_VA() macro to extract va from pv->pv_va by clearing
PV_WIRED flag, and use it where appropriate.

There should be no functional changes. Only for safety in future.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/arch/powerpc/ibm4xx/pmap.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/powerpc/ibm4xx/pmap.c
diff -u src/sys/arch/powerpc/ibm4xx/pmap.c:1.90 src/sys/arch/powerpc/ibm4xx/pmap.c:1.91
--- src/sys/arch/powerpc/ibm4xx/pmap.c:1.90	Mon Jul  6 10:40:21 2020
+++ src/sys/arch/powerpc/ibm4xx/pmap.c	Thu Sep 10 03:02:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.90 2020/07/06 10:40:21 rin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.91 2020/09/10 03:02:36 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.90 2020/07/06 10:40:21 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.91 2020/09/10 03:02:36 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -156,7 +156,8 @@ static char *pmap_attrib;
 #define PV_WIRE(pv)	((pv)->pv_va |= PV_WIRED)
 #define PV_UNWIRE(pv)	((pv)->pv_va &= ~PV_WIRED)
 #define PV_ISWIRED(pv)	((pv)->pv_va & PV_WIRED)
-#define PV_CMPVA(va,pv)	(!(((pv)->pv_va ^ (va)) & (~PV_WIRED)))
+#define PV_VA(pv)	((pv)->pv_va & ~PV_WIRED)
+#define PV_CMPVA(va,pv)	(!(PV_VA(pv) ^ (va)))
 
 struct pv_entry {
 	struct pv_entry *pv_next;	/* Linked list of mappings */
@@ -1115,14 +1116,14 @@ pmap_page_protect(struct vm_page *pg, vm
 		npv = pv->pv_next;
 
 		pm = pv->pv_pm;
-		va = pv->pv_va;
+		va = PV_VA(pv);
 		pmap_protect(pm, va, va + PAGE_SIZE, prot);
 	}
 	/* Now check the head pv */
 	if (pvh->pv_pm) {
 		pv = pvh;
 		pm = pv->pv_pm;
-		va = pv->pv_va;
+		va = PV_VA(pv);
 		pmap_protect(pm, va, va + PAGE_SIZE, prot);
 	}
 }



CVS commit: src/sys/arch/powerpc/booke

2020-09-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Sep 10 02:45:28 UTC 2020

Modified Files:
src/sys/arch/powerpc/booke: trap.c

Log Message:
Fix build with UVMHIST; stop passing string literal to UVMHIST_LOG(),
and also cast pointer arguments into uintptr_t.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/powerpc/booke/trap.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/powerpc/booke/trap.c
diff -u src/sys/arch/powerpc/booke/trap.c:1.34 src/sys/arch/powerpc/booke/trap.c:1.35
--- src/sys/arch/powerpc/booke/trap.c:1.34	Wed Jul 15 09:10:14 2020
+++ src/sys/arch/powerpc/booke/trap.c	Thu Sep 10 02:45:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.34 2020/07/15 09:10:14 rin Exp $	*/
+/*	$NetBSD: trap.c,v 1.35 2020/09/10 02:45:28 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.34 2020/07/15 09:10:14 rin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.35 2020/09/10 02:45:28 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altivec.h"
@@ -294,12 +294,18 @@ isi_exception(struct trapframe *tf, ksig
 		KASSERT(pg);
 		struct vm_page_md * const mdpg = VM_PAGE_TO_MD(pg);
 
-		UVMHIST_LOG(pmapexechist,
-		"srr0=%#x pg=%p (pa %#"PRIxPADDR"): %s", 
-		tf->tf_srr0, pg, pa, 
-		(VM_PAGEMD_EXECPAGE_P(mdpg)
-			? "no syncicache (already execpage)"
-			: "performed syncicache (now execpage)"));
+#ifdef UVMHIST
+		if (VM_PAGEMD_EXECPAGE_P(mdpg))
+			UVMHIST_LOG(pmapexechist,
+			"srr0=%#x pg=%p (pa %#"PRIxPADDR"): "
+			"no syncicache (already execpage)", 
+			tf->tf_srr0, (uintptr_t)pg, pa, 0);
+		else
+			UVMHIST_LOG(pmapexechist,
+			"srr0=%#x pg=%p (pa %#"PRIxPADDR"): "
+			"performed syncicache (now execpage)",
+			tf->tf_srr0, (uintptr_t)pg, pa, 0);
+#endif
 
 		if (!VM_PAGEMD_EXECPAGE_P(mdpg)) {
 			ci->ci_softc->cpu_ev_exec_trap_sync.ev_count++;



CVS commit: src/sys/arch/powerpc/fpu

2020-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jul 15 09:42:43 UTC 2020

Modified Files:
src/sys/arch/powerpc/fpu: fpu_emu.c

Log Message:
Now, FPU emulation for booke and ibm4xx works fine at a level where
all the related ATF tests pass correctly. However, there still remain
problems:

- FEX and VX bits for FPSCR cannot be modified by mcrfs, mtfsf{,i},
  and mtfsb[01].
- Invalid operations should be treated differently depending on
  FPSCR[VE].

Therefore, comment them in order not to be forgotten.

No binary changes.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/powerpc/fpu/fpu_emu.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/powerpc/fpu/fpu_emu.c
diff -u src/sys/arch/powerpc/fpu/fpu_emu.c:1.32 src/sys/arch/powerpc/fpu/fpu_emu.c:1.33
--- src/sys/arch/powerpc/fpu/fpu_emu.c:1.32	Wed Jul 15 09:36:35 2020
+++ src/sys/arch/powerpc/fpu/fpu_emu.c	Wed Jul 15 09:42:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu_emu.c,v 1.32 2020/07/15 09:36:35 rin Exp $ */
+/*	$NetBSD: fpu_emu.c,v 1.33 2020/07/15 09:42:43 rin Exp $ */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 1.32 2020/07/15 09:36:35 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 1.33 2020/07/15 09:42:43 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -605,6 +605,15 @@ fpu_execute(struct trapframe *tf, struct
 fe->fe_cx = mask & a[1];
 fe->fe_fpscr = (fe->fe_fpscr&~mask) | 
 	(fe->fe_cx);
+/*
+ * XXX
+ * Forbidden to set FEX and VX, also for
+ * mcrfs, mtfsfi, and mtfsb[01].
+ *
+ * XXX
+ * Handle invalid operation differently,
+ * depending on VE.
+ */
 /* XXX weird stuff about OX, FX, FEX, and VX should be handled */
 break;
 			case	OPC63_FCTID:



CVS commit: src/sys/arch/powerpc/fpu

2020-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jul 15 09:36:35 UTC 2020

Modified Files:
src/sys/arch/powerpc/fpu: fpu_emu.c

Log Message:
Try to fix FPSCR bits in the end of emulation:

- FPSCR[FEX] is not a sticky bit.
- Turn on FPSCR[FEX] if the emulated instruction causes invalid operation,
  and invalid operation exception is not masked out.
- FPSCR[VX] is not a sticky bit, however it should be set when at least
  one of FPSCR[VXfoo] bits (they are sticky!) is set.
- FPSCR[FX] is a sticky bit, and it should be set if FPSCR is modified by
  instructions other than mtfsf{,i}.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/powerpc/fpu/fpu_emu.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/powerpc/fpu/fpu_emu.c
diff -u src/sys/arch/powerpc/fpu/fpu_emu.c:1.31 src/sys/arch/powerpc/fpu/fpu_emu.c:1.32
--- src/sys/arch/powerpc/fpu/fpu_emu.c:1.31	Wed Jul 15 09:22:26 2020
+++ src/sys/arch/powerpc/fpu/fpu_emu.c	Wed Jul 15 09:36:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu_emu.c,v 1.31 2020/07/15 09:22:26 rin Exp $ */
+/*	$NetBSD: fpu_emu.c,v 1.32 2020/07/15 09:36:35 rin Exp $ */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 1.31 2020/07/15 09:22:26 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 1.32 2020/07/15 09:36:35 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -147,7 +147,9 @@ FPU_EMU_EVCNT_DECL(fnmadd);
 			FPSCR_VXZDZ|FPSCR_VXIMZ|FPSCR_VXVC|FPSCR_VXSOFT|\
 			FPSCR_VXSQRT|FPSCR_VXCVI)
 #define	FPSR_EX		(FPSCR_VE|FPSCR_OE|FPSCR_UE|FPSCR_ZE|FPSCR_XE)
-#define	FPSR_EXOP	(FPSR_EX_MSK&(~FPSR_EX))
+#define	FPSR_INV	(FPSCR_VXSNAN|FPSCR_VXISI|FPSCR_VXIDI|		\
+			FPSCR_VXZDZ|FPSCR_VXIMZ|FPSCR_VXVC|FPSCR_VXSOFT|\
+			FPSCR_VXSQRT|FPSCR_VXCVI)
 
 
 int fpe_debug = 0;
@@ -287,6 +289,7 @@ fpu_execute(struct trapframe *tf, struct
 	int ra, rb, rc, rt, type, mask, fsr, cx, bf, setcr;
 	unsigned int cond;
 	struct fpreg *fs;
+	int mtfsf = 0;
 
 	/* Setup work. */
 	fp = NULL;
@@ -550,6 +553,7 @@ fpu_execute(struct trapframe *tf, struct
 	sizeof(double));
 break;
 			case	OPC63_MTFSFI:
+mtfsf = 1;
 FPU_EMU_EVCNT_INCR(mtfsfi);
 DPRINTF(FPE_INSN, ("fpu_execute: MTFSFI\n"));
 rb >>= 1;
@@ -585,6 +589,7 @@ fpu_execute(struct trapframe *tf, struct
 	sizeof(fs->fpscr));
 break;
 			case	OPC63_MTFSF:
+mtfsf = 1;
 FPU_EMU_EVCNT_INCR(mtfsf);
 DPRINTF(FPE_INSN, ("fpu_execute: MTFSF\n"));
 if ((rt = instr.i_xfl.i_flm) == -1)
@@ -769,11 +774,10 @@ fpu_execute(struct trapframe *tf, struct
 	if (fp)
 		fpu_implode(fe, fp, type, (u_int *)>fpreg[rt]);
 	cx = fe->fe_cx;
-	fsr = fe->fe_fpscr;
+	fsr = fe->fe_fpscr & ~(FPSCR_FEX|FPSCR_VX);
 	if (cx != 0) {
-		fsr &= ~FPSCR_FX;
-		if ((cx^fsr)_EX_MSK)
-			fsr |= FPSCR_FX;
+		if (cx & FPSR_INV)
+			cx |= FPSCR_VX;
 		mask = fsr & FPSR_EX;
 		mask <<= (25-3);
 		if (cx & mask) 
@@ -782,11 +786,13 @@ fpu_execute(struct trapframe *tf, struct
 			/* Need to replace CC */
 			fsr &= ~FPSCR_FPRF;
 		}
-		if (cx & (FPSR_EXOP))
-			fsr |= FPSCR_VX;
 		fsr |= cx;
 		DPRINTF(FPE_INSN, ("fpu_execute: cx %x, fsr %x\n", cx, fsr));
 	}
+	if (fsr & FPSR_INV)
+		fsr |= FPSCR_VX;
+	if (mtfsf == 0 && ((fsr ^ fe->fe_fpscr) & FPSR_EX_MSK))
+		fsr |= FPSCR_FX;
 
 	if (cond) {
 		cond = fsr & 0xf000;



CVS commit: src/sys/arch/powerpc/fpu

2020-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jul 15 09:22:26 UTC 2020

Modified Files:
src/sys/arch/powerpc/fpu: fpu_emu.c

Log Message:
Set ksi_code correctly via fpu_get_fault_code() for SIGFPE.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/powerpc/fpu/fpu_emu.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/powerpc/fpu/fpu_emu.c
diff -u src/sys/arch/powerpc/fpu/fpu_emu.c:1.30 src/sys/arch/powerpc/fpu/fpu_emu.c:1.31
--- src/sys/arch/powerpc/fpu/fpu_emu.c:1.30	Wed Jul 15 09:16:35 2020
+++ src/sys/arch/powerpc/fpu/fpu_emu.c	Wed Jul 15 09:22:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu_emu.c,v 1.30 2020/07/15 09:16:35 rin Exp $ */
+/*	$NetBSD: fpu_emu.c,v 1.31 2020/07/15 09:22:26 rin Exp $ */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 1.30 2020/07/15 09:16:35 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 1.31 2020/07/15 09:22:26 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -244,6 +244,7 @@ success:
 		DPRINTF(FPE_EX, ("fpu_emulate: SIGFPE\n"));
 		ksi->ksi_signo = SIGFPE;
 		ksi->ksi_trap = EXC_PGM;
+		ksi->ksi_code = fpu_get_fault_code();
 		return true;
 
 	case FAULT:



CVS commit: src/sys/arch/powerpc

2020-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jul 15 09:19:49 UTC 2020

Modified Files:
src/sys/arch/powerpc/include: fpu.h
src/sys/arch/powerpc/powerpc: fpu.c

Log Message:
Expose fpu_get_fault_code() even if !PPC_HAVE_FPU, and
adjust it to systems without FPU.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/powerpc/include/fpu.h
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/powerpc/powerpc/fpu.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/powerpc/include/fpu.h
diff -u src/sys/arch/powerpc/include/fpu.h:1.24 src/sys/arch/powerpc/include/fpu.h:1.25
--- src/sys/arch/powerpc/include/fpu.h:1.24	Mon Jul  6 10:52:12 2020
+++ src/sys/arch/powerpc/include/fpu.h	Wed Jul 15 09:19:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.h,v 1.24 2020/07/06 10:52:12 rin Exp $	*/
+/*	$NetBSD: fpu.h,v 1.25 2020/07/15 09:19:49 rin Exp $	*/
 
 /*-
  * Copyright (C) 1996 Wolfgang Solfrank.
@@ -83,6 +83,8 @@ void	fpu_mark_used(struct lwp *);
 void	fpu_restore_from_mcontext(struct lwp *, const mcontext_t *);
 bool	fpu_save_to_mcontext(struct lwp *, mcontext_t *, unsigned int *);
 
+int	fpu_get_fault_code(void);
+
 extern const pcu_ops_t fpu_ops;
 
 /* List of PowerPC architectures that support FPUs. */
@@ -112,8 +114,6 @@ fpu_discard(lwp_t *l)
 void	fpu_load_from_fpreg(const struct fpreg *);
 void	fpu_unload_to_fpreg(struct fpreg *);
 
-int	fpu_get_fault_code(void);
-
 #endif /* PPC_HAVE_FPU */
 #endif /* _KERNEL */
 

Index: src/sys/arch/powerpc/powerpc/fpu.c
diff -u src/sys/arch/powerpc/powerpc/fpu.c:1.41 src/sys/arch/powerpc/powerpc/fpu.c:1.42
--- src/sys/arch/powerpc/powerpc/fpu.c:1.41	Mon Jul  6 10:52:12 2020
+++ src/sys/arch/powerpc/powerpc/fpu.c	Wed Jul 15 09:19:49 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu.c,v 1.41 2020/07/06 10:52:12 rin Exp $	*/
+/*	$NetBSD: fpu.c,v 1.42 2020/07/15 09:19:49 rin Exp $	*/
 
 /*
  * Copyright (C) 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.41 2020/07/06 10:52:12 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.42 2020/07/15 09:19:49 rin Exp $");
 
 #include 
 #include 
@@ -124,7 +124,6 @@ fpu_state_release(lwp_t *l)
 #endif
 }
 
-#ifdef PPC_HAVE_FPU
 #define	STICKYBITS	(FPSCR_VX|FPSCR_OX|FPSCR_UX|FPSCR_ZX|FPSCR_XX)
 #define	STICKYSHIFT	25
 #define	MASKBITS	(FPSCR_VE|FPSCR_OE|FPSCR_UE|FPSCR_ZE|FPSCR_XE)
@@ -139,6 +138,7 @@ fpu_get_fault_code(void)
 	uint32_t fpscr, ofpscr;
 	int code;
 
+#ifdef PPC_HAVE_FPU
 	kpreempt_disable();
 
 	struct cpu_info * const ci = curcpu();
@@ -182,6 +182,10 @@ fpu_get_fault_code(void)
 	}
 
 	kpreempt_enable();
+#else /* !PPC_HAVE_FPU */
+	fpscr64 = *(uint64_t *)>pcb_fpu.fpscr;
+	((uint32_t *)>pcb_fpu.fpscr)[_QUAD_LOWWORD] &= ~MASKBITS;
+#endif
 
 	/*
 	 * Now determine the fault type.  First we test to see if any of sticky
@@ -207,7 +211,6 @@ fpu_get_fault_code(void)
 	elsecode = 0;
 	return code;
 }
-#endif /* PPC_HAVE_FPU */
 
 bool
 fpu_save_to_mcontext(lwp_t *l, mcontext_t *mcp, unsigned int *flagp)



CVS commit: src/sys/arch/powerpc/fpu

2020-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jul 15 09:16:35 UTC 2020

Modified Files:
src/sys/arch/powerpc/fpu: fpu_emu.c

Log Message:
Do not raise SIGFPE unless MSR[FE0] or MSR[FE1] is set via fenv(3).


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/powerpc/fpu/fpu_emu.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/powerpc/fpu/fpu_emu.c
diff -u src/sys/arch/powerpc/fpu/fpu_emu.c:1.29 src/sys/arch/powerpc/fpu/fpu_emu.c:1.30
--- src/sys/arch/powerpc/fpu/fpu_emu.c:1.29	Wed Jul 15 08:29:07 2020
+++ src/sys/arch/powerpc/fpu/fpu_emu.c	Wed Jul 15 09:16:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu_emu.c,v 1.29 2020/07/15 08:29:07 rin Exp $ */
+/*	$NetBSD: fpu_emu.c,v 1.30 2020/07/15 09:16:35 rin Exp $ */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 1.29 2020/07/15 08:29:07 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 1.30 2020/07/15 09:16:35 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -92,6 +92,8 @@ __KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 
 #include 
 
 #include 
+#include 
+
 #include 
 #include 
 #include 
@@ -191,6 +193,7 @@ fpu_dumpfpn(struct fpn *fp)
 bool
 fpu_emulate(struct trapframe *tf, struct fpreg *fpf, ksiginfo_t *ksi)
 {
+	struct pcb *pcb;
 	union instr insn;
 	struct fpemu fe;
 
@@ -229,11 +232,15 @@ fpu_emulate(struct trapframe *tf, struct
 	}
 	switch (fpu_execute(tf, , )) {
 	case 0:
+success:
 		DPRINTF(FPE_EX, ("fpu_emulate: success\n"));
 		tf->tf_srr0 += 4;
 		return true;
 
 	case FPE:
+		pcb = lwp_getpcb(curlwp);
+		if ((pcb->pcb_flags & PSL_FE_PREC) == 0)
+			goto success;
 		DPRINTF(FPE_EX, ("fpu_emulate: SIGFPE\n"));
 		ksi->ksi_signo = SIGFPE;
 		ksi->ksi_trap = EXC_PGM;



CVS commit: src/sys/arch/powerpc

2020-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jul 15 09:10:14 UTC 2020

Modified Files:
src/sys/arch/powerpc/booke: trap.c
src/sys/arch/powerpc/ibm4xx: trap.c

Log Message:
For booke and ibm4xx, emulate m[ft]msr in user mode, in the same
manner as oea.

Now, user process can decide by itself whether floating-point
exception triggers SIGFPE or not via fenv(3).


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/powerpc/booke/trap.c
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/powerpc/ibm4xx/trap.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/powerpc/booke/trap.c
diff -u src/sys/arch/powerpc/booke/trap.c:1.33 src/sys/arch/powerpc/booke/trap.c:1.34
--- src/sys/arch/powerpc/booke/trap.c:1.33	Wed Jul 15 07:44:34 2020
+++ src/sys/arch/powerpc/booke/trap.c	Wed Jul 15 09:10:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.33 2020/07/15 07:44:34 rin Exp $	*/
+/*	$NetBSD: trap.c,v 1.34 2020/07/15 09:10:14 rin Exp $	*/
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.33 2020/07/15 07:44:34 rin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.34 2020/07/15 09:10:14 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altivec.h"
@@ -437,10 +437,7 @@ emulate_opcode(struct trapframe *tf, ksi
 		return true;
 	}
 
-	/*
-	 * If we bothered to emulate FP, we would try to do so here.
-	 */
-	return false;
+	return emulate_mxmsr(curlwp, tf, opcode);
 }
 
 static int

Index: src/sys/arch/powerpc/ibm4xx/trap.c
diff -u src/sys/arch/powerpc/ibm4xx/trap.c:1.84 src/sys/arch/powerpc/ibm4xx/trap.c:1.85
--- src/sys/arch/powerpc/ibm4xx/trap.c:1.84	Wed Jul 15 08:48:40 2020
+++ src/sys/arch/powerpc/ibm4xx/trap.c	Wed Jul 15 09:10:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.84 2020/07/15 08:48:40 rin Exp $	*/
+/*	$NetBSD: trap.c,v 1.85 2020/07/15 09:10:14 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -69,7 +69,7 @@
 #define	__UFETCHSTORE_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.84 2020/07/15 08:48:40 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.85 2020/07/15 09:10:14 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -287,6 +287,7 @@ vm_signal:
 		if (rv == 0) {
 			break;
 		}
+isi:
 		KSI_INIT_TRAP();
 		ksi.ksi_trap = EXC_ISI;
 		ksi.ksi_addr = (void *)tf->tf_srr0;
@@ -324,6 +325,20 @@ sigtrap:
 			}
 			ksi.ksi_code = TRAP_BRKPT;
 			ksi.ksi_signo = SIGTRAP;
+		} else if (tf->tf_esr & ESR_PPR) {
+			uint32_t opcode;
+
+			rv = copyin((void *)tf->tf_srr0, ,
+			sizeof(opcode));
+			if (rv)
+goto isi;
+			if (emulate_mxmsr(l, tf, opcode)) {
+tf->tf_srr0 += 4;
+break;
+			}
+
+			ksi.ksi_code = ILL_PRVOPC;
+			ksi.ksi_signo = SIGILL;
 		} else {
 			pcb = lwp_getpcb(l);
 



CVS commit: src/sys/arch/powerpc

2020-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jul 15 08:58:52 UTC 2020

Modified Files:
src/sys/arch/powerpc/include: cpu.h instr.h
src/sys/arch/powerpc/powerpc: powerpc_machdep.c trap.c

Log Message:
Factor out emulation code for m[ft]msr in user mode from oea, and
adjust it for systems without FPU.

Now, it can be used from booke and ibm4xx in order to support fenv(3).


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/sys/arch/powerpc/include/cpu.h
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/powerpc/include/instr.h
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/powerpc/powerpc/powerpc_machdep.c
cvs rdiff -u -r1.162 -r1.163 src/sys/arch/powerpc/powerpc/trap.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/powerpc/include/cpu.h
diff -u src/sys/arch/powerpc/include/cpu.h:1.114 src/sys/arch/powerpc/include/cpu.h:1.115
--- src/sys/arch/powerpc/include/cpu.h:1.114	Tue Jul  7 01:39:23 2020
+++ src/sys/arch/powerpc/include/cpu.h	Wed Jul 15 08:58:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.114 2020/07/07 01:39:23 rin Exp $	*/
+/*	$NetBSD: cpu.h,v 1.115 2020/07/15 08:58:51 rin Exp $	*/
 
 /*
  * Copyright (C) 1999 Wolfgang Solfrank.
@@ -391,6 +391,8 @@ void	icache_inv(vaddr_t, vsize_t);
 void *	mapiodev(paddr_t, psize_t, bool);
 void	unmapiodev(vaddr_t, vsize_t);
 
+int	emulate_mxmsr(struct lwp *, struct trapframe *, uint32_t);
+
 #ifdef MULTIPROCESSOR
 int	md_setup_trampoline(volatile struct cpu_hatch_data *,
 	struct cpu_info *);

Index: src/sys/arch/powerpc/include/instr.h
diff -u src/sys/arch/powerpc/include/instr.h:1.8 src/sys/arch/powerpc/include/instr.h:1.9
--- src/sys/arch/powerpc/include/instr.h:1.8	Mon Feb 27 06:54:00 2017
+++ src/sys/arch/powerpc/include/instr.h	Wed Jul 15 08:58:51 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: instr.h,v 1.8 2017/02/27 06:54:00 chs Exp $ */
+/*	$NetBSD: instr.h,v 1.9 2020/07/15 08:58:51 rin Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -405,12 +405,6 @@ union instr {
 #define	OPC_MFSPR_REG(o)	(((o) >> 21) & 0x1f)
 #define	OPC_MFSPR_P(o, spr)	(((o) & OPC_MFSPR_MASK) == OPC_MFSPR(spr))
 
-#define	OPC_MFMSR_CODE		0x7ca6
-#define	OPC_MFMSR_MASK		0xfc1f
-#define	OPC_MFMSR		OPC_MFMSR_CODE
-#define	OPC_MFMSR_REG(o)	(((o) >> 21) & 0x1f)
-#define	OPC_MFMSR_P(o)		(((o) & OPC_MFMSR_MASK) == OPC_MFMSR_CODE)
-
 /*
  * booke doesn't have lwsync even though gcc emits it so we have to emulate it.
  */

Index: src/sys/arch/powerpc/powerpc/powerpc_machdep.c
diff -u src/sys/arch/powerpc/powerpc/powerpc_machdep.c:1.79 src/sys/arch/powerpc/powerpc/powerpc_machdep.c:1.80
--- src/sys/arch/powerpc/powerpc/powerpc_machdep.c:1.79	Tue Jul  7 01:39:23 2020
+++ src/sys/arch/powerpc/powerpc/powerpc_machdep.c	Wed Jul 15 08:58:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: powerpc_machdep.c,v 1.79 2020/07/07 01:39:23 rin Exp $	*/
+/*	$NetBSD: powerpc_machdep.c,v 1.80 2020/07/15 08:58:52 rin Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: powerpc_machdep.c,v 1.79 2020/07/07 01:39:23 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: powerpc_machdep.c,v 1.80 2020/07/15 08:58:52 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altivec.h"
@@ -738,6 +738,82 @@ cpu_debug_dump(void)
 #endif	/* DDB */
 #endif /* MULTIPROCESSOR */
 
+int
+emulate_mxmsr(struct lwp *l, struct trapframe *tf, uint32_t opcode)
+{
+
+#define	OPC_MFMSR_CODE		0x7ca6
+#define	OPC_MFMSR_MASK		0xfc1f
+#define	OPC_MFMSR_P(o)		(((o) & OPC_MFMSR_MASK) == OPC_MFMSR_CODE)
+
+#define	OPC_MTMSR_CODE		0x7c000124
+#define	OPC_MTMSR_MASK		0xfc1f
+#define	OPC_MTMSR_P(o)		(((o) & OPC_MTMSR_MASK) == OPC_MTMSR_CODE)
+
+#define	OPC_MXMSR_REG(o)	(((o) >> 21) & 0x1f)
+
+	if (OPC_MFMSR_P(opcode)) {
+		struct pcb * const pcb = lwp_getpcb(l);
+		register_t msr = tf->tf_srr1 & PSL_USERSRR1;
+
+		if (fpu_used_p(l))
+			msr |= PSL_FP;
+#ifdef ALTIVEC
+		if (vec_used_p(l))
+			msr |= PSL_VEC;
+#endif
+
+		msr |= (pcb->pcb_flags & PSL_FE_PREC);
+		tf->tf_fixreg[OPC_MXMSR_REG(opcode)] = msr;
+		return 1;
+	}
+
+	if (OPC_MTMSR_P(opcode)) {
+		struct pcb * const pcb = lwp_getpcb(l);
+		register_t msr = tf->tf_fixreg[OPC_MXMSR_REG(opcode)];
+
+		/*
+		 * Ignore the FP enable bit in the requested MSR.
+		 * It might be set in the thread's actual MSR but the
+		 * user code isn't allowed to change it.
+		 */
+		msr &= ~PSL_FP;
+#ifdef ALTIVEC
+		msr &= ~PSL_VEC;
+#endif
+
+		/*
+		 * Don't let the user muck with bits he's not allowed to.
+		 */
+#ifdef PPC_HAVE_FPU
+		if (!PSL_USEROK_P(msr))
+#else
+		if (!PSL_USEROK_P(msr & ~PSL_FE_PREC))
+#endif
+			return 0;
+
+		/*
+		 * For now, only update the FP exception mode.
+		 */
+		pcb->pcb_flags &= ~PSL_FE_PREC;
+		pcb->pcb_flags |= msr & PSL_FE_PREC;
+
+#ifdef PPC_HAVE_FPU
+		/*
+		 * If we think we have the FPU, update SRR1 too.  If we're
+		 * wrong userret() will take care of it.
+		 */
+		if 

CVS commit: src/sys/arch/powerpc/ibm4xx

2020-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jul 15 08:48:40 UTC 2020

Modified Files:
src/sys/arch/powerpc/ibm4xx: trap.c

Log Message:
Treat trap instruction from userland correctly in EXC_PGM handler;
raise SIGTRAP with TRAP_BRKPT instead of SIGILL.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/sys/arch/powerpc/ibm4xx/trap.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/powerpc/ibm4xx/trap.c
diff -u src/sys/arch/powerpc/ibm4xx/trap.c:1.83 src/sys/arch/powerpc/ibm4xx/trap.c:1.84
--- src/sys/arch/powerpc/ibm4xx/trap.c:1.83	Mon Jul  6 10:41:43 2020
+++ src/sys/arch/powerpc/ibm4xx/trap.c	Wed Jul 15 08:48:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.83 2020/07/06 10:41:43 rin Exp $	*/
+/*	$NetBSD: trap.c,v 1.84 2020/07/15 08:48:40 rin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -69,7 +69,7 @@
 #define	__UFETCHSTORE_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.83 2020/07/06 10:41:43 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.84 2020/07/15 08:48:40 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -309,27 +309,38 @@ vm_signal:
 		break;
 
 	case EXC_PGM|EXC_USER:
-		/*
-		 * Illegal insn:
-		 *
-		 * let's try to see if its FPU and can be emulated.
-		 */
 		curcpu()->ci_data.cpu_ntrap++;
-		pcb = lwp_getpcb(l);
 
-		if (__predict_false(!fpu_used_p(l))) {
-			memset(>pcb_fpu, 0, sizeof(pcb->pcb_fpu));
-			fpu_mark_used(l);
-		}
+		KSI_INIT_TRAP();
+		ksi.ksi_trap = EXC_PGM;
+		ksi.ksi_addr = (void *)tf->tf_srr0;
 
-		if (fpu_emulate(tf, >pcb_fpu, )) {
-			if (ksi.ksi_signo == 0)	/* was emulated */
+		if (tf->tf_esr & ESR_PTR) {
+sigtrap:
+			if (p->p_raslist != NULL &&
+			ras_lookup(p, (void *)tf->tf_srr0) != (void *) -1) {
+tf->tf_srr1 += 4;
 break;
+			}
+			ksi.ksi_code = TRAP_BRKPT;
+			ksi.ksi_signo = SIGTRAP;
 		} else {
-			ksi.ksi_signo = SIGILL;
-			ksi.ksi_code = ILL_ILLOPC;
-			ksi.ksi_trap = EXC_PGM;
-			ksi.ksi_addr = (void *)tf->tf_srr0;
+			pcb = lwp_getpcb(l);
+
+			if (__predict_false(!fpu_used_p(l))) {
+memset(>pcb_fpu, 0, sizeof(pcb->pcb_fpu));
+fpu_mark_used(l);
+			}
+
+			if (fpu_emulate(tf, >pcb_fpu, )) {
+if (ksi.ksi_signo == 0)	/* was emulated */
+	break;
+else if (ksi.ksi_signo == SIGTRAP)
+	goto sigtrap;	/* XXX H/W bug? */
+			} else {
+ksi.ksi_code = ILL_ILLOPC;
+ksi.ksi_signo = SIGILL;
+			}
 		}
 
 		trapsignal(l, );



CVS commit: src/sys/arch/powerpc/fpu

2020-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jul 15 08:29:07 UTC 2020

Modified Files:
src/sys/arch/powerpc/fpu: fpu_emu.c

Log Message:
FPSCR[FEX] is not a sticky bit; it is always cleared when read from
userland via mffs on real hardware.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/powerpc/fpu/fpu_emu.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/powerpc/fpu/fpu_emu.c
diff -u src/sys/arch/powerpc/fpu/fpu_emu.c:1.28 src/sys/arch/powerpc/fpu/fpu_emu.c:1.29
--- src/sys/arch/powerpc/fpu/fpu_emu.c:1.28	Wed Jul 15 08:10:41 2020
+++ src/sys/arch/powerpc/fpu/fpu_emu.c	Wed Jul 15 08:29:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu_emu.c,v 1.28 2020/07/15 08:10:41 rin Exp $ */
+/*	$NetBSD: fpu_emu.c,v 1.29 2020/07/15 08:29:07 rin Exp $ */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 1.28 2020/07/15 08:10:41 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 1.29 2020/07/15 08:29:07 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -571,6 +571,8 @@ fpu_execute(struct trapframe *tf, struct
 			case	OPC63_MFFS:
 FPU_EMU_EVCNT_INCR(mffs);
 DPRINTF(FPE_INSN, ("fpu_execute: MFFS\n"));
+/* XXX FEX is not sticky */
+fs->fpscr &= ~FPSCR_FEX;
 memcpy(>fpreg[rt], >fpscr,
 	sizeof(fs->fpscr));
 break;



CVS commit: src/sys/arch/powerpc/fpu

2020-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jul 15 08:10:41 UTC 2020

Modified Files:
src/sys/arch/powerpc/fpu: fpu_emu.c

Log Message:
PR port-powerpc/55425

Fix emulation for mtfsf; source register is frB here.

Now, userland processes successfully change rounding mode, by which
FPU-optimized code in OpenSSL works just fine as far as I can see.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/powerpc/fpu/fpu_emu.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/powerpc/fpu/fpu_emu.c
diff -u src/sys/arch/powerpc/fpu/fpu_emu.c:1.27 src/sys/arch/powerpc/fpu/fpu_emu.c:1.28
--- src/sys/arch/powerpc/fpu/fpu_emu.c:1.27	Wed Jul 15 07:54:25 2020
+++ src/sys/arch/powerpc/fpu/fpu_emu.c	Wed Jul 15 08:10:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: fpu_emu.c,v 1.27 2020/07/15 07:54:25 rin Exp $ */
+/*	$NetBSD: fpu_emu.c,v 1.28 2020/07/15 08:10:41 rin Exp $ */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 1.27 2020/07/15 07:54:25 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fpu_emu.c,v 1.28 2020/07/15 08:10:41 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -586,7 +586,7 @@ fpu_execute(struct trapframe *tf, struct
 		if (rt & (1fpreg[rb];
 fe->fe_cx = mask & a[1];
 fe->fe_fpscr = (fe->fe_fpscr&~mask) | 
 	(fe->fe_cx);



CVS commit: src/sys/arch/powerpc/powerpc

2020-07-15 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Jul 15 07:58:26 UTC 2020

Modified Files:
src/sys/arch/powerpc/powerpc: trap.c

Log Message:
Rename emulated_opcode() to emulate_privileged() for clarity.
No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/arch/powerpc/powerpc/trap.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/powerpc/powerpc/trap.c
diff -u src/sys/arch/powerpc/powerpc/trap.c:1.161 src/sys/arch/powerpc/powerpc/trap.c:1.162
--- src/sys/arch/powerpc/powerpc/trap.c:1.161	Mon Jul  6 11:24:57 2020
+++ src/sys/arch/powerpc/powerpc/trap.c	Wed Jul 15 07:58:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: trap.c,v 1.161 2020/07/06 11:24:57 rin Exp $	*/
+/*	$NetBSD: trap.c,v 1.162 2020/07/15 07:58:26 rin Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -35,7 +35,7 @@
 #define	__UCAS_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.161 2020/07/06 11:24:57 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.162 2020/07/15 07:58:26 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altivec.h"
@@ -69,7 +69,7 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.1
 #include 
 #include 
 
-static int emulated_opcode(struct lwp *, struct trapframe *);
+static int emulate_privileged(struct lwp *, struct trapframe *);
 static int fix_unaligned(struct lwp *, struct trapframe *);
 static inline vaddr_t setusr(vaddr_t, size_t *);
 static inline void unsetusr(void);
@@ -435,7 +435,7 @@ vm_signal:
 ksi.ksi_signo = SIGFPE;
 ksi.ksi_code = fpu_get_fault_code();
 			} else if (tf->tf_srr1 & 0x4) {
-if (emulated_opcode(l, tf)) {
+if (emulate_privileged(l, tf)) {
 	tf->tf_srr0 += 4;
 	break;
 }
@@ -1076,8 +1076,8 @@ fix_unaligned(struct lwp *l, struct trap
 	return -1;
 }
 
-int
-emulated_opcode(struct lwp *l, struct trapframe *tf)
+static int
+emulate_privileged(struct lwp *l, struct trapframe *tf)
 {
 	uint32_t opcode;
 



  1   2   3   4   5   6   7   8   9   >