Subject: Three small patches for ARM
To: None <port-arm@netbsd.org>
From: Scott <scott_allan@picovex.com>
List: port-arm
Date: 07/26/2006 18:46:22
This is a multi-part message in MIME format.
--------------070504010006050809010607
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi all,

I'm working on a board port and I ran into a few small things, so I thought 
I'd send out the patches I came up with to fix them.

1) fix_unknown_cpu.patch
identify_arm_cpu() prints out a helpful message when it detects that you're 
trying to run on a CPU that you didn't configure for.  Unfortunately, the 
check for class_option being NULL is backward, so it either won't print the 
class_option, or it will try to dereference a NULL.  The patch just flips the 
!= NULL to be == NULL.

2) allow_pmap_up_to_end_of_memory.patch
I ran into a problem when I tried to set up a mapping that started at virtual 
address 0xFFF00000 and was 0x00100000 long.  In other words, the mapping 
should have gone to the end of the 32 bit address space.  The mapping was made 
with no problem, but pmap_devmap_find_va() wouldn't find an address within the 
mapping.  For example, if I told it to find a mapping for 0x1000 bytes at 
0xFFF01000, it would try to make sure that 0xFFF01000 was greater than 
0xFFF00000 and that (0xFFF01000+0x1000) was less than (0xFFF00000+0x00100000). 
  However, that last expression (0xFFF00000+0x00100000) wrapped around to be 
simply 0x00000000 so it wasn't found.  This patch fixes this problem in 
pmap_devmap_find_va() and pmap_devmap_find_pa() by subtracting one off of the 
sizes to be compared, so in my example, (0xFFF01000+0x1000-1) will be less 
than (0xFFF00000+0x00100000-1).

3) allow_asm_vmparam.patch
This one is really simple.  I wanted to use KERNEL_BASE in an assembly source, 
but arch/arm/include/arm32/vmparam.h wasn't protected by #ifndef 
__ASSEMBLER__.  The patch adds the protection.

Feedback will be appreciated, but even better would be to see these patches 
incorporated into NetBSD.

Thanks much,
   Scott

--------------070504010006050809010607
Content-Type: text/x-patch;
 name="allow_asm_vmparam.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="allow_asm_vmparam.patch"

Index: netbsd_quilt/src/sys/arch/arm/include/arm32/vmparam.h
===================================================================
--- netbsd_quilt.orig/src/sys/arch/arm/include/arm32/vmparam.h
+++ netbsd_quilt/src/sys/arch/arm/include/arm32/vmparam.h
@@ -44,7 +44,9 @@
  * Virtual Memory parameters common to all arm32 platforms.
  */
 
+#ifndef __ASSEMBLER__
 #include <sys/lock.h>		/* struct simplelock */ 
+#endif /* __ASSEMBLER__ */
 #include <arm/arm32/pte.h>	/* pt_entry_t */
 
 #define	USRSTACK	VM_MAXUSER_ADDRESS
@@ -92,6 +94,7 @@
 #define	VM_MIN_KERNEL_ADDRESS	((vaddr_t) KERNEL_BASE)
 #define	VM_MAX_KERNEL_ADDRESS	((vaddr_t) 0xffffffff)
 
+#ifndef __ASSEMBLER__
 /* XXX max. amount of KVM to be used by buffers. */
 #ifndef VM_MAX_KERNEL_BUF
 extern vaddr_t virtual_avail;
@@ -129,6 +132,7 @@
 	(pg)->mdpage.urw_mappings = 0;					\
 	(pg)->mdpage.k_mappings = 0;					\
 } while (/*CONSTCOND*/0)
+#endif /* __ASSEMBLER__ */
 
 #endif /* _KERNEL */
 

--------------070504010006050809010607
Content-Type: text/x-patch;
 name="allow_pmap_up_to_end_of_memory.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="allow_pmap_up_to_end_of_memory.patch"

Index: netbsd_quilt/src/sys/arch/arm/arm32/pmap.c
===================================================================
--- netbsd_quilt.orig/src/sys/arch/arm/arm32/pmap.c
+++ netbsd_quilt/src/sys/arch/arm/arm32/pmap.c
@@ -4587,12 +4587,12 @@
 	if (pmap_devmap_table == NULL)
 		return (NULL);
 
-	endpa = (uint64_t)pa + (uint64_t)size;
+	endpa = (uint64_t)pa + (uint64_t)(size - 1);
 
 	for (i = 0; pmap_devmap_table[i].pd_size != 0; i++) {
 		if (pa >= pmap_devmap_table[i].pd_pa &&
 		    endpa <= (uint64_t)pmap_devmap_table[i].pd_pa +
-			     (uint64_t)pmap_devmap_table[i].pd_size)
+			     (uint64_t)(pmap_devmap_table[i].pd_size - 1))
 			return (&pmap_devmap_table[i]);
 	}
 
@@ -4609,8 +4609,8 @@
 
 	for (i = 0; pmap_devmap_table[i].pd_size != 0; i++) {
 		if (va >= pmap_devmap_table[i].pd_va &&
-		    va + size <= pmap_devmap_table[i].pd_va +
-				 pmap_devmap_table[i].pd_size)
+		    va + size - 1 <= pmap_devmap_table[i].pd_va +
+				     pmap_devmap_table[i].pd_size - 1)
 			return (&pmap_devmap_table[i]);
 	}
 

--------------070504010006050809010607
Content-Type: text/x-patch;
 name="fix_unknown_cpu.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="fix_unknown_cpu.patch"

Index: netbsd_quilt/src/sys/arch/arm/arm32/cpu.c
===================================================================
--- netbsd_quilt.orig/src/sys/arch/arm/arm32/cpu.c
+++ netbsd_quilt/src/sys/arch/arm/arm32/cpu.c
@@ -588,7 +588,7 @@
 #endif
 		break;
 	default:
-		if (cpu_classes[cpu_class].class_option != NULL)
+		if (cpu_classes[cpu_class].class_option == NULL)
 			aprint_error("%s: %s does not fully support this CPU."
 			       "\n", dv->dv_xname, ostype);
 		else {

--------------070504010006050809010607--