From owner-freebsd-hackers Sat Jan 29 10: 6:21 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from rover.village.org (rover.village.org [204.144.255.49]) by hub.freebsd.org (Postfix) with ESMTP id 70C0A14C39 for ; Sat, 29 Jan 2000 10:06:15 -0800 (PST) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (harmony.village.org [10.0.0.6]) by rover.village.org (8.9.3/8.9.3) with ESMTP id LAA18192; Sat, 29 Jan 2000 11:06:13 -0700 (MST) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (localhost.village.org [127.0.0.1]) by harmony.village.org (8.9.3/8.8.3) with ESMTP id LAA07899; Sat, 29 Jan 2000 11:06:16 -0700 (MST) Message-Id: <200001291806.LAA07899@harmony.village.org> To: YAMAMOTO Shigeru Subject: Re: how to allocate an alined address for a device? Cc: dfr@nlsystems.com, freebsd-hackers@FreeBSD.ORG In-reply-to: Your message of "Sat, 29 Jan 2000 22:24:54 +0900." <20000129222454T.shigeru@iij.ad.jp> References: <20000129222454T.shigeru@iij.ad.jp> Date: Sat, 29 Jan 2000 11:06:15 -0700 From: Warner Losh Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In message <20000129222454T.shigeru@iij.ad.jp> YAMAMOTO Shigeru writes: : + alignment_size = (1u << ((flags & RF_ALIGNMENT_MASK) >> RF_ALIGNMENT_SHIFT)); alignment_size = (1u << (RF_ALIGNMENT(flags))); : + 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); : +} I believe that this looks good. : +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)); : } This could more simply be stated as RF_ALIGNMENT_LOG2(ffs(size)). I don't think that it is really needed. : +#define RF_PCCARD_ATTR 0x10000 /* PCCARD attribute memory */ Please leave this in. It doesn't have anything to do with the changes you are making. Actually, I should remove it in an independent commit. I'll do it a different way for the WaveGear Avaitor driver I'm porting from NetBSD. Also for the XE driver. : +#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) You might want to add: #define RF_ALIGNMENT(x) (((x) & RF_ALIGNMENT_MASK) >> RF_ALIGNMENT_SHIFT) Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message