Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Aug 2007 05:07:18 GMT
From:      "Constantine A. Murenin" <cnst@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 124760 for review
Message-ID:  <200708060507.l7657Isu023493@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=124760

Change 124760 by cnst@dale on 2007/08/06 05:06:23

	convert bus_space_map(9) to bus_alloc_resource(9)/rman_get_bus{tag,handle}(9).
	
	Some direction of which functions should and should not be used 
	was given by imp@, but appropriate usage was fine-tuned by manually 
	comparing how these functions are called in FreeBSD vs OpenBSD drivers.
	
	I.e. NetBSD's/OpenBSD's 'size' argument of type bus_size_t to bus_space_map(9)
	is called 'count' in FreeBSD's bus_alloc_resource(9) et al, even though most 
	drivers have a define called *IOSIZE that they pass as this 'count' value. 
	(Hence my question of why is it called 'count' on FreeBSD in the first place?)
	
	Can be quickly verified by comparing FreeBSD's dev/ex/if_ex{_isa.c,reg.h} to 
	OpenBSD's dev/isa/if_ex{.c,reg.h} (see EX_IOSIZE define on both systems),
	but many other drivers can be used for this comparison, too.
	
	Correctness was also verified by comparing the notation appearing in dmesg:
	
	OpenBSD:
		...
		lm0 at isa0 port 0x290/8: W83627DHG
		...
		pccom0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo
		...
	
	FreeBSD (before this patch or with a similar patch but using bus_alloc_resource_any):
		...
		sio0: <16550A-compatible COM port> port 0x3f8-0x3ff irq 4 flags 0x10 on acpi0
		...
		lm0: <Winbond W83627DHG Hardware Monitor> at port 0x290 on isa0
		...
	
	FreeBSD (after this patch, only lm0 part is shown below):
		...
		lm0: <Winbond W83627DHG Hardware Monitor> at port 0x290-0x297 on isa0
		...
	
	Anyhow, lm(4) continues to work, all recommended functions are used, and
	all newly introduced XXX are removed, so that's all that matters in the end.
	Also, I assume working through source-code instead of documentation adds
	some valuable flavour to the experience. :)

Affected files ...

.. //depot/projects/soc2007/cnst-sensors/sys.dev.lm/lm78_isa.c#5 edit

Differences ...

==== //depot/projects/soc2007/cnst-sensors/sys.dev.lm/lm78_isa.c#5 (text+ko) ====

@@ -1,4 +1,4 @@
-/*	$P4: //depot/projects/soc2007/cnst-sensors/sys.dev.lm/lm78_isa.c#4 $	*/
+/*	$P4: //depot/projects/soc2007/cnst-sensors/sys.dev.lm/lm78_isa.c#5 $	*/
 /*	$FreeBSD$	*/
 /*	$OpenBSD: lm78_isa.c,v 1.2 2007/07/01 21:48:57 cnst Exp $	*/
 
@@ -56,6 +56,8 @@
 struct lm_isa_softc {
 	struct lm_softc sc_lmsc;
 
+	struct resource *sc_iores;
+	int sc_iorid;
 	bus_space_tag_t sc_iot;
 	bus_space_handle_t sc_ioh;
 };
@@ -90,22 +92,20 @@
 lm_isa_probe(struct device *dev)
 {
 	struct lm_isa_softc *sc = device_get_softc(dev);
+	struct resource *iores;
+	int iorid = 0;
 	bus_space_tag_t iot;
-	bus_addr_t iobase;
 	bus_space_handle_t ioh;
 	int banksel, vendid, chipid, addr;
 
-	/* XXX */
-	iot = I386_BUS_SPACE_IO;
-	if (device_get_unit(dev) == 0)
-		iobase = 0x290;	/* XXX */
-	else
-		return (1);
-
-	if (bus_space_map(iot, iobase, 8, 0, &ioh)) {
+	iores = bus_alloc_resource(dev, SYS_RES_IOPORT, &iorid,
+	    0ul, ~0ul, 8, RF_ACTIVE);
+	if (iores == NULL) {
 		DPRINTF(("%s: can't map i/o space\n", __func__));
 		return (1);
 	}
+	iot = rman_get_bustag(iores);
+	ioh = rman_get_bushandle(iores);
 
 	/* Probe for Winbond chips. */
 	bus_space_write_1(iot, ioh, LMC_ADDR, WB_BANKSEL);
@@ -146,7 +146,7 @@
 	}
 
  notfound:
-	bus_space_unmap(iot, ioh, 8);
+	bus_release_resource(dev, SYS_RES_IOPORT, iorid, iores);
 
 	return (1);
 
@@ -159,16 +159,10 @@
 	sc->sc_lmsc.lm_readreg = lm_isa_readreg;
 	lm_probe(&sc->sc_lmsc);
 
-	bus_space_unmap(iot, ioh, 8);
+	bus_release_resource(dev, SYS_RES_IOPORT, iorid, iores);
+	sc->sc_iot = 0;
+	sc->sc_ioh = 0;
 
-#ifdef fixme
-	ia->ipa_nio = 1;
-	ia->ipa_io[0].length = 8;
-
-	ia->ipa_nmem = 0;
-	ia->ipa_nirq = 0;
-	ia->ipa_ndrq = 0;
-#endif
 	return (0);
 }
 
@@ -176,24 +170,20 @@
 lm_isa_attach(struct device *dev)
 {
 	struct lm_isa_softc *sc = device_get_softc(dev);
-	bus_addr_t iobase;
 #ifdef notyet
 	struct lm_softc *lmsc;
 	int i;
 	u_int8_t sbusaddr;
 #endif
 
-	sc->sc_iot = I386_BUS_SPACE_IO;
-
-	if (device_get_unit(dev) == 0)
-		iobase = 0x290;	/* XXX */
-	else
-		return (1);
-
-	if (bus_space_map(sc->sc_iot, iobase, 8, 0, &sc->sc_ioh)) {
+	sc->sc_iores = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->sc_iorid,
+	    0ul, ~0ul, 8, RF_ACTIVE);
+	if (sc->sc_iores == NULL) {
 		device_printf(dev, "can't map i/o space\n");
 		return (1);
 	}
+	sc->sc_iot = rman_get_bustag(sc->sc_iores);
+	sc->sc_ioh = rman_get_bushandle(sc->sc_iores);
 
 	/* Bus-independent attachment */
 	lm_attach(&sc->sc_lmsc);
@@ -235,7 +225,10 @@
 	if (error)
 		return (error);
 
-	bus_space_unmap(sc->sc_iot, sc->sc_ioh, 8);
+	error = bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_iorid,
+	    sc->sc_iores);
+	if (error)
+		return (error);
 
 	return (0);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708060507.l7657Isu023493>