Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Feb 2016 07:20:54 +0000
From:      "Sgalabov_gmail.com (Stanislav Galabov)" <phabric-noreply@FreeBSD.org>
To:        freebsd-mips@freebsd.org
Subject:   [Differential] [Request, 243 lines] D5184: Remove bus_space_fdt for MIPS and make bus_space_generic handle things properly
Message-ID:  <differential-rev-PHID-DREV-jbgadikog5rvcfxbnt6p-req@FreeBSD.org>

next in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Sgalabov_gmail.com created this revision.
Sgalabov_gmail.com added reviewers: MIPS, adrian, kan.
Sgalabov_gmail.com added a subscriber: freebsd-mips-list.
Sgalabov_gmail.com set the repository for this revision to rS FreeBSD src repository.
Sgalabov_gmail.com added a project: MIPS.
Herald added a subscriber: imp.

REVISION SUMMARY
  This patch removes the bus_space_fdt from the MIPS platforms and makes bus_space_generic properly map/unmap memory (using pmap_mapdev and pmap_unmapdev respectively) so that resources are properly managed.
  
  This work has been done by Alexander Kabaev for his CI20 port, but I am also using it for the Ralink/Mediatek work, so I have tried to extract it from his work and am submitting it here for review.

REPOSITORY
  rS FreeBSD src repository

REVISION DETAIL
  https://reviews.freebsd.org/D5184

AFFECTED FILES
  sys/conf/files.mips
  sys/mips/include/bus.h
  sys/mips/include/fdt.h
  sys/mips/mips/bus_space_fdt.c
  sys/mips/mips/bus_space_generic.c
  sys/mips/mips/nexus.c

EMAIL PREFERENCES
  https://reviews.freebsd.org/settings/panel/emailpreferences/

To: Sgalabov_gmail.com, MIPS, adrian, kan
Cc: imp, freebsd-mips-list

