Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/memremap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/rculist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/pfn_t.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "nfit_test.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static LIST_HEAD(iomap_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static struct iomap_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	nfit_test_lookup_fn nfit_test_lookup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	nfit_test_evaluate_dsm_fn evaluate_dsm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) } iomap_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	.list = LIST_HEAD_INIT(iomap_ops.list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) void nfit_test_setup(nfit_test_lookup_fn lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		nfit_test_evaluate_dsm_fn evaluate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	iomap_ops.nfit_test_lookup = lookup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	iomap_ops.evaluate_dsm = evaluate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	list_add_rcu(&iomap_ops.list, &iomap_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) EXPORT_SYMBOL(nfit_test_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) void nfit_test_teardown(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	list_del_rcu(&iomap_ops.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) EXPORT_SYMBOL(nfit_test_teardown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static struct nfit_test_resource *__get_nfit_res(resource_size_t resource)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct iomap_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	ops = list_first_or_null_rcu(&iomap_head, typeof(*ops), list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return ops->nfit_test_lookup(resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) struct nfit_test_resource *get_nfit_res(resource_size_t resource)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct nfit_test_resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	res = __get_nfit_res(resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) EXPORT_SYMBOL(get_nfit_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) void __iomem *__nfit_test_ioremap(resource_size_t offset, unsigned long size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		void __iomem *(*fallback_fn)(resource_size_t, unsigned long))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct nfit_test_resource *nfit_res = get_nfit_res(offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (nfit_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return (void __iomem *) nfit_res->buf + offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			- nfit_res->res.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	return fallback_fn(offset, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) void __iomem *__wrap_devm_ioremap(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		resource_size_t offset, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct nfit_test_resource *nfit_res = get_nfit_res(offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (nfit_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		return (void __iomem *) nfit_res->buf + offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			- nfit_res->res.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	return devm_ioremap(dev, offset, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) EXPORT_SYMBOL(__wrap_devm_ioremap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) void *__wrap_devm_memremap(struct device *dev, resource_size_t offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		size_t size, unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct nfit_test_resource *nfit_res = get_nfit_res(offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (nfit_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return nfit_res->buf + offset - nfit_res->res.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return devm_memremap(dev, offset, size, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) EXPORT_SYMBOL(__wrap_devm_memremap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static void nfit_test_kill(void *_pgmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct dev_pagemap *pgmap = _pgmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	WARN_ON(!pgmap || !pgmap->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (pgmap->ops && pgmap->ops->kill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		pgmap->ops->kill(pgmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		percpu_ref_kill(pgmap->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (pgmap->ops && pgmap->ops->cleanup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		pgmap->ops->cleanup(pgmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		wait_for_completion(&pgmap->done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		percpu_ref_exit(pgmap->ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static void dev_pagemap_percpu_release(struct percpu_ref *ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	struct dev_pagemap *pgmap =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		container_of(ref, struct dev_pagemap, internal_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	complete(&pgmap->done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) void *__wrap_devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	resource_size_t offset = pgmap->range.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct nfit_test_resource *nfit_res = get_nfit_res(offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (!nfit_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		return devm_memremap_pages(dev, pgmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (!pgmap->ref) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		if (pgmap->ops && (pgmap->ops->kill || pgmap->ops->cleanup))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		init_completion(&pgmap->done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		error = percpu_ref_init(&pgmap->internal_ref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				dev_pagemap_percpu_release, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			return ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		pgmap->ref = &pgmap->internal_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		if (!pgmap->ops || !pgmap->ops->kill || !pgmap->ops->cleanup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			WARN(1, "Missing reference count teardown definition\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	error = devm_add_action_or_reset(dev, nfit_test_kill, pgmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		return ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return nfit_res->buf + offset - nfit_res->res.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) EXPORT_SYMBOL_GPL(__wrap_devm_memremap_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) pfn_t __wrap_phys_to_pfn_t(phys_addr_t addr, unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct nfit_test_resource *nfit_res = get_nfit_res(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (nfit_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		flags &= ~PFN_MAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)         return phys_to_pfn_t(addr, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) EXPORT_SYMBOL(__wrap_phys_to_pfn_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) void *__wrap_memremap(resource_size_t offset, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct nfit_test_resource *nfit_res = get_nfit_res(offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (nfit_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		return nfit_res->buf + offset - nfit_res->res.start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return memremap(offset, size, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) EXPORT_SYMBOL(__wrap_memremap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) void __wrap_devm_memunmap(struct device *dev, void *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	struct nfit_test_resource *nfit_res = get_nfit_res((long) addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (nfit_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	return devm_memunmap(dev, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) EXPORT_SYMBOL(__wrap_devm_memunmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) void __iomem *__wrap_ioremap(resource_size_t offset, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	return __nfit_test_ioremap(offset, size, ioremap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) EXPORT_SYMBOL(__wrap_ioremap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) void __iomem *__wrap_ioremap_wc(resource_size_t offset, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return __nfit_test_ioremap(offset, size, ioremap_wc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) EXPORT_SYMBOL(__wrap_ioremap_wc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) void __wrap_iounmap(volatile void __iomem *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct nfit_test_resource *nfit_res = get_nfit_res((long) addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if (nfit_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	return iounmap(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) EXPORT_SYMBOL(__wrap_iounmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) void __wrap_memunmap(void *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct nfit_test_resource *nfit_res = get_nfit_res((long) addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (nfit_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	return memunmap(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) EXPORT_SYMBOL(__wrap_memunmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static bool nfit_test_release_region(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		struct resource *parent, resource_size_t start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		resource_size_t n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static void nfit_devres_release(struct device *dev, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct resource *res = *((struct resource **) data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	WARN_ON(!nfit_test_release_region(NULL, &iomem_resource, res->start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			resource_size(res)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int match(struct device *dev, void *__res, void *match_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct resource *res = *((struct resource **) __res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	resource_size_t start = *((resource_size_t *) match_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	return res->start == start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static bool nfit_test_release_region(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		struct resource *parent, resource_size_t start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		resource_size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (parent == &iomem_resource) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		struct nfit_test_resource *nfit_res = get_nfit_res(start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		if (nfit_res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			struct nfit_test_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			struct resource *res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 				devres_release(dev, nfit_devres_release, match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 						&start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 				return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			spin_lock(&nfit_res->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			list_for_each_entry(req, &nfit_res->requests, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 				if (req->res.start == start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 					res = &req->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 					list_del(&req->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			spin_unlock(&nfit_res->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			WARN(!res || resource_size(res) != n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 					"%s: start: %llx n: %llx mismatch: %pr\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 						__func__, start, n, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static struct resource *nfit_test_request_region(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		struct resource *parent, resource_size_t start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		resource_size_t n, const char *name, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	struct nfit_test_resource *nfit_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (parent == &iomem_resource) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		nfit_res = get_nfit_res(start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		if (nfit_res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			struct nfit_test_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			struct resource *res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			if (start + n > nfit_res->res.start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 					+ resource_size(&nfit_res->res)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 				pr_debug("%s: start: %llx n: %llx overflow: %pr\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 						__func__, start, n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 						&nfit_res->res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 				return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			spin_lock(&nfit_res->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			list_for_each_entry(req, &nfit_res->requests, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 				if (start == req->res.start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 					res = &req->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			spin_unlock(&nfit_res->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 				WARN(1, "%pr already busy\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 				return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			req = kzalloc(sizeof(*req), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			if (!req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 				return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			INIT_LIST_HEAD(&req->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			res = &req->res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			res->start = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			res->end = start + n - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			res->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			res->flags = resource_type(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			res->flags |= IORESOURCE_BUSY | flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			spin_lock(&nfit_res->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			list_add(&req->list, &nfit_res->requests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			spin_unlock(&nfit_res->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 				struct resource **d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 				d = devres_alloc(nfit_devres_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 						sizeof(struct resource *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 						GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 				if (!d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 					return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 				*d = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 				devres_add(dev, d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			pr_debug("%s: %pr\n", __func__, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		return __devm_request_region(dev, parent, start, n, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	return __request_region(parent, start, n, name, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct resource *__wrap___request_region(struct resource *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		resource_size_t start, resource_size_t n, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return nfit_test_request_region(NULL, parent, start, n, name, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) EXPORT_SYMBOL(__wrap___request_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) int __wrap_insert_resource(struct resource *parent, struct resource *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	if (get_nfit_res(res->start))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	return insert_resource(parent, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) EXPORT_SYMBOL(__wrap_insert_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) int __wrap_remove_resource(struct resource *res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	if (get_nfit_res(res->start))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	return remove_resource(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) EXPORT_SYMBOL(__wrap_remove_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) struct resource *__wrap___devm_request_region(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		struct resource *parent, resource_size_t start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		resource_size_t n, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	return nfit_test_request_region(dev, parent, start, n, name, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) EXPORT_SYMBOL(__wrap___devm_request_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) void __wrap___release_region(struct resource *parent, resource_size_t start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		resource_size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	if (!nfit_test_release_region(NULL, parent, start, n))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		__release_region(parent, start, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) EXPORT_SYMBOL(__wrap___release_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) void __wrap___devm_release_region(struct device *dev, struct resource *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		resource_size_t start, resource_size_t n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (!nfit_test_release_region(dev, parent, start, n))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		__devm_release_region(dev, parent, start, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) EXPORT_SYMBOL(__wrap___devm_release_region);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) acpi_status __wrap_acpi_evaluate_object(acpi_handle handle, acpi_string path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		struct acpi_object_list *p, struct acpi_buffer *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	struct nfit_test_resource *nfit_res = get_nfit_res((long) handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	union acpi_object **obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	if (!nfit_res || strcmp(path, "_FIT") || !buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		return acpi_evaluate_object(handle, path, p, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	obj = nfit_res->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	buf->length = sizeof(union acpi_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	buf->pointer = *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) EXPORT_SYMBOL(__wrap_acpi_evaluate_object);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) union acpi_object * __wrap_acpi_evaluate_dsm(acpi_handle handle, const guid_t *guid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		u64 rev, u64 func, union acpi_object *argv4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	union acpi_object *obj = ERR_PTR(-ENXIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	struct iomap_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	ops = list_first_or_null_rcu(&iomap_head, typeof(*ops), list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		obj = ops->evaluate_dsm(handle, guid, rev, func, argv4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	if (IS_ERR(obj))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		return acpi_evaluate_dsm(handle, guid, rev, func, argv4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	return obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) EXPORT_SYMBOL(__wrap_acpi_evaluate_dsm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) MODULE_LICENSE("GPL v2");