Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
base.c
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Ben Skeggs
23  */
24 
25 #include <core/object.h>
26 #include <core/class.h>
27 
28 #include <subdev/fb.h>
29 #include <engine/dmaobj.h>
30 
31 int
33  struct nouveau_object *engine,
34  struct nouveau_oclass *oclass,
35  void *data, u32 size, int len, void **pobject)
36 {
37  struct nv_dma_class *args = data;
38  struct nouveau_dmaobj *object;
39  int ret;
40 
41  if (size < sizeof(*args))
42  return -EINVAL;
43 
44  ret = nouveau_object_create_(parent, engine, oclass, 0, len, pobject);
45  object = *pobject;
46  if (ret)
47  return ret;
48 
49  switch (args->flags & NV_DMA_TARGET_MASK) {
50  case NV_DMA_TARGET_VM:
51  object->target = NV_MEM_TARGET_VM;
52  break;
53  case NV_DMA_TARGET_VRAM:
54  object->target = NV_MEM_TARGET_VRAM;
55  break;
56  case NV_DMA_TARGET_PCI:
57  object->target = NV_MEM_TARGET_PCI;
58  break;
60  case NV_DMA_TARGET_AGP:
61  object->target = NV_MEM_TARGET_PCI_NOSNOOP;
62  break;
63  default:
64  return -EINVAL;
65  }
66 
67  switch (args->flags & NV_DMA_ACCESS_MASK) {
68  case NV_DMA_ACCESS_VM:
69  object->access = NV_MEM_ACCESS_VM;
70  break;
71  case NV_DMA_ACCESS_RD:
72  object->access = NV_MEM_ACCESS_RO;
73  break;
74  case NV_DMA_ACCESS_WR:
75  object->access = NV_MEM_ACCESS_WO;
76  break;
77  case NV_DMA_ACCESS_RDWR:
78  object->access = NV_MEM_ACCESS_RW;
79  break;
80  default:
81  return -EINVAL;
82  }
83 
84  object->start = args->start;
85  object->limit = args->limit;
86  return 0;
87 }