[-- Attachment #2 --]
diff --git a/sys/mips/mips/nexus.c
 b/sys/mips/mips/nexus.c
--- a/sys/mips/mips/nexus.c
+++ b/sys/mips/mips/nexus.c
@@ -422,23 +422,16 @@
 		paddr = rman_get_start(r);
 		psize = rman_get_size(r);
 #ifdef FDT
-		err = bus_space_map(fdtbus_bs_tag, paddr, psize, 0,
+		rman_set_bustag(r, fdtbus_bs_tag);
+#else
+		rman_set_bustag(r, mips_bus_space_generic);
+#endif
+		err = bus_space_map(rman_get_bustag(r), paddr, psize, 0,
 		    (bus_space_handle_t *)&vaddr);
 		if (err != 0) {
 			rman_deactivate_resource(r);
 			return (err);
 		}
-		rman_set_bustag(r, fdtbus_bs_tag);
-#else
-		vaddr = (bus_space_handle_t)pmap_mapdev(paddr,
-		    (vm_size_t)psize);
-		if (vaddr == 0) {
-			rman_deactivate_resource(r);
-			return (ENOMEM);
-		}
-		rman_set_bustag(r, mips_bus_space_generic);
-#endif
-
 		rman_set_virtual(r, vaddr);
 		rman_set_bushandle(r, (bus_space_handle_t)(uintptr_t)vaddr);
 	}
@@ -457,11 +450,7 @@
 
 	if (type == SYS_RES_MEMORY && vaddr != 0) {
 		psize = (bus_size_t)rman_get_size(r);
-#ifdef FDT
-		bus_space_unmap(fdtbus_bs_tag, vaddr, psize);
-#else
-		pmap_unmapdev((vm_offset_t)vaddr, psize);
-#endif
+		bus_space_unmap(rman_get_bustag(r), vaddr, psize);
 		rman_set_virtual(r, NULL);
 		rman_set_bushandle(r, 0);
 	}
diff --git a/sys/mips/mips/bus_space_generic.c
 b/sys/mips/mips/bus_space_generic.c
--- a/sys/mips/mips/bus_space_generic.c
+++ b/sys/mips/mips/bus_space_generic.c
@@ -228,20 +228,21 @@
 
 int
 generic_bs_map(void *t __unused, bus_addr_t addr,
-	      bus_size_t size __unused, int flags __unused,
+	      bus_size_t size, int flags __unused,
 	      bus_space_handle_t *bshp)
 {
 
-	*bshp = addr;
+	*bshp = (bus_space_handle_t)pmap_mapdev((vm_paddr_t)addr,
+	    (vm_size_t)size);
 	return (0);
 }
 
 void
-generic_bs_unmap(void *t __unused, bus_space_handle_t bh __unused,
-	      bus_size_t size __unused)
+generic_bs_unmap(void *t __unused, bus_space_handle_t bh,
+	      bus_size_t size)
 {
 
-	/* Do nothing */
+	pmap_unmapdev((vm_offset_t)bh, (vm_size_t)size);
 }
 
 int
diff --git a/sys/mips/mips/bus_space_fdt.c
 b/sys/mips/mips/bus_space_fdt.c
deleted file mode 100644
--- a/sys/mips/mips/bus_space_fdt.c
+++ /dev/null
@@ -1,205 +0,0 @@
-/*      $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $    */
-/*-
- * $Id: bus.h,v 1.6 2007/08/09 11:23:32 katta Exp $
- *
- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
- * NASA Ames Research Center.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
- * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed by Christopher G. Demetriou
- *	for the NetBSD Project.
- * 4. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *	from: src/sys/alpha/include/bus.h,v 1.5 1999/08/28 00:38:40 peter
- * $FreeBSD$
- */
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <sys/ktr.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-#include <vm/vm_kern.h>
-#include <vm/vm_extern.h>
-
-#include <machine/bus.h>
-#include <machine/cache.h>
-
-static int	fdt_bs_map(void *, bus_addr_t, bus_size_t, int,
-		    bus_space_handle_t *);
-
-static struct bus_space fdt_space = {
-	/* cookie */
-	.bs_cookie =	(void *) 0,
-
-	/* mapping/unmapping */
-	.bs_map =	fdt_bs_map,
-	.bs_unmap =	generic_bs_unmap,
-	.bs_subregion =	generic_bs_subregion,
-
-	/* allocation/deallocation */
-	.bs_alloc =	generic_bs_alloc,
-	.bs_free =	generic_bs_free,
-
-	/* barrier */
-	.bs_barrier =	generic_bs_barrier,
-
-	/* read (single) */
-	.bs_r_1 =	generic_bs_r_1,
-	.bs_r_2 =	generic_bs_r_2,
-	.bs_r_4 =	generic_bs_r_4,
-	.bs_r_8 =	generic_bs_r_8,
-
-	/* read multiple */
-	.bs_rm_1 =	generic_bs_rm_1,
-	.bs_rm_2 =	generic_bs_rm_2,
-	.bs_rm_4 =	generic_bs_rm_4,
-	.bs_rm_8 =	generic_bs_rm_8,
-
-	/* read region */
-	.bs_rr_1 =	generic_bs_rr_1,
-	.bs_rr_2 =	generic_bs_rr_2,
-	.bs_rr_4 =	generic_bs_rr_4,
-	.bs_rr_8 =	generic_bs_rr_8,
-
-	/* write (single) */
-	.bs_w_1 =	generic_bs_w_1,
-	.bs_w_2 =	generic_bs_w_2,
-	.bs_w_4 =	generic_bs_w_4,
-	.bs_w_8 =	generic_bs_w_8,
-
-	/* write multiple */
-	.bs_wm_1 =	generic_bs_wm_1,
-	.bs_wm_2 =	generic_bs_wm_2,
-	.bs_wm_4 =	generic_bs_wm_4,
-	.bs_wm_8 =	generic_bs_wm_8,
-
-	/* write region */
-	.bs_wr_1 =	generic_bs_wr_1,
-	.bs_wr_2 =	generic_bs_wr_2,
-	.bs_wr_4 =	generic_bs_wr_4,
-	.bs_wr_8 =	generic_bs_wr_8,
-
-	/* set multiple */
-	.bs_sm_1 =	generic_bs_sm_1,
-	.bs_sm_2 =	generic_bs_sm_2,
-	.bs_sm_4 =	generic_bs_sm_4,
-	.bs_sm_8 =	generic_bs_sm_8,
-
-	/* set region */
-	.bs_sr_1 =	generic_bs_sr_1,
-	.bs_sr_2 =	generic_bs_sr_2,
-	.bs_sr_4 =	generic_bs_sr_4,
-	.bs_sr_8 =	generic_bs_sr_8,
-
-	/* copy */
-	.bs_c_1 =	generic_bs_c_1,
-	.bs_c_2 =	generic_bs_c_2,
-	.bs_c_4 =	generic_bs_c_4,
-	.bs_c_8 =	generic_bs_c_8,
-
-	/* read (single) stream */
-	.bs_r_1_s =	generic_bs_r_1,
-	.bs_r_2_s =	generic_bs_r_2,
-	.bs_r_4_s =	generic_bs_r_4,
-	.bs_r_8_s =	generic_bs_r_8,
-
-	/* read multiple stream */
-	.bs_rm_1_s =	generic_bs_rm_1,
-	.bs_rm_2_s =	generic_bs_rm_2,
-	.bs_rm_4_s =	generic_bs_rm_4,
-	.bs_rm_8_s =	generic_bs_rm_8,
-
-	/* read region stream */
-	.bs_rr_1_s =	generic_bs_rr_1,
-	.bs_rr_2_s =	generic_bs_rr_2,
-	.bs_rr_4_s =	generic_bs_rr_4,
-	.bs_rr_8_s =	generic_bs_rr_8,
-
-	/* write (single) stream */
-	.bs_w_1_s =	generic_bs_w_1,
-	.bs_w_2_s =	generic_bs_w_2,
-	.bs_w_4_s =	generic_bs_w_4,
-	.bs_w_8_s =	generic_bs_w_8,
-
-	/* write multiple stream */
-	.bs_wm_1_s =	generic_bs_wm_1,
-	.bs_wm_2_s =	generic_bs_wm_2,
-	.bs_wm_4_s =	generic_bs_wm_4,
-	.bs_wm_8_s =	generic_bs_wm_8,
-
-	/* write region stream */
-	.bs_wr_1_s =	generic_bs_wr_1,
-	.bs_wr_2_s =	generic_bs_wr_2,
-	.bs_wr_4_s =	generic_bs_wr_4,
-	.bs_wr_8_s =	generic_bs_wr_8,
-};
-
-/* generic bus_space tag */
-bus_space_tag_t	mips_bus_space_fdt = &fdt_space;
-
-static int
-fdt_bs_map(void *t __unused, bus_addr_t addr, bus_size_t size __unused,
-    int flags __unused, bus_space_handle_t *bshp)
-{
-
-	*bshp = MIPS_PHYS_TO_DIRECT_UNCACHED(addr);
-	return (0);
-}
diff --git a/sys/mips/include/fdt.h
 b/sys/mips/include/fdt.h
--- a/sys/mips/include/fdt.h
+++ b/sys/mips/include/fdt.h
@@ -40,7 +40,7 @@
 #if defined(CPU_RMI) || defined(CPU_NLM)
 #define fdtbus_bs_tag	rmi_uart_bus_space
 #else
-#define fdtbus_bs_tag	mips_bus_space_fdt
+#define fdtbus_bs_tag	mips_bus_space_generic
 #endif
 
 #endif /* _MACHINE_FDT_H_ */
diff --git a/sys/mips/include/bus.h
 b/sys/mips/include/bus.h
--- a/sys/mips/include/bus.h
+++ b/sys/mips/include/bus.h
@@ -721,7 +721,6 @@
  */
 DECLARE_BUS_SPACE_PROTOTYPES(generic);
 extern bus_space_tag_t mips_bus_space_generic;
-extern bus_space_tag_t mips_bus_space_fdt;
 
 /* Special bus space for RMI processors */
 #if defined(CPU_RMI) || defined (CPU_NLM)
diff --git a/sys/conf/files.mips
 b/sys/conf/files.mips
--- a/sys/conf/files.mips
+++ b/sys/conf/files.mips
@@ -7,7 +7,6 @@
 # Arch dependent files
 mips/mips/autoconf.c			standard
 mips/mips/bus_space_generic.c		standard
-mips/mips/bus_space_fdt.c		optional	fdt
 mips/mips/busdma_machdep.c		standard
 mips/mips/cache.c			standard
 mips/mips/cache_mipsNN.c		standard


Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?differential-rev-PHID-DREV-jbgadikog5rvcfxbnt6p-req>