/* * SPDX-License-Identifier: MIT * * Copyright © 2016 Intel Corporation */ #ifndef I915_SCATTERLIST_H #define I915_SCATTERLIST_H #include <linux/pfn.h> #include <linux/scatterlist.h> #include <linux/dma-mapping.h> #include <xen/xen.h> #include "i915_gem.h" struct drm_mm_node; struct ttm_resource; /* * Optimised SGL iterator for GEM objects */ static __always_inline struct sgt_iter { … } static inline int __sg_page_count(const struct scatterlist *sg) { … } static inline int __sg_dma_page_count(const struct scatterlist *sg) { … } static inline struct scatterlist *____sg_next(struct scatterlist *sg) { … } /** * __sg_next - return the next scatterlist entry in a list * @sg: The current sg entry * * Description: * If the entry is the last, return NULL; otherwise, step to the next * element in the array (@sg@+1). If that's a chain pointer, follow it; * otherwise just return the pointer to the current element. **/ static inline struct scatterlist *__sg_next(struct scatterlist *sg) { … } /** * __for_each_sgt_daddr - iterate over the device addresses of the given sg_table * @__dp: Device address (output) * @__iter: 'struct sgt_iter' (iterator state, internal) * @__sgt: sg_table to iterate over (input) * @__step: step size */ #define __for_each_sgt_daddr(__dp, __iter, __sgt, __step) … /** * __for_each_daddr_next - iterates over the device addresses with pre-initialized iterator. * @__dp: Device address (output) * @__iter: 'struct sgt_iter' (iterator state, external) * @__step: step size */ #define __for_each_daddr_next(__dp, __iter, __step) … /** * for_each_sgt_page - iterate over the pages of the given sg_table * @__pp: page pointer (output) * @__iter: 'struct sgt_iter' (iterator state, internal) * @__sgt: sg_table to iterate over (input) */ #define for_each_sgt_page(__pp, __iter, __sgt) … /** * i915_sg_dma_sizes - Record the dma segment sizes of a scatterlist * @sg: The scatterlist * * Return: An unsigned int with segment sizes logically or'ed together. * A caller can use this information to determine what hardware page table * entry sizes can be used to map the memory represented by the scatterlist. */ static inline unsigned int i915_sg_dma_sizes(struct scatterlist *sg) { … } static inline unsigned int i915_sg_segment_size(struct device *dev) { … } bool i915_sg_trim(struct sg_table *orig_st); /** * struct i915_refct_sgt_ops - Operations structure for struct i915_refct_sgt */ struct i915_refct_sgt_ops { … }; /** * struct i915_refct_sgt - A refcounted scatter-gather table * @kref: struct kref for refcounting * @table: struct sg_table holding the scatter-gather table itself. Note that * @table->sgl = NULL can be used to determine whether a scatter-gather table * is present or not. * @size: The size in bytes of the underlying memory buffer * @ops: The operations structure. */ struct i915_refct_sgt { … }; /** * i915_refct_sgt_put - Put a refcounted sg-table * @rsgt: the struct i915_refct_sgt to put. */ static inline void i915_refct_sgt_put(struct i915_refct_sgt *rsgt) { … } /** * i915_refct_sgt_get - Get a refcounted sg-table * @rsgt: the struct i915_refct_sgt to get. */ static inline struct i915_refct_sgt * i915_refct_sgt_get(struct i915_refct_sgt *rsgt) { … } /** * __i915_refct_sgt_init - Initialize a refcounted sg-list with a custom * operations structure * @rsgt: The struct i915_refct_sgt to initialize. * @size: Size in bytes of the underlying memory buffer. * @ops: A customized operations structure in case the refcounted sg-list * is embedded into another structure. */ static inline void __i915_refct_sgt_init(struct i915_refct_sgt *rsgt, size_t size, const struct i915_refct_sgt_ops *ops) { … } void i915_refct_sgt_init(struct i915_refct_sgt *rsgt, size_t size); struct i915_refct_sgt *i915_rsgt_from_mm_node(const struct drm_mm_node *node, u64 region_start, u32 page_alignment); struct i915_refct_sgt *i915_rsgt_from_buddy_resource(struct ttm_resource *res, u64 region_start, u32 page_alignment); #endif