1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright(c) 2015 Intel Deutschland GmbH
5 #ifndef __DEVCOREDUMP_H
6 #define __DEVCOREDUMP_H
8 #include <linux/device.h>
9 #include <linux/module.h>
10 #include <linux/vmalloc.h>
12 #include <linux/scatterlist.h>
13 #include <linux/slab.h>
16 * _devcd_free_sgtable - free all the memory of the given scatterlist table
17 * (i.e. both pages and scatterlist instances)
18 * NOTE: if two tables allocated and chained using the sg_chain function then
19 * this function should be called only once on the first table
20 * @table: pointer to sg_table to free
22 static inline void _devcd_free_sgtable(struct scatterlist *table)
26 struct scatterlist *iter;
27 struct scatterlist *delete_iter;
31 for_each_sg(table, iter, sg_nents(table), i) {
37 /* then free all chained tables */
39 delete_iter = table; /* always points on a head of a table */
40 while (!sg_is_last(iter)) {
42 if (sg_is_chain(iter)) {
43 iter = sg_chain_ptr(iter);
49 /* free the last table */
54 #ifdef CONFIG_DEV_COREDUMP
55 void dev_coredumpv(struct device *dev, void *data, size_t datalen,
58 void dev_coredumpm(struct device *dev, struct module *owner,
59 void *data, size_t datalen, gfp_t gfp,
60 ssize_t (*read)(char *buffer, loff_t offset, size_t count,
61 void *data, size_t datalen),
62 void (*free)(void *data));
64 void dev_coredumpsg(struct device *dev, struct scatterlist *table,
65 size_t datalen, gfp_t gfp);
67 static inline void dev_coredumpv(struct device *dev, void *data,
68 size_t datalen, gfp_t gfp)
74 dev_coredumpm(struct device *dev, struct module *owner,
75 void *data, size_t datalen, gfp_t gfp,
76 ssize_t (*read)(char *buffer, loff_t offset, size_t count,
77 void *data, size_t datalen),
78 void (*free)(void *data))
83 static inline void dev_coredumpsg(struct device *dev, struct scatterlist *table,
84 size_t datalen, gfp_t gfp)
86 _devcd_free_sgtable(table);
88 #endif /* CONFIG_DEV_COREDUMP */
90 #endif /* __DEVCOREDUMP_H */