Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 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 "drmP.h" |
| 26 | #include "nouveau_drv.h" |
| 27 | #include "nouveau_mm.h" |
| 28 | |
Ben Skeggs | b5e2f07 | 2011-02-14 07:34:55 +1000 | [diff] [blame] | 29 | /* 0 = unsupported |
| 30 | * 1 = non-compressed |
| 31 | * 3 = compressed |
| 32 | */ |
| 33 | static const u8 types[256] = { |
| 34 | 1, 1, 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 0, 0, 0, 0, |
| 35 | 0, 1, 0, 0, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0, 0, |
| 36 | 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, |
| 37 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, |
| 38 | 3, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 39 | 0, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 40 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 41 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, |
| 42 | 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 0, 1, 1, 1, 1, 0, |
| 43 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 44 | 0, 0, 0, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 0, 0, |
| 45 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, |
| 46 | 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, |
| 47 | 3, 3, 0, 0, 0, 0, 0, 0, 3, 0, 0, 3, 0, 3, 0, 3, |
| 48 | 3, 0, 3, 3, 3, 3, 3, 0, 0, 3, 0, 3, 0, 3, 3, 0, |
| 49 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 1, 1, 0 |
| 50 | }; |
| 51 | |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 52 | bool |
| 53 | nvc0_vram_flags_valid(struct drm_device *dev, u32 tile_flags) |
| 54 | { |
Ben Skeggs | b5e2f07 | 2011-02-14 07:34:55 +1000 | [diff] [blame] | 55 | u8 memtype = (tile_flags & NOUVEAU_GEM_TILE_LAYOUT_MASK) >> 8; |
| 56 | return likely((types[memtype] == 1)); |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | int |
| 60 | nvc0_vram_new(struct drm_device *dev, u64 size, u32 align, u32 ncmin, |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 61 | u32 type, struct nouveau_mem **pmem) |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 62 | { |
| 63 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 64 | struct ttm_bo_device *bdev = &dev_priv->ttm.bdev; |
| 65 | struct ttm_mem_type_manager *man = &bdev->man[TTM_PL_VRAM]; |
| 66 | struct nouveau_mm *mm = man->priv; |
| 67 | struct nouveau_mm_node *r; |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 68 | struct nouveau_mem *mem; |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 69 | int ret; |
| 70 | |
| 71 | size >>= 12; |
| 72 | align >>= 12; |
| 73 | ncmin >>= 12; |
| 74 | |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 75 | mem = kzalloc(sizeof(*mem), GFP_KERNEL); |
| 76 | if (!mem) |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 77 | return -ENOMEM; |
| 78 | |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 79 | INIT_LIST_HEAD(&mem->regions); |
| 80 | mem->dev = dev_priv->dev; |
| 81 | mem->memtype = type; |
| 82 | mem->size = size; |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 83 | |
| 84 | mutex_lock(&mm->mutex); |
| 85 | do { |
| 86 | ret = nouveau_mm_get(mm, 1, size, ncmin, align, &r); |
| 87 | if (ret) { |
| 88 | mutex_unlock(&mm->mutex); |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 89 | nv50_vram_del(dev, &mem); |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 90 | return ret; |
| 91 | } |
| 92 | |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 93 | list_add_tail(&r->rl_entry, &mem->regions); |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 94 | size -= r->length; |
| 95 | } while (size); |
| 96 | mutex_unlock(&mm->mutex); |
| 97 | |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 98 | r = list_first_entry(&mem->regions, struct nouveau_mm_node, rl_entry); |
| 99 | mem->offset = (u64)r->offset << 12; |
| 100 | *pmem = mem; |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | int |
| 105 | nvc0_vram_init(struct drm_device *dev) |
| 106 | { |
| 107 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 108 | |
| 109 | dev_priv->vram_size = nv_rd32(dev, 0x10f20c) << 20; |
| 110 | dev_priv->vram_size *= nv_rd32(dev, 0x121c74); |
| 111 | dev_priv->vram_rblock_size = 4096; |
| 112 | return 0; |
| 113 | } |