From owner-freebsd-hackers Sat Jan 29 5:29:38 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from mgo.iij.ad.jp (mgo.iij.ad.jp [202.232.15.6]) by hub.freebsd.org (Postfix) with ESMTP id 42D0916223 for ; Sat, 29 Jan 2000 05:25:31 -0800 (PST) (envelope-from shigeru@iij.ad.jp) Received: from ns.iij.ad.jp (root@ns.iij.ad.jp [192.168.2.8]) by mgo.iij.ad.jp (8.8.8/MGO1.0) with ESMTP id WAA05443; Sat, 29 Jan 2000 22:24:58 +0900 (JST) Received: from fs.iij.ad.jp (root@fs.iij.ad.jp [192.168.2.9]) by ns.iij.ad.jp (8.8.5/3.5Wpl7) with ESMTP id WAA16945; Sat, 29 Jan 2000 22:24:57 +0900 (JST) Received: from mercury.iij.ad.jp (mercury.iij.ad.jp [192.168.4.89]) by fs.iij.ad.jp (8.8.5/3.5Wpl7) with ESMTP id WAA22947; Sat, 29 Jan 2000 22:24:56 +0900 (JST) Received: from localhost (localhost [127.0.0.1]) by mercury.iij.ad.jp (8.9.3/3.5W) with ESMTP id WAA21069; Sat, 29 Jan 2000 22:24:55 +0900 (JST) To: dfr@nlsystems.com Cc: imp@village.org, freebsd-hackers@FreeBSD.ORG Subject: Re: how to allocate an alined address for a device? In-Reply-To: Your message of "Sat, 29 Jan 2000 11:05:47 +0000 (GMT)" References: X-Mailer: Mew version 1.93b38 on XEmacs 21.2 (Shinjuku) Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="--Next_Part(Sat_Jan_29_22:21:14_2000_914)--" Content-Transfer-Encoding: 7bit Message-Id: <20000129222454T.shigeru@iij.ad.jp> Date: Sat, 29 Jan 2000 22:24:54 +0900 From: YAMAMOTO Shigeru X-Dispatcher: imput version 991025(IM133) Lines: 101 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG ----Next_Part(Sat_Jan_29_22:21:14_2000_914)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit >>>>> "Doug" == Doug Rabson writes: >> Well, with just 6 bits one could handle any alignment requirement up to >> 2^(2^6). >> >> We have 6 bits left. If this were the alignment requirement, a value of >> 0 would mean 2^0 or 1, which is the current behavior. More restrictive >> alignment requirements could be encoded easily. No ABI or API change >> needed. >> >> #define RF_ALIGNMENT_MASK 0xfc00 >> #define RF_ALIGNMENT_SHIFT 10 >> #define RF_ALIGNMENT_LOG2(x) (x << RF_ALIGNMENT_SHIFT) Doug> That seems reasonable. We should implement this right after 4.0 is Doug> done. I re-write a code using Warner's idea. Thanks, ------- YAMAMOTO Shigeru Internet Initiative Japan Inc. Network Engineering Div. ----Next_Part(Sat_Jan_29_22:21:14_2000_914)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=align2.diff --- kern/subr_rman.c.org Tue Nov 16 08:28:57 1999 +++ kern/subr_rman.c Sat Jan 29 03:40:36 2000 @@ -227,7 +227,19 @@ continue; } rstart = max(s->r_start, start); - rend = min(s->r_end, max(start + count, end)); + if (flags & RF_ALIGNMENT_MASK) { + /* need to align an address */ + u_long aligned_rstart; + u_long alignment_size; + + alignment_size = (1u << ((flags & RF_ALIGNMENT_MASK) >> RF_ALIGNMENT_SHIFT)); + aligned_rstart = (rstart & (~alignment_size + 1u)); + if ((rstart & (~(~alignment_size + 1u))) != 0) { + aligned_rstart += alignment_size; + } + 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); @@ -608,4 +620,19 @@ rv = int_rman_release_resource(rm, r); simple_unlock(rm->rm_slock); return (rv); +} + +u_int32_t +rman_make_alignment_flags(int size) { + int i; + + for (i = 0; i < 32 && size > 0x01; i ++) { + size = (size >> 1); + } + + if (i > 31) { + i = 0; + } + + return(RF_ALIGNMENT_LOG2(i)); } --- sys/rman.h.org Mon Jan 10 08:48:52 2000 +++ sys/rman.h Sat Jan 29 03:44:40 2000 @@ -64,7 +64,11 @@ #define RF_WANTED 0x0010 /* somebody is waiting for this resource */ #define RF_FIRSTSHARE 0x0020 /* first in sharing list */ -#define RF_PCCARD_ATTR 0x10000 /* PCCARD attribute memory */ +#define RF_PCCARD_ATTR 0x10000 /* PCCARD attribute memory */ + +#define RF_ALIGNMENT_SHIFT 10 /* alignment size bit starts bit 10 */ +#define RF_ALIGNMENT_MASK (0x003F << RF_ALIGNMENT_SHIFT) /* resource address alignemnt size bit mask */ +#define RF_ALIGNMENT_LOG2(x) ((x) << RF_ALIGNMENT_SHIFT) enum rman_type { RMAN_UNINIT = 0, RMAN_GAUGE, RMAN_ARRAY }; @@ -91,6 +95,8 @@ struct resource *rman_reserve_resource(struct rman *rm, u_long start, u_long end, u_long count, u_int flags, struct device *dev); + +extern u_int32_t rman_make_alignment_flags __P((int size)); #define rman_get_start(r) ((r)->r_start) #define rman_get_end(r) ((r)->r_end) ----Next_Part(Sat_Jan_29_22:21:14_2000_914)---- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message