xref: /netbsd-src/sys/external/bsd/drm2/include/asm/page.h (revision c7e270a79b37fecc1b5d689ecdfd35a837b26df9)
1*c7e270a7Sriastradh /*	$NetBSD: page.h,v 1.3 2021/12/19 01:18:45 riastradh Exp $	*/
277b5597aSriastradh 
377b5597aSriastradh /*-
477b5597aSriastradh  * Copyright (c) 2014 The NetBSD Foundation, Inc.
577b5597aSriastradh  * All rights reserved.
677b5597aSriastradh  *
777b5597aSriastradh  * This code is derived from software contributed to The NetBSD Foundation
877b5597aSriastradh  * by Taylor R. Campbell.
977b5597aSriastradh  *
1077b5597aSriastradh  * Redistribution and use in source and binary forms, with or without
1177b5597aSriastradh  * modification, are permitted provided that the following conditions
1277b5597aSriastradh  * are met:
1377b5597aSriastradh  * 1. Redistributions of source code must retain the above copyright
1477b5597aSriastradh  *    notice, this list of conditions and the following disclaimer.
1577b5597aSriastradh  * 2. Redistributions in binary form must reproduce the above copyright
1677b5597aSriastradh  *    notice, this list of conditions and the following disclaimer in the
1777b5597aSriastradh  *    documentation and/or other materials provided with the distribution.
1877b5597aSriastradh  *
1977b5597aSriastradh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2077b5597aSriastradh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2177b5597aSriastradh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2277b5597aSriastradh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2377b5597aSriastradh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2477b5597aSriastradh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2577b5597aSriastradh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2677b5597aSriastradh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2777b5597aSriastradh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2877b5597aSriastradh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2977b5597aSriastradh  * POSSIBILITY OF SUCH DAMAGE.
3077b5597aSriastradh  */
3177b5597aSriastradh 
3277b5597aSriastradh #ifndef _ASM_PAGE_H_
3377b5597aSriastradh #define _ASM_PAGE_H_
3477b5597aSriastradh 
35*c7e270a7Sriastradh #include <sys/bitops.h>
3677b5597aSriastradh #include <sys/bus.h>
3777b5597aSriastradh 
3877b5597aSriastradh #include <uvm/uvm_page.h>
3977b5597aSriastradh 
4077b5597aSriastradh #include <linux/mm_types.h>
4177b5597aSriastradh 
4277b5597aSriastradh /*
4377b5597aSriastradh  * XXX Not sure why this is here, but so it is in Linux...  Also, not
4477b5597aSriastradh  * sure what the right type is: Linux uses dma_addr_t, but I don't
4577b5597aSriastradh  * think bus_addr_t is right here -- paddr_t sounds more appropriate.
4677b5597aSriastradh  */
4777b5597aSriastradh 
4877b5597aSriastradh static inline bus_addr_t
page_to_phys(struct page * page)4977b5597aSriastradh page_to_phys(struct page *page)
5077b5597aSriastradh {
5177b5597aSriastradh 	return VM_PAGE_TO_PHYS(&page->p_vmp);
5277b5597aSriastradh }
5377b5597aSriastradh 
54b81c64e1Sriastradh static inline unsigned long
page_to_pfn(struct page * page)55b81c64e1Sriastradh page_to_pfn(struct page *page)
56b81c64e1Sriastradh {
57b81c64e1Sriastradh 	return (page_to_phys(page) >> PAGE_SHIFT);
58b81c64e1Sriastradh }
59b81c64e1Sriastradh 
60*c7e270a7Sriastradh static inline size_t
get_order(size_t n)61*c7e270a7Sriastradh get_order(size_t n)
62*c7e270a7Sriastradh {
63*c7e270a7Sriastradh 	return fls64((n - 1) >> PAGE_SHIFT);
64*c7e270a7Sriastradh }
65*c7e270a7Sriastradh 
6677b5597aSriastradh #endif	/* _ASM_PAGE_H_ */
67