Path: blob/main/sys/compat/linuxkpi/common/include/asm/set_memory.h
39604 views
/*-1* Copyright (c) 2010 Isilon Systems, Inc.2* Copyright (c) 2016 Matt Macy ([email protected])3* Copyright (c) 2017 Mellanox Technologies, Ltd.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice unmodified, this list of conditions, and the following11* disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR17* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES18* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.19* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,20* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT21* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,22* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF25* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26*/2728#ifndef _LINUXKPI_ASM_SET_MEMORY_H_29#define _LINUXKPI_ASM_SET_MEMORY_H_3031#include <linux/page.h>3233static inline int34set_memory_uc(unsigned long addr, int numpages)35{36vm_size_t len;3738len = (vm_size_t)numpages << PAGE_SHIFT;39return (-pmap_change_attr(addr, len, VM_MEMATTR_UNCACHEABLE));40}4142static inline int43set_memory_wc(unsigned long addr, int numpages)44{45#ifdef VM_MEMATTR_WRITE_COMBINING46vm_size_t len;4748len = (vm_size_t)numpages << PAGE_SHIFT;49return (-pmap_change_attr(addr, len, VM_MEMATTR_WRITE_COMBINING));50#else51return (set_memory_uc(addr, numpages));52#endif53}5455static inline int56set_memory_wb(unsigned long addr, int numpages)57{58vm_size_t len;5960len = (vm_size_t)numpages << PAGE_SHIFT;61return (-pmap_change_attr(addr, len, VM_MEMATTR_WRITE_BACK));62}6364static inline int65set_pages_uc(struct page *page, int numpages)66{67KASSERT(numpages == 1, ("%s: numpages %d", __func__, numpages));6869pmap_page_set_memattr(page, VM_MEMATTR_UNCACHEABLE);70return (0);71}7273static inline int74set_pages_wc(struct page *page, int numpages)75{76KASSERT(numpages == 1, ("%s: numpages %d", __func__, numpages));7778#ifdef VM_MEMATTR_WRITE_COMBINING79pmap_page_set_memattr(page, VM_MEMATTR_WRITE_COMBINING);80#else81return (set_pages_uc(page, numpages));82#endif83return (0);84}8586static inline int87set_pages_wb(struct page *page, int numpages)88{89KASSERT(numpages == 1, ("%s: numpages %d", __func__, numpages));9091pmap_page_set_memattr(page, VM_MEMATTR_WRITE_BACK);92return (0);93}9495static inline int96set_pages_array_wb(struct page **pages, int addrinarray)97{98int i;99100for (i = 0; i < addrinarray; i++)101set_pages_wb(pages[i], 1);102return (0);103}104105static inline int106set_pages_array_wc(struct page **pages, int addrinarray)107{108int i;109110for (i = 0; i < addrinarray; i++)111set_pages_wc(pages[i], 1);112return (0);113}114115static inline int116set_pages_array_uc(struct page **pages, int addrinarray)117{118int i;119120for (i = 0; i < addrinarray; i++)121set_pages_uc(pages[i], 1);122return (0);123}124125#endif /* _LINUXKPI_ASM_SET_MEMORY_H_ */126127128