1/* $NetBSD: nouveau_subdev_fb_ramnvaa.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $ */
2
3/*
4 * Copyright 2013 Red Hat Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Ben Skeggs
25 */
26
27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_fb_ramnvaa.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $");
29
30#include "nv50.h"
31
32static int
33nvaa_ram_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
34 struct nouveau_oclass *oclass, void *data, u32 datasize,
35 struct nouveau_object **pobject)
36{
37 const u32 rsvd_head = ( 256 * 1024) >> 12; /* vga memory */
38 const u32 rsvd_tail = (1024 * 1024) >> 12; /* vbios etc */
39 struct nouveau_fb *pfb = nouveau_fb(parent);
40 struct nouveau_ram *ram;
41 int ret;
42
43 ret = nouveau_ram_create(parent, engine, oclass, &ram);
44 *pobject = nv_object(ram);
45 if (ret)
46 return ret;
47
48 ram->size = nv_rd32(pfb, 0x10020c);
49 ram->size = (ram->size & 0xffffff00) | ((ram->size & 0x000000ff) << 32);
50
51 ret = nouveau_mm_init(&pfb->vram, rsvd_head, (ram->size >> 12) -
52 (rsvd_head + rsvd_tail), 1);
53 if (ret)
54 return ret;
55
56 ram->type = NV_MEM_TYPE_STOLEN;
57 ram->stolen = (u64)nv_rd32(pfb, 0x100e10) << 12;
58 ram->get = nv50_ram_get;
59 ram->put = nv50_ram_put;
60 return 0;
61}
62
63struct nouveau_oclass
64nvaa_ram_oclass = {
65 .ofuncs = &(struct nouveau_ofuncs) {
66 .ctor = nvaa_ram_ctor,
67 .dtor = _nouveau_ram_dtor,
68 .init = _nouveau_ram_init,
69 .fini = _nouveau_ram_fini,
70 },
71};
72