Module Name: src
Committed By: cherry
Date: Mon Dec 26 17:54:07 UTC 2016
Modified Files:
src/sys/arch/amd64/amd64: machdep.c
src/sys/arch/i386/i386: machdep.c
src/sys/arch/x86/include: machdep.h
src/sys/arch/x86/x86: x86_machdep.c
Log Message:
the i386 and amd64 boot time msgbuf init code is nearly identical.
Unify them into x86/x86_machdep.c:init_x86_msgbuf()
Boot tested on GENERIC (i386, amd64), XEN3_DOM0 (amd64)
To generate a diff of this commit:
cvs rdiff -u -r1.245 -r1.246 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.775 -r1.776 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/include/machdep.h
cvs rdiff -u -r1.79 -r1.80 src/sys/arch/x86/x86/x86_machdep.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.245 src/sys/arch/amd64/amd64/machdep.c:1.246
--- src/sys/arch/amd64/amd64/machdep.c:1.245 Mon Dec 26 13:55:13 2016
+++ src/sys/arch/amd64/amd64/machdep.c Mon Dec 26 17:54:06 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.245 2016/12/26 13:55:13 cherry Exp $ */
+/* $NetBSD: machdep.c,v 1.246 2016/12/26 17:54:06 cherry Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.245 2016/12/26 13:55:13 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.246 2016/12/26 17:54:06 cherry Exp $");
/* #define XENDEBUG_LOW */
@@ -254,14 +254,6 @@ size_t dump_npages;
size_t dump_header_size;
size_t dump_totalbytesleft;
-vaddr_t msgbuf_vaddr;
-
-struct {
- paddr_t paddr;
- psize_t sz;
-} msgbuf_p_seg[VM_PHYSSEG_MAX];
-unsigned int msgbuf_p_cnt = 0;
-
vaddr_t idt_vaddr;
paddr_t idt_paddr;
vaddr_t gdt_vaddr;
@@ -1466,52 +1458,6 @@ extern vector IDTVEC(oosyscall);
extern vector *IDTVEC(exceptions)[];
static void
-init_x86_64_msgbuf(void)
-{
- /* Message buffer is located at end of core. */
- psize_t sz = round_page(MSGBUFSIZE);
- psize_t reqsz = sz;
- uvm_physseg_t x;
-
- search_again:
- for (x = uvm_physseg_get_first();
- uvm_physseg_valid_p(x);
- x = uvm_physseg_get_next(x)) {
-
- if (ctob(uvm_physseg_get_avail_end(x)) == avail_end)
- break;
- }
-
- if (uvm_physseg_valid_p(x) == false)
- panic("init_x86_64: can't find end of memory");
-
- /* Shrink so it'll fit in the last segment. */
- if (uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x) < atop(sz))
- sz = ctob(uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x));
-
- uvm_physseg_unplug(uvm_physseg_get_end(x) - atop(sz), atop(sz));
- msgbuf_p_seg[msgbuf_p_cnt].sz = sz;
- msgbuf_p_seg[msgbuf_p_cnt++].paddr = ctob(uvm_physseg_get_avail_end(x));
-
- /* Now find where the new avail_end is. */
- avail_end = ctob(uvm_physseg_get_avail_end(x));
-
- if (sz == reqsz)
- return;
-
- reqsz -= sz;
- if (msgbuf_p_cnt == VM_PHYSSEG_MAX) {
- /* No more segments available, bail out. */
- printf("WARNING: MSGBUFSIZE (%zu) too large, using %zu.\n",
- (size_t)MSGBUFSIZE, (size_t)(MSGBUFSIZE - reqsz));
- return;
- }
-
- sz = reqsz;
- goto search_again;
-}
-
-static void
init_x86_64_ksyms(void)
{
#if NKSYMS || defined(DDB) || defined(MODULAR)
@@ -1640,7 +1586,7 @@ init_x86_64(paddr_t first_avail)
atop(avail_start), atop(avail_end), VM_FREELIST_DEFAULT);
#endif
- init_x86_64_msgbuf();
+ init_x86_msgbuf();
pmap_growkernel(VM_MIN_KERNEL_ADDRESS + 32 * 1024 * 1024);
Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.775 src/sys/arch/i386/i386/machdep.c:1.776
--- src/sys/arch/i386/i386/machdep.c:1.775 Mon Dec 26 15:47:48 2016
+++ src/sys/arch/i386/i386/machdep.c Mon Dec 26 17:54:06 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.775 2016/12/26 15:47:48 cherry Exp $ */
+/* $NetBSD: machdep.c,v 1.776 2016/12/26 17:54:06 cherry Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.775 2016/12/26 15:47:48 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.776 2016/12/26 17:54:06 cherry Exp $");
#include "opt_beep.h"
#include "opt_compat_ibcs2.h"
@@ -236,13 +236,6 @@ int i386_use_fxsave;
int i386_has_sse;
int i386_has_sse2;
-vaddr_t msgbuf_vaddr;
-struct {
- paddr_t paddr;
- psize_t sz;
-} msgbuf_p_seg[VM_PHYSSEG_MAX];
-unsigned int msgbuf_p_cnt = 0;
-
vaddr_t idt_vaddr;
paddr_t idt_paddr;
vaddr_t gdt_vaddr;
@@ -1034,51 +1027,6 @@ initgdt(union descriptor *tgdt)
#endif /* !XEN */
}
-static void
-init386_msgbuf(void)
-{
- /* Message buffer is located at end of core. */
- psize_t sz = round_page(MSGBUFSIZE);
- psize_t reqsz = sz;
- uvm_physseg_t x;
-
-search_again:
- for (x = uvm_physseg_get_first();
- uvm_physseg_valid_p(x);
- x = uvm_physseg_get_next(x)) {
- if (ctob(uvm_physseg_get_avail_end(x)) == avail_end) {
- break;
- }
- }
- if (uvm_physseg_valid_p(x) == false)
- panic("init386: can't find end of memory");
-
- /* Shrink so it'll fit in the last segment. */
- if (uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x) < atop(sz))
- sz = ctob(uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x));
-
- uvm_physseg_unplug(uvm_physseg_get_end(x) - atop(sz), atop(sz));
- msgbuf_p_seg[msgbuf_p_cnt].sz = sz;
- msgbuf_p_seg[msgbuf_p_cnt++].paddr = ctob(uvm_physseg_get_avail_end(x));
-
- /* Now find where the new avail_end is. */
- avail_end = ctob(uvm_physseg_get_avail_end(x));
-
- if (sz == reqsz)
- return;
-
- reqsz -= sz;
- if (msgbuf_p_cnt == VM_PHYSSEG_MAX) {
- /* No more segments available, bail out. */
- printf("WARNING: MSGBUFSIZE (%zu) too large, using %zu.\n",
- (size_t)MSGBUFSIZE, (size_t)(MSGBUFSIZE - reqsz));
- return;
- }
-
- sz = reqsz;
- goto search_again;
-}
-
#ifndef XEN
static void
init386_pte0(void)
@@ -1273,7 +1221,7 @@ init386(paddr_t first_avail)
#endif /* !XEN */
- init386_msgbuf();
+ init_x86_msgbuf();
#if !defined(XEN) && NBIOSCALL > 0
/*
Index: src/sys/arch/x86/include/machdep.h
diff -u src/sys/arch/x86/include/machdep.h:1.8 src/sys/arch/x86/include/machdep.h:1.9
--- src/sys/arch/x86/include/machdep.h:1.8 Sat Jul 16 17:02:34 2016
+++ src/sys/arch/x86/include/machdep.h Mon Dec 26 17:54:07 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.h,v 1.8 2016/07/16 17:02:34 maxv Exp $ */
+/* $NetBSD: machdep.h,v 1.9 2016/12/26 17:54:07 cherry Exp $ */
/*
* Copyright (c) 2000, 2007 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -32,11 +32,21 @@
extern phys_ram_seg_t mem_clusters[];
extern int mem_cluster_cnt;
+extern vaddr_t msgbuf_vaddr;
+extern unsigned int msgbuf_p_cnt;
+
struct btinfo_memmap;
struct extent;
struct sysctllog;
+struct msgbuf_p_seg {
+ paddr_t paddr;
+ psize_t sz;
+};
+
+extern struct msgbuf_p_seg msgbuf_p_seg[];
+
void x86_cpu_idle_init(void);
void x86_cpu_idle_get(void (**)(void), char *, size_t);
void x86_cpu_idle_set(void (*)(void), const char *, bool);
@@ -45,6 +55,7 @@ int x86_select_freelist(uint64_t);
void init_x86_clusters(void);
int init_x86_vm(paddr_t);
+void init_x86_msgbuf(void);
void x86_startup(void);
void x86_sysctl_machdep_setup(struct sysctllog **);
Index: src/sys/arch/x86/x86/x86_machdep.c
diff -u src/sys/arch/x86/x86/x86_machdep.c:1.79 src/sys/arch/x86/x86/x86_machdep.c:1.80
--- src/sys/arch/x86/x86/x86_machdep.c:1.79 Tue Dec 20 14:03:15 2016
+++ src/sys/arch/x86/x86/x86_machdep.c Mon Dec 26 17:54:07 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: x86_machdep.c,v 1.79 2016/12/20 14:03:15 maxv Exp $ */
+/* $NetBSD: x86_machdep.c,v 1.80 2016/12/26 17:54:07 cherry Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.79 2016/12/20 14:03:15 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_machdep.c,v 1.80 2016/12/26 17:54:07 cherry Exp $");
#include "opt_modular.h"
#include "opt_physmem.h"
@@ -101,6 +101,16 @@ struct bootinfo bootinfo;
static kauth_listener_t x86_listener;
+extern paddr_t lowmem_rsvd, avail_start, avail_end;
+
+vaddr_t msgbuf_vaddr;
+
+struct msgbuf_p_seg msgbuf_p_seg[VM_PHYSSEG_MAX];
+
+unsigned int msgbuf_p_cnt = 0;
+
+void init_x86_msgbuf(void);
+
/*
* Given the type of a bootinfo entry, looks for a matching item inside
* the bootinfo structure. If found, returns a pointer to it (which must
@@ -482,8 +492,6 @@ static struct {
{ VM_FREELIST_FIRST16, 16 * 1024 * 1024 },
};
-extern paddr_t lowmem_rsvd, avail_end;
-
int
x86_select_freelist(uint64_t maxaddr)
{
@@ -902,6 +910,52 @@ init_x86_vm(paddr_t pa_kend)
#endif /* !XEN */
void
+init_x86_msgbuf(void)
+{
+ /* Message buffer is located at end of core. */
+ psize_t sz = round_page(MSGBUFSIZE);
+ psize_t reqsz = sz;
+ uvm_physseg_t x;
+
+ search_again:
+ for (x = uvm_physseg_get_first();
+ uvm_physseg_valid_p(x);
+ x = uvm_physseg_get_next(x)) {
+
+ if (ctob(uvm_physseg_get_avail_end(x)) == avail_end)
+ break;
+ }
+
+ if (uvm_physseg_valid_p(x) == false)
+ panic("init_x86_msgbuf: can't find end of memory");
+
+ /* Shrink so it'll fit in the last segment. */
+ if (uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x) < atop(sz))
+ sz = ctob(uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x));
+
+ uvm_physseg_unplug(uvm_physseg_get_end(x) - atop(sz), atop(sz));
+ msgbuf_p_seg[msgbuf_p_cnt].sz = sz;
+ msgbuf_p_seg[msgbuf_p_cnt++].paddr = ctob(uvm_physseg_get_avail_end(x));
+
+ /* Now find where the new avail_end is. */
+ avail_end = ctob(uvm_physseg_get_avail_end(x));
+
+ if (sz == reqsz)
+ return;
+
+ reqsz -= sz;
+ if (msgbuf_p_cnt == VM_PHYSSEG_MAX) {
+ /* No more segments available, bail out. */
+ printf("WARNING: MSGBUFSIZE (%zu) too large, using %zu.\n",
+ (size_t)MSGBUFSIZE, (size_t)(MSGBUFSIZE - reqsz));
+ return;
+ }
+
+ sz = reqsz;
+ goto search_again;
+}
+
+void
x86_reset(void)
{
uint8_t b;