Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
      3  *
      4  * Permission is hereby granted, free of charge, to any person obtaining a
      5  * copy of this software and associated documentation files (the
      6  * "Software"), to deal in the Software without restriction, including
      7  * without limitation the rights to use, copy, modify, merge, publish,
      8  * distribute, sub license, and/or sell copies of the Software, and to
      9  * permit persons to whom the Software is furnished to do so, subject to
     10  * the following conditions:
     11  *
     12  * The above copyright notice and this permission notice (including the
     13  * next paragraph) shall be included in all copies or substantial portions
     14  * of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
     19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
     20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     23  *
     24  * Authors:
     25  *    Binglin Chen <binglin.chen (at) intel.com>
     26  *
     27  */
     28 
     29 #include "psb_def.h"
     30 
     31 #ifdef HAVE_CONFIG_H
     32 #include "config.h"
     33 #endif
     34 
     35 #include <linux/types.h>
     36 #include <stdlib.h>
     37 #include <string.h>
     38 #include "psb_ws_driver.h"
     39 
     40 static struct _ValidateNode *
     41 psb_alloc(struct _WsbmVNodeFuncs *func, int type_id) {
     42     if (type_id == 0) {
     43         struct _PsbDrmValidateNode *vNode = malloc(sizeof(*vNode));
     44 
     45         if (vNode == NULL) return NULL;
     46 
     47         vNode->base.func = func;
     48         vNode->base.type_id = 0;
     49         return &vNode->base;
     50     } else {
     51         struct _ValidateNode *node = malloc(sizeof(*node));
     52 
     53         if (node == NULL) return NULL;
     54 
     55         node->func = func;
     56         node->type_id = 1;
     57         return node;
     58     }
     59 }
     60 
     61 /*
     62  * Free an allocated validate list node.
     63  */
     64 
     65 static void
     66 psb_free(struct _ValidateNode *node)
     67 {
     68     if (node->type_id == 0)
     69         free(containerOf(node, struct _PsbDrmValidateNode, base));
     70 
     71     else
     72         free(node);
     73 }
     74 
     75 /*
     76  * Clear the private part of the validate list node. This happens when
     77  * the list node is newly allocated or is being reused. Since we only have
     78  * a private part when node->type_id == 0 we only care to clear in that
     79  * case. We want to clear the drm ioctl argument.
     80  */
     81 
     82 static void
     83 psb_clear(struct _ValidateNode *node)
     84 {
     85     if (node->type_id == 0) {
     86         struct _PsbDrmValidateNode *vNode =
     87             containerOf(node, struct _PsbDrmValidateNode, base);
     88 
     89         memset(&vNode->val_arg.d.req, 0, sizeof(vNode->val_arg.d.req));
     90     }
     91 }
     92 
     93 static struct _WsbmVNodeFuncs psbVNode = {
     94     .alloc = psb_alloc,
     95     .free = psb_free,
     96     .clear = psb_clear,
     97 };
     98 
     99 struct _WsbmVNodeFuncs *
    100 psbVNodeFuncs(void) {
    101     return &psbVNode;
    102 }
    103