linux/drivers/staging/media/atomisp/pci/atomisp2/include/hmm/hmm_pool.h
<<
>>
Prefs
   1/*
   2 * Support for Medifield PNW Camera Imaging ISP subsystem.
   3 *
   4 * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
   5 *
   6 * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
   7 *
   8 * This program is free software; you can redistribute it and/or
   9 * modify it under the terms of the GNU General Public License version
  10 * 2 as published by the Free Software Foundation.
  11 *
  12 * This program is distributed in the hope that it will be useful,
  13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15 * GNU General Public License for more details.
  16 *
  17 *
  18 */
  19#ifndef __HMM_POOL_H__
  20#define __HMM_POOL_H__
  21
  22#include <linux/kernel.h>
  23#include <linux/slab.h>
  24#include <linux/list.h>
  25#include <linux/spinlock.h>
  26#include <linux/mutex.h>
  27#include <linux/kref.h>
  28#include "hmm_common.h"
  29#include "hmm/hmm_bo.h"
  30
  31#define ALLOC_PAGE_FAIL_NUM             5
  32
  33enum hmm_pool_type {
  34        HMM_POOL_TYPE_RESERVED,
  35        HMM_POOL_TYPE_DYNAMIC,
  36};
  37
  38/**
  39 * struct hmm_pool_ops  -  memory pool callbacks.
  40 *
  41 * @pool_init:             initialize the memory pool.
  42 * @pool_exit:             uninitialize the memory pool.
  43 * @pool_alloc_pages:      allocate pages from memory pool.
  44 * @pool_free_pages:       free pages to memory pool.
  45 * @pool_inited:           check whether memory pool is initialized.
  46 */
  47struct hmm_pool_ops {
  48        int (*pool_init)(void **pool, unsigned int pool_size);
  49        void (*pool_exit)(void **pool);
  50        unsigned int (*pool_alloc_pages)(void *pool,
  51                                        struct hmm_page_object *page_obj,
  52                                        unsigned int size, bool cached);
  53        void (*pool_free_pages)(void *pool,
  54                                struct hmm_page_object *page_obj);
  55        int (*pool_inited)(void *pool);
  56};
  57
  58struct hmm_pool {
  59        struct hmm_pool_ops     *pops;
  60
  61        void                    *pool_info;
  62};
  63
  64/**
  65 * struct hmm_reserved_pool_info  - represents reserved pool private data.
  66 * @pages:                          a array that store physical pages.
  67 *                                  The array is as reserved memory pool.
  68 * @index:                          to indicate the first blank page number
  69 *                                  in reserved memory pool(pages array).
  70 * @pgnr:                           the valid page amount in reserved memory
  71 *                                  pool.
  72 * @list_lock:                      list lock is used to protect the operation
  73 *                                  to reserved memory pool.
  74 * @flag:                           reserved memory pool state flag.
  75 */
  76struct hmm_reserved_pool_info {
  77        struct page             **pages;
  78
  79        unsigned int            index;
  80        unsigned int            pgnr;
  81        spinlock_t              list_lock;
  82        bool                    initialized;
  83};
  84
  85/**
  86 * struct hmm_dynamic_pool_info  -  represents dynamic pool private data.
  87 * @pages_list:                     a list that store physical pages.
  88 *                                  The pages list is as dynamic memory pool.
  89 * @list_lock:                      list lock is used to protect the operation
  90 *                                  to dynamic memory pool.
  91 * @flag:                           dynamic memory pool state flag.
  92 * @pgptr_cache:                    struct kmem_cache, manages a cache.
  93 */
  94struct hmm_dynamic_pool_info {
  95        struct list_head        pages_list;
  96
  97        /* list lock is used to protect the free pages block lists */
  98        spinlock_t              list_lock;
  99
 100        struct kmem_cache       *pgptr_cache;
 101        bool                    initialized;
 102
 103        unsigned int            pool_size;
 104        unsigned int            pgnr;
 105};
 106
 107struct hmm_page {
 108        struct page             *page;
 109        struct list_head        list;
 110};
 111
 112extern struct hmm_pool_ops      reserved_pops;
 113extern struct hmm_pool_ops      dynamic_pops;
 114
 115#endif
 116