On Tue, 2009-02-17 at 15:20 +0800, Peter Teoh wrote: > looking into kernel source, it seemed quite simple: > > ./sound/pci/emu10k1/memory.c: > #define get_aligned_page(offset) ((offset) >> PAGE_SHIFT) > blk->first_page = get_aligned_page(blk->mem.offset); > blk->last_page = get_aligned_page(blk->mem.offset + blk->mem.size > - 1); > psize = get_aligned_page(size + PAGE_SIZE -1); > page = get_aligned_page(offset); > > ./sound/pci/trident/trident_memory.c: > #define get_aligned_page(offset) ((offset) >> 12) > #define get_aligned_page(offset) ((offset) >> 13) > #define get_aligned_page(offset) ((offset) / ALIGN_PAGE_SIZE) > ptr = page_to_ptr(trident, get_aligned_page(offset)); > psize = get_aligned_page(size + ALIGN_PAGE_SIZE -1); > > ie, just AND with the alignement requirement. > > And the trident_memory.c:is_valid_page() function worked like this: > > /* > * check if the given pointer is valid for pages > */ > static int is_valid_page(unsigned long ptr) > { > if (ptr & ~0x3fffffffUL) { > snd_printk(KERN_ERR "max memory size is 1GB!!\n"); > return 0; > } > if (ptr & (SNDRV_TRIDENT_PAGE_SIZE-1)) { > snd_printk(KERN_ERR "page is not aligned\n"); > return 0; > } > return 1; > } > > So, as the last part shows, just AND the address with the alignment > requirement will do. > > But I have not looked else where. Please look at the snippet below and correct me if I am wrong #define ALIGN_SIZE 16 #define ALIGN_MASK ~(ALIGN_SIZE - 1) #define GET_ALIGNED_ADDR(x) (x & ALIGN_MASK) Wouldn't GET_ALIGNED_ADDR return aligned address? Regards - Himanshu -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