Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Jan 2000 13:43:10 +0900
From:      YAMAMOTO Shigeru <shigeru@iij.ad.jp>
To:        imp@village.org
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: how to allocate an alined address for a device? 
Message-ID:  <20000128134310D.shigeru@iij.ad.jp>
In-Reply-To: Your message of "Tue, 18 Jan 2000 16:15:36 -0700" <200001182315.QAA20891@harmony.village.org>
References:  <200001182315.QAA20891@harmony.village.org>

next in thread | previous in thread | raw e-mail | index | archive | help
----Next_Part(Fri_Jan_28_13:42:12_2000_229)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


>>>>> "Warner" == Warner Losh <Warner> writes:
Warner> In a cardbus system, one would force the alignment in the card bus
Warner> bridge.  It would reject those things that aren't aligned in a sane
Warner> manner for cardbus.  It would try again to get a different range, if
Warner> possible, or would reject the attempt.

I think it is no good to try again to get a different range.
Because, a different system has a different free address range and a device
dirver can not know where is a free address range.

So I change rman_reserve_resource() in @src/sys/kern/subr_rman.c for we can
allocate an aligned address.

My idea is using high bits of flags.
RF_ALIGN_XXX in aflags specifies an alignment request and an alignment
size.
Bad point of my idea is that we need to use a different bit for each an
alignment size.

This is a patch for @src/sys/kern/subr_rman.c (rev. 1.10) and
@src/sys/sys/rman.h (rev. 1.5)

Is my idea good or not?

Thanks,

-------
YAMAMOTO Shigeru			Internet Initiative Japan Inc.
<shigeru@iij.ad.jp>			Network Engineering Div.

----Next_Part(Fri_Jan_28_13:42:12_2000_229)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=align.diff

--- kern/subr_rman.c.org	Tue Nov 16 08:28:57 1999
+++ kern/subr_rman.c	Thu Jan 27 02:33:03 2000
@@ -227,7 +227,17 @@
 			continue;
 		}
 		rstart = max(s->r_start, start);
-		rend = min(s->r_end, max(start + count, end));
+		if (flags & RF_ALIGN_MASK) {
+		/* need to align an address */
+			u_long	aligned_rstart;
+
+			aligned_rstart = (rstart & (~((u_long)(flags & RF_ALIGN_MASK)) + 1u));
+			if ((rstart & (~(~((u_long)(flags & RF_ALIGN_MASK)) + 1u))) != 0) {
+				aligned_rstart += ((u_long)(flags & RF_ALIGN_MASK));
+			}
+			rstart = aligned_rstart;
+		}
+		rend = min(s->r_end, max(max(start + count, end), rstart + count));
 #ifdef RMAN_DEBUG
 		printf("truncated region: [%#lx, %#lx]; size %#lx (requested %#lx)\n",
 		       rstart, rend, (rend - rstart + 1), count);
--- sys/rman.h.org	Mon Jan 10 08:48:52 2000
+++ sys/rman.h	Thu Jan 27 02:36:51 2000
@@ -57,14 +57,33 @@
 	struct	rman *r_rm;	/* resource manager from whence this came */
 };
 
-#define	RF_ALLOCATED	0x0001	/* resource has been reserved */
-#define	RF_ACTIVE	0x0002	/* resource allocation has been activated */
-#define	RF_SHAREABLE	0x0004	/* resource permits contemporaneous sharing */
-#define	RF_TIMESHARE	0x0008	/* resource permits time-division sharing */
-#define	RF_WANTED	0x0010	/* somebody is waiting for this resource */
-#define	RF_FIRSTSHARE	0x0020	/* first in sharing list */
+#define	RF_ALLOCATED	0x00000001	/* resource has been reserved */
+#define	RF_ACTIVE	0x00000002	/* resource allocation has been activated */
+#define	RF_SHAREABLE	0x00000004	/* resource permits contemporaneous sharing */
+#define	RF_TIMESHARE	0x00000008	/* resource permits time-division sharing */
+#define	RF_WANTED	0x00000010	/* somebody is waiting for this resource */
+#define	RF_FIRSTSHARE	0x00000020	/* first in sharing list */
 
-#define RF_PCCARD_ATTR	0x10000 /* PCCARD attribute memory */
+#define RF_ALIGN_4K	0x00001000	/* require 4K byte address alignment */
+#define RF_ALIGN_8K	0x00002000	/* require 8K byte address alignment */
+#define RF_ALIGN_16K	0x00004000	/* require 16K byte address alignment */
+#define RF_ALIGN_32K	0x00008000	/* require 32K byte address alignment */
+#define RF_ALIGN_64K	0x00010000	/* require 64K byte address alignment */
+#define RF_ALIGN_128K	0x00020000	/* require 128K byte address alignment */
+#define RF_ALIGN_256K	0x00040000	/* require 256K byte address alignment */
+#define RF_ALIGN_512K	0x00080000	/* require 512K byte address alignment */
+#define RF_ALIGN_1M	0x00100000	/* require 1M byte address alignment */
+#define RF_ALIGN_2M	0x00200000	/* require 2M byte address alignment */
+#define RF_ALIGN_4M	0x00400000	/* require 4M byte address alignment */
+#define RF_ALIGN_8M	0x00800000	/* require 8M byte address alignment */
+#if 0	/* XXX Is there a device which requires more large address alignment? */
+#define RF_ALIGN_16M	0x01000000	/* require 16M byte address alignment */
+#define RF_ALIGN_32M	0x02000000	/* require 32M byte address alignment */
+#define RF_ALIGN_64M	0x04000000	/* require 64M byte address alignment */
+#define RF_ALIGN_128M	0x08000000	/* require 128M byte address alignment */
+#endif
+#define	RF_ALIGN_MASK	0x00FFF000	/* mask for RF_ALIGN_XX */
+#define	RF_PCCARD_ATTR	RF_ALIGN_4K	/* PCCARD attribute memory */
 
 enum	rman_type { RMAN_UNINIT = 0, RMAN_GAUGE, RMAN_ARRAY };
 

----Next_Part(Fri_Jan_28_13:42:12_2000_229)----


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




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