Changeset View
Changeset View
Standalone View
Standalone View
sys/vm/vm_extern.h
Show First 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | |||||
u_int vm_wait_count(void); | u_int vm_wait_count(void); | ||||
/* | /* | ||||
* Is pa a multiple of alignment, which is a power-of-two? | * Is pa a multiple of alignment, which is a power-of-two? | ||||
*/ | */ | ||||
static inline bool | static inline bool | ||||
vm_addr_align_ok(vm_paddr_t pa, u_long alignment) | vm_addr_align_ok(vm_paddr_t pa, u_long alignment) | ||||
{ | { | ||||
#ifdef INVARIANTS | |||||
if (!powerof2(alignment)) | |||||
panic("%s: alignment is not a power of 2: %#lx", | |||||
__func__, alignment); | |||||
#endif | |||||
return ((pa & (alignment - 1)) == 0); | return ((pa & (alignment - 1)) == 0); | ||||
dougm: For what it's worth, this could be written as
return (pa == rounddown2(pa, alignment)); | |||||
Not Done Inline ActionsI don't see how that makes anything clearer. On the other hand, using powerof2() provides clarity. alc: I don't see how that makes anything clearer. On the other hand, using powerof2() provides… | |||||
} | } | ||||
/* | /* | ||||
* Do the first and last addresses of a range match in all bits except the ones | * Do the first and last addresses of a range match in all bits except the ones | ||||
* in -boundary (a power-of-two)? For boundary == 0, all addresses match. | * in -boundary (a power-of-two)? For boundary == 0, all addresses match. | ||||
*/ | */ | ||||
static inline bool | static inline bool | ||||
vm_addr_bound_ok(vm_paddr_t pa, vm_paddr_t size, vm_paddr_t boundary) | vm_addr_bound_ok(vm_paddr_t pa, vm_paddr_t size, vm_paddr_t boundary) | ||||
{ | { | ||||
#ifdef INVARIANTS | |||||
if (!powerof2(boundary)) | |||||
panic("%s: boundary is not a power of 2: %#jx", | |||||
__func__, (uintmax_t)boundary); | |||||
Not Done Inline ActionsThere is no alignment argument for the function, it is boundary. And boundary has vm_paddr_t type, which makes it fail on most of 32bit arches. You need to use uintmax_t cast and %jx for format. BTW, it is better to use %#jx instead of manually adding 0x. kib: There is no alignment argument for the function, it is boundary. And boundary has vm_paddr_t… | |||||
#endif | |||||
return (((pa ^ (pa + size - 1)) & -boundary) == 0); | return (((pa ^ (pa + size - 1)) & -boundary) == 0); | ||||
Done Inline ActionsFor what it's worth, this could be written as return (rounddown2(pa + size - 1, boundary) <= pa); dougm: For what it's worth, this could be written as
return (rounddown2(pa + size - 1, boundary) <=… | |||||
} | } | ||||
static inline bool | static inline bool | ||||
vm_addr_ok(vm_paddr_t pa, vm_paddr_t size, u_long alignment, | vm_addr_ok(vm_paddr_t pa, vm_paddr_t size, u_long alignment, | ||||
vm_paddr_t boundary) | vm_paddr_t boundary) | ||||
{ | { | ||||
return (vm_addr_align_ok(pa, alignment) && | return (vm_addr_align_ok(pa, alignment) && | ||||
vm_addr_bound_ok(pa, size, boundary)); | vm_addr_bound_ok(pa, size, boundary)); | ||||
} | } | ||||
#endif /* _KERNEL */ | #endif /* _KERNEL */ | ||||
#endif /* !_VM_EXTERN_H_ */ | #endif /* !_VM_EXTERN_H_ */ |
For what it's worth, this could be written as
return (pa == rounddown2(pa, alignment));