| 1 | /* $NetBSD: nouveau_core_ramht.c,v 1.1.1.1 2014/08/06 12:36:24 riastradh Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2012 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 | |
| 25 | #include <sys/cdefs.h> |
| 26 | __KERNEL_RCSID(0, "$NetBSD: nouveau_core_ramht.c,v 1.1.1.1 2014/08/06 12:36:24 riastradh Exp $" ); |
| 27 | |
| 28 | #include <core/object.h> |
| 29 | #include <core/ramht.h> |
| 30 | |
| 31 | #include <subdev/bar.h> |
| 32 | |
| 33 | static u32 |
| 34 | nouveau_ramht_hash(struct nouveau_ramht *ramht, int chid, u32 handle) |
| 35 | { |
| 36 | u32 hash = 0; |
| 37 | |
| 38 | while (handle) { |
| 39 | hash ^= (handle & ((1 << ramht->bits) - 1)); |
| 40 | handle >>= ramht->bits; |
| 41 | } |
| 42 | |
| 43 | hash ^= chid << (ramht->bits - 4); |
| 44 | hash = hash << 3; |
| 45 | return hash; |
| 46 | } |
| 47 | |
| 48 | int |
| 49 | nouveau_ramht_insert(struct nouveau_ramht *ramht, int chid, |
| 50 | u32 handle, u32 context) |
| 51 | { |
| 52 | struct nouveau_bar *bar = nouveau_bar(ramht); |
| 53 | u32 co, ho; |
| 54 | |
| 55 | co = ho = nouveau_ramht_hash(ramht, chid, handle); |
| 56 | do { |
| 57 | if (!nv_ro32(ramht, co + 4)) { |
| 58 | nv_wo32(ramht, co + 0, handle); |
| 59 | nv_wo32(ramht, co + 4, context); |
| 60 | if (bar) |
| 61 | bar->flush(bar); |
| 62 | return co; |
| 63 | } |
| 64 | |
| 65 | co += 8; |
| 66 | if (co >= nv_gpuobj(ramht)->size) |
| 67 | co = 0; |
| 68 | } while (co != ho); |
| 69 | |
| 70 | return -ENOMEM; |
| 71 | } |
| 72 | |
| 73 | void |
| 74 | nouveau_ramht_remove(struct nouveau_ramht *ramht, int cookie) |
| 75 | { |
| 76 | struct nouveau_bar *bar = nouveau_bar(ramht); |
| 77 | nv_wo32(ramht, cookie + 0, 0x00000000); |
| 78 | nv_wo32(ramht, cookie + 4, 0x00000000); |
| 79 | if (bar) |
| 80 | bar->flush(bar); |
| 81 | } |
| 82 | |
| 83 | static struct nouveau_oclass |
| 84 | nouveau_ramht_oclass = { |
| 85 | .handle = 0x0000abcd, |
| 86 | .ofuncs = &(struct nouveau_ofuncs) { |
| 87 | .ctor = NULL, |
| 88 | .dtor = _nouveau_gpuobj_dtor, |
| 89 | .init = _nouveau_gpuobj_init, |
| 90 | .fini = _nouveau_gpuobj_fini, |
| 91 | .rd32 = _nouveau_gpuobj_rd32, |
| 92 | .wr32 = _nouveau_gpuobj_wr32, |
| 93 | }, |
| 94 | }; |
| 95 | |
| 96 | int |
| 97 | nouveau_ramht_new(struct nouveau_object *parent, struct nouveau_object *pargpu, |
| 98 | u32 size, u32 align, struct nouveau_ramht **pramht) |
| 99 | { |
| 100 | struct nouveau_ramht *ramht; |
| 101 | int ret; |
| 102 | |
| 103 | ret = nouveau_gpuobj_create(parent, parent->engine ? |
| 104 | parent->engine : parent, /* <nv50 ramht */ |
| 105 | &nouveau_ramht_oclass, 0, pargpu, size, |
| 106 | align, NVOBJ_FLAG_ZERO_ALLOC, &ramht); |
| 107 | *pramht = ramht; |
| 108 | if (ret) |
| 109 | return ret; |
| 110 | |
| 111 | ramht->bits = order_base_2(nv_gpuobj(ramht)->size >> 3); |
| 112 | return 0; |
| 113 | } |
| 114 | |