linux/drivers/staging/media/atomisp/pci/atomisp2/hrt/hive_isp_css_mm_hrt.c
<<
>>
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
  20#include "atomisp_internal.h"
  21
  22#include "hive_isp_css_mm_hrt.h"
  23#include "hmm/hmm.h"
  24
  25#define __page_align(size)      (((size) + (PAGE_SIZE-1)) & (~(PAGE_SIZE-1)))
  26
  27static void *my_userptr;
  28static unsigned my_num_pages;
  29static enum hrt_userptr_type my_usr_type;
  30
  31void hrt_isp_css_mm_set_user_ptr(void *userptr,
  32                                 unsigned int num_pages,
  33                                 enum hrt_userptr_type type)
  34{
  35        my_userptr = userptr;
  36        my_num_pages = num_pages;
  37        my_usr_type = type;
  38}
  39
  40static ia_css_ptr __hrt_isp_css_mm_alloc(size_t bytes, void *userptr,
  41                                    unsigned int num_pages,
  42                                    enum hrt_userptr_type type,
  43                                    bool cached)
  44{
  45#ifdef CONFIG_ION
  46        if (type == HRT_USR_ION)
  47                return hmm_alloc(bytes, HMM_BO_ION, 0,
  48                                         userptr, cached);
  49
  50#endif
  51        if (type == HRT_USR_PTR) {
  52                if (userptr == NULL)
  53                        return hmm_alloc(bytes, HMM_BO_PRIVATE, 0,
  54                                                 NULL, cached);
  55                else {
  56                        if (num_pages < ((__page_align(bytes)) >> PAGE_SHIFT))
  57                                dev_err(atomisp_dev,
  58                                         "user space memory size is less"
  59                                         " than the expected size..\n");
  60                        else if (num_pages > ((__page_align(bytes))
  61                                              >> PAGE_SHIFT))
  62                                dev_err(atomisp_dev,
  63                                         "user space memory size is"
  64                                         " large than the expected size..\n");
  65
  66                        return hmm_alloc(bytes, HMM_BO_USER, 0,
  67                                                 userptr, cached);
  68                }
  69        } else {
  70                dev_err(atomisp_dev, "user ptr type is incorrect.\n");
  71                return 0;
  72        }
  73}
  74
  75ia_css_ptr hrt_isp_css_mm_alloc(size_t bytes)
  76{
  77        return __hrt_isp_css_mm_alloc(bytes, my_userptr,
  78                                      my_num_pages, my_usr_type, false);
  79}
  80
  81ia_css_ptr hrt_isp_css_mm_alloc_user_ptr(size_t bytes, void *userptr,
  82                                    unsigned int num_pages,
  83                                    enum hrt_userptr_type type,
  84                                    bool cached)
  85{
  86        return __hrt_isp_css_mm_alloc(bytes, userptr, num_pages,
  87                                      type, cached);
  88}
  89
  90ia_css_ptr hrt_isp_css_mm_alloc_cached(size_t bytes)
  91{
  92        if (my_userptr == NULL)
  93                return hmm_alloc(bytes, HMM_BO_PRIVATE, 0, NULL,
  94                                                HMM_CACHED);
  95        else {
  96                if (my_num_pages < ((__page_align(bytes)) >> PAGE_SHIFT))
  97                        dev_err(atomisp_dev,
  98                                        "user space memory size is less"
  99                                        " than the expected size..\n");
 100                else if (my_num_pages > ((__page_align(bytes)) >> PAGE_SHIFT))
 101                        dev_err(atomisp_dev,
 102                                        "user space memory size is"
 103                                        " large than the expected size..\n");
 104
 105                return hmm_alloc(bytes, HMM_BO_USER, 0,
 106                                                my_userptr, HMM_CACHED);
 107        }
 108}
 109
 110ia_css_ptr hrt_isp_css_mm_calloc(size_t bytes)
 111{
 112        ia_css_ptr ptr = hrt_isp_css_mm_alloc(bytes);
 113        if (ptr)
 114                hmm_set(ptr, 0, bytes);
 115        return ptr;
 116}
 117
 118ia_css_ptr hrt_isp_css_mm_calloc_cached(size_t bytes)
 119{
 120        ia_css_ptr ptr = hrt_isp_css_mm_alloc_cached(bytes);
 121        if (ptr)
 122                hmm_set(ptr, 0, bytes);
 123        return ptr;
 124}
 125
 126