linux/include/media/frame_vector.h
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2#ifndef _MEDIA_FRAME_VECTOR_H
   3#define _MEDIA_FRAME_VECTOR_H
   4
   5/* Container for pinned pfns / pages in frame_vector.c */
   6struct frame_vector {
   7        unsigned int nr_allocated;      /* Number of frames we have space for */
   8        unsigned int nr_frames; /* Number of frames stored in ptrs array */
   9        bool got_ref;           /* Did we pin pages by getting page ref? */
  10        bool is_pfns;           /* Does array contain pages or pfns? */
  11        void *ptrs[];           /* Array of pinned pfns / pages. Use
  12                                 * pfns_vector_pages() or pfns_vector_pfns()
  13                                 * for access */
  14};
  15
  16struct frame_vector *frame_vector_create(unsigned int nr_frames);
  17void frame_vector_destroy(struct frame_vector *vec);
  18int get_vaddr_frames(unsigned long start, unsigned int nr_pfns,
  19                     struct frame_vector *vec);
  20void put_vaddr_frames(struct frame_vector *vec);
  21int frame_vector_to_pages(struct frame_vector *vec);
  22void frame_vector_to_pfns(struct frame_vector *vec);
  23
  24static inline unsigned int frame_vector_count(struct frame_vector *vec)
  25{
  26        return vec->nr_frames;
  27}
  28
  29static inline struct page **frame_vector_pages(struct frame_vector *vec)
  30{
  31        if (vec->is_pfns) {
  32                int err = frame_vector_to_pages(vec);
  33
  34                if (err)
  35                        return ERR_PTR(err);
  36        }
  37        return (struct page **)(vec->ptrs);
  38}
  39
  40static inline unsigned long *frame_vector_pfns(struct frame_vector *vec)
  41{
  42        if (!vec->is_pfns)
  43                frame_vector_to_pfns(vec);
  44        return (unsigned long *)(vec->ptrs);
  45}
  46
  47#endif /* _MEDIA_FRAME_VECTOR_H */
  48