2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
25 #include <core/object.h>
26 #include <subdev/bar.h>
28 struct nouveau_barobj {
29 struct nouveau_object base;
30 struct nouveau_vma vma;
35 nouveau_barobj_ctor(struct nouveau_object *parent,
36 struct nouveau_object *engine,
37 struct nouveau_oclass *oclass, void *mem, u32 size,
38 struct nouveau_object **pobject)
40 struct nouveau_bar *bar = (void *)engine;
41 struct nouveau_barobj *barobj;
44 ret = nouveau_object_create(parent, engine, oclass, 0, &barobj);
45 *pobject = nv_object(barobj);
49 ret = bar->kmap(bar, mem, NV_MEM_ACCESS_RW, &barobj->vma);
53 barobj->iomem = bar->iomem + (u32)barobj->vma.offset;
58 nouveau_barobj_dtor(struct nouveau_object *object)
60 struct nouveau_bar *bar = (void *)object->engine;
61 struct nouveau_barobj *barobj = (void *)object;
63 bar->unmap(bar, &barobj->vma);
64 nouveau_object_destroy(&barobj->base);
68 nouveau_barobj_rd32(struct nouveau_object *object, u64 addr)
70 struct nouveau_barobj *barobj = (void *)object;
71 return ioread32_native(barobj->iomem + addr);
75 nouveau_barobj_wr32(struct nouveau_object *object, u64 addr, u32 data)
77 struct nouveau_barobj *barobj = (void *)object;
78 iowrite32_native(data, barobj->iomem + addr);
81 static struct nouveau_oclass
82 nouveau_barobj_oclass = {
83 .ofuncs = &(struct nouveau_ofuncs) {
84 .ctor = nouveau_barobj_ctor,
85 .dtor = nouveau_barobj_dtor,
86 .init = nouveau_object_init,
87 .fini = nouveau_object_fini,
88 .rd32 = nouveau_barobj_rd32,
89 .wr32 = nouveau_barobj_wr32,
94 nouveau_bar_alloc(struct nouveau_bar *bar, struct nouveau_object *parent,
95 struct nouveau_mem *mem, struct nouveau_object **pobject)
97 struct nouveau_object *engine = nv_object(bar);
98 return nouveau_object_ctor(parent, engine, &nouveau_barobj_oclass,
103 nouveau_bar_create_(struct nouveau_object *parent,
104 struct nouveau_object *engine,
105 struct nouveau_oclass *oclass, int length, void **pobject)
107 struct nouveau_device *device = nv_device(parent);
108 struct nouveau_bar *bar;
111 ret = nouveau_subdev_create_(parent, engine, oclass, 0, "BARCTL",
112 "bar", length, pobject);
117 bar->iomem = ioremap(pci_resource_start(device->pdev, 3),
118 pci_resource_len(device->pdev, 3));
123 nouveau_bar_destroy(struct nouveau_bar *bar)
127 nouveau_subdev_destroy(&bar->base);
131 _nouveau_bar_dtor(struct nouveau_object *object)
133 struct nouveau_bar *bar = (void *)object;
134 nouveau_bar_destroy(bar);