Module Name:    src
Committed By:   macallan
Date:           Thu May  6 04:30:18 UTC 2010

Modified Files:
        src/sys/dev/rasops: rasops.c rasops.h

Log Message:
Introduce a new flag for rasops_info to keep rasops_reconfig() from trying
to allocate memory. Use this when calling rasops_reconfig() before it is safe
to call kmem_alloc().


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/dev/rasops/rasops.c
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/rasops/rasops.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/dev/rasops/rasops.c
diff -u src/sys/dev/rasops/rasops.c:1.63 src/sys/dev/rasops/rasops.c:1.64
--- src/sys/dev/rasops/rasops.c:1.63	Tue May  4 04:57:34 2010
+++ src/sys/dev/rasops/rasops.c	Thu May  6 04:30:18 2010
@@ -1,4 +1,4 @@
-/*	 $NetBSD: rasops.c,v 1.63 2010/05/04 04:57:34 macallan Exp $	*/
+/*	 $NetBSD: rasops.c,v 1.64 2010/05/06 04:30:18 macallan Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.63 2010/05/04 04:57:34 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.64 2010/05/06 04:30:18 macallan Exp $");
 
 #include "opt_rasops.h"
 #include "rasops_glue.h"
@@ -163,6 +163,8 @@
 void	rasops_make_box_chars_16(struct rasops_info *);
 void	rasops_make_box_chars_32(struct rasops_info *);
 
+extern int cold;
+
 /*
  * Initialize a 'rasops_info' descriptor.
  */
@@ -250,15 +252,18 @@
 	}
 
 	/* autogenerate box drawing characters */
+	ri->ri_optfont.firstchar = WSFONT_FLAG_OPT;
+	ri->ri_optfont.numchars = 16;
 	ri->ri_optfont.fontwidth = ri->ri_font->fontwidth;
 	ri->ri_optfont.fontheight = ri->ri_font->fontheight;
 	ri->ri_optfont.stride = ri->ri_font->stride;
-	ri->ri_optfont.firstchar = WSFONT_FLAG_OPT;
-	ri->ri_optfont.numchars = 16;
-	
 	len = ri->ri_optfont.fontheight * ri->ri_optfont.stride *
-	      ri->ri_optfont.numchars; 
-	if ((ri->ri_optfont.data = kmem_zalloc(len, KM_SLEEP)) != NULL) {
+		      ri->ri_optfont.numchars; 
+
+	if (((ri->ri_flg & RI_NO_AUTO) == 0) && 
+	  ((ri->ri_optfont.data = kmem_zalloc(len, KM_SLEEP)) != NULL)) {
+
+	
 		switch (ri->ri_optfont.stride) {
 		case 1:
 			rasops_make_box_chars_8(ri);
@@ -270,7 +275,8 @@
 			rasops_make_box_chars_32(ri);
 			break;
 		}
-	}
+	} else
+		memset(&ri->ri_optfont, 0, sizeof(ri->ri_optfont));
 
 	if (ri->ri_font->fontwidth > 32 || ri->ri_font->fontwidth < 4)
 		panic("rasops_init: fontwidth assumptions botched!");

Index: src/sys/dev/rasops/rasops.h
diff -u src/sys/dev/rasops/rasops.h:1.25 src/sys/dev/rasops/rasops.h:1.26
--- src/sys/dev/rasops/rasops.h:1.25	Tue May  4 04:57:34 2010
+++ src/sys/dev/rasops/rasops.h	Thu May  6 04:30:18 2010
@@ -1,4 +1,4 @@
-/* 	$NetBSD: rasops.h,v 1.25 2010/05/04 04:57:34 macallan Exp $ */
+/* 	$NetBSD: rasops.h,v 1.26 2010/05/06 04:30:18 macallan Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -48,6 +48,13 @@
 #define RI_ROTATE_CCW	0x200	/* display is rotated, quarter counter-clockwise */
 #define RI_ROTATE_UD	0x400	/* display is rotated, upside-down */
 #define RI_ROTATE_MASK	0x700
+/*
+ * if you call rasops_init() or rasops_reconfig() in a context where it is not
+ * safe to call kmem_alloc(), like early on during kernel startup, you MUST set
+ * RI_NO_AUTO to keep rasops from trying to allocate memory for autogenerated
+ * box drawing characters
+ */
+#define	RI_NO_AUTO	0x800	/* do not generate box drawing characters */
 
 struct rasops_info {
 	/* These must be filled in by the caller */
@@ -124,7 +131,8 @@
        ((c) >= (font)->firstchar && 				\
 	((c) - (font)->firstchar) < (font)->numchars)
 
-#define PICK_FONT(ri, c) ((c & WSFONT_FLAGS_MASK) == WSFONT_FLAG_OPT) ? \
+#define PICK_FONT(ri, c) (((c & WSFONT_FLAGS_MASK) == WSFONT_FLAG_OPT) && \
+			  (ri->ri_optfont.data != NULL)) ? \
 			 &ri->ri_optfont : ri->ri_font
 
 /*

Reply via email to