linux/drivers/staging/dream/qdsp5/adsp_jpeg_verify_cmd.c
<<
>>
Prefs
   1/* arch/arm/mach-msm/qdsp5/adsp_jpeg_verify_cmd.c
   2 *
   3 * Verification code for aDSP JPEG packets from userspace.
   4 *
   5 * Copyright (c) 2008 QUALCOMM Incorporated
   6 * Copyright (C) 2008 Google, Inc.
   7 *
   8 * This software is licensed under the terms of the GNU General Public
   9 * License version 2, as published by the Free Software Foundation, and
  10 * may be copied, distributed, and modified under those terms.
  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#include <mach/qdsp5/qdsp5jpegcmdi.h>
  20#include "adsp.h"
  21
  22static uint32_t dec_fmt;
  23
  24static inline void get_sizes(jpeg_cmd_enc_cfg *cmd, uint32_t *luma_size,
  25                             uint32_t *chroma_size)
  26{
  27        uint32_t fmt, luma_width, luma_height;
  28
  29        fmt = cmd->process_cfg & JPEG_CMD_ENC_PROCESS_CFG_IP_DATA_FORMAT_M;
  30        luma_width = (cmd->ip_size_cfg & JPEG_CMD_IP_SIZE_CFG_LUMA_WIDTH_M)
  31                      >> 16;
  32        luma_height = cmd->frag_cfg & JPEG_CMD_FRAG_SIZE_LUMA_HEIGHT_M;
  33        *luma_size = luma_width * luma_height;
  34        if (fmt == JPEG_CMD_ENC_PROCESS_CFG_IP_DATA_FORMAT_H2V2)
  35                *chroma_size = *luma_size/2;
  36        else
  37                *chroma_size = *luma_size;
  38}
  39
  40static inline int verify_jpeg_cmd_enc_cfg(struct msm_adsp_module *module,
  41                                          void *cmd_data, size_t cmd_size)
  42{
  43        jpeg_cmd_enc_cfg *cmd = (jpeg_cmd_enc_cfg *)cmd_data;
  44        uint32_t luma_size, chroma_size;
  45        int i, num_frags;
  46
  47        if (cmd_size != sizeof(jpeg_cmd_enc_cfg)) {
  48                printk(KERN_ERR "adsp: module %s: JPEG ENC CFG invalid cmd_size %d\n",
  49                        module->name, cmd_size);
  50                return -1;
  51        }
  52
  53        get_sizes(cmd, &luma_size, &chroma_size);
  54        num_frags = (cmd->process_cfg >> 10) & 0xf;
  55        num_frags = ((num_frags == 1) ? num_frags : num_frags * 2);
  56        for (i = 0; i < num_frags; i += 2) {
  57                if (adsp_pmem_fixup(module, (void **)(&cmd->frag_cfg_part[i]), luma_size) ||
  58                    adsp_pmem_fixup(module, (void **)(&cmd->frag_cfg_part[i+1]), chroma_size))
  59                        return -1;
  60        }
  61
  62        if (adsp_pmem_fixup(module, (void **)&cmd->op_buf_0_cfg_part1,
  63                            cmd->op_buf_0_cfg_part2) ||
  64            adsp_pmem_fixup(module, (void **)&cmd->op_buf_1_cfg_part1,
  65                            cmd->op_buf_1_cfg_part2))
  66                return -1;
  67        return 0;
  68}
  69
  70static inline int verify_jpeg_cmd_dec_cfg(struct msm_adsp_module *module,
  71                                          void *cmd_data, size_t cmd_size)
  72{
  73        jpeg_cmd_dec_cfg *cmd = (jpeg_cmd_dec_cfg *)cmd_data;
  74        uint32_t div;
  75
  76        if (cmd_size != sizeof(jpeg_cmd_dec_cfg)) {
  77                printk(KERN_ERR "adsp: module %s: JPEG DEC CFG invalid cmd_size %d\n",
  78                        module->name, cmd_size);
  79                return -1;
  80        }
  81
  82        if (adsp_pmem_fixup(module, (void **)&cmd->ip_stream_buf_cfg_part1,
  83                            cmd->ip_stream_buf_cfg_part2) ||
  84            adsp_pmem_fixup(module, (void **)&cmd->op_stream_buf_0_cfg_part1,
  85                            cmd->op_stream_buf_0_cfg_part2) ||
  86            adsp_pmem_fixup(module, (void **)&cmd->op_stream_buf_1_cfg_part1,
  87                            cmd->op_stream_buf_1_cfg_part2))
  88                return -1;
  89        dec_fmt = cmd->op_data_format &
  90                JPEG_CMD_DEC_OP_DATA_FORMAT_M;
  91        div = (dec_fmt == JPEG_CMD_DEC_OP_DATA_FORMAT_H2V2) ? 2 : 1;
  92        if (adsp_pmem_fixup(module, (void **)&cmd->op_stream_buf_0_cfg_part3,
  93                            cmd->op_stream_buf_0_cfg_part2 / div) ||
  94            adsp_pmem_fixup(module, (void **)&cmd->op_stream_buf_1_cfg_part3,
  95                            cmd->op_stream_buf_1_cfg_part2 / div))
  96                return -1;
  97        return 0;
  98}
  99
 100static int verify_jpeg_cfg_cmd(struct msm_adsp_module *module,
 101                               void *cmd_data, size_t cmd_size)
 102{
 103        uint32_t cmd_id = ((uint32_t *)cmd_data)[0];
 104        switch(cmd_id) {
 105        case JPEG_CMD_ENC_CFG:
 106                return verify_jpeg_cmd_enc_cfg(module, cmd_data, cmd_size);
 107        case JPEG_CMD_DEC_CFG:
 108                return verify_jpeg_cmd_dec_cfg(module, cmd_data, cmd_size);
 109        default:
 110                if (cmd_id > 1) {
 111                        printk(KERN_ERR "adsp: module %s: invalid JPEG CFG cmd_id %d\n", module->name, cmd_id);
 112                        return -1;
 113                }
 114        }
 115        return 0;
 116}
 117
 118static int verify_jpeg_action_cmd(struct msm_adsp_module *module,
 119                                  void *cmd_data, size_t cmd_size)
 120{
 121        uint32_t cmd_id = ((uint32_t *)cmd_data)[0];
 122        switch (cmd_id) {
 123        case JPEG_CMD_ENC_OP_CONSUMED:
 124        {
 125                jpeg_cmd_enc_op_consumed *cmd =
 126                        (jpeg_cmd_enc_op_consumed *)cmd_data;
 127
 128                if (cmd_size != sizeof(jpeg_cmd_enc_op_consumed)) {
 129                        printk(KERN_ERR "adsp: module %s: JPEG_CMD_ENC_OP_CONSUMED invalid size %d\n",
 130                                module->name, cmd_size);
 131                        return -1;
 132                }
 133
 134                if (adsp_pmem_fixup(module, (void **)&cmd->op_buf_addr,
 135                                    cmd->op_buf_size))
 136                        return -1;
 137        }
 138        break;
 139        case JPEG_CMD_DEC_OP_CONSUMED:
 140        {
 141                uint32_t div;
 142                jpeg_cmd_dec_op_consumed *cmd =
 143                        (jpeg_cmd_dec_op_consumed *)cmd_data;
 144
 145                if (cmd_size != sizeof(jpeg_cmd_enc_op_consumed)) {
 146                        printk(KERN_ERR "adsp: module %s: JPEG_CMD_DEC_OP_CONSUMED invalid size %d\n",
 147                                module->name, cmd_size);
 148                        return -1;
 149                }
 150
 151                div = (dec_fmt == JPEG_CMD_DEC_OP_DATA_FORMAT_H2V2) ?  2 : 1;
 152                if (adsp_pmem_fixup(module, (void **)&cmd->luma_op_buf_addr,
 153                                    cmd->luma_op_buf_size) ||
 154                    adsp_pmem_fixup(module, (void **)&cmd->chroma_op_buf_addr,
 155                                    cmd->luma_op_buf_size / div))
 156                        return -1;
 157        }
 158        break;
 159        default:
 160                if (cmd_id > 7) {
 161                        printk(KERN_ERR "adsp: module %s: invalid cmd_id %d\n",
 162                                module->name, cmd_id);
 163                        return -1;
 164                }
 165        }
 166        return 0;
 167}
 168
 169int adsp_jpeg_verify_cmd(struct msm_adsp_module *module,
 170                         unsigned int queue_id, void *cmd_data,
 171                         size_t cmd_size)
 172{
 173        switch(queue_id) {
 174        case QDSP_uPJpegCfgCmdQueue:
 175                return verify_jpeg_cfg_cmd(module, cmd_data, cmd_size);
 176        case QDSP_uPJpegActionCmdQueue:
 177                return verify_jpeg_action_cmd(module, cmd_data, cmd_size);
 178        default:
 179                return -1;
 180        }
 181}
 182
 183
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.