1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright © 2011 Intel Corporation 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the "Software"), 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to deal in the Software without restriction, including without limitation 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and/or sell copies of the Software, and to permit persons to whom the 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software is furnished to do so, subject to the following conditions: 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the next 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * paragraph) shall be included in all copies or substantial portions of the 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software. 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IN THE SOFTWARE. 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "intel_resolve_map.h" 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <assert.h> 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stdlib.h> 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/** 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Set that the miptree slice at (level, layer) needs a resolve. 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * If a map element already exists with the given key, then the value is 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * changed to the given value of \c need. 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgintel_resolve_map_set(struct intel_resolve_map *head, 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org uint32_t level, 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org uint32_t layer, 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org enum gen6_hiz_op need) 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct intel_resolve_map **tail = &head->next; 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct intel_resolve_map *prev = head; 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org while (*tail) { 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if ((*tail)->level == level && (*tail)->layer == layer) { 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (*tail)->need = need; 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return; 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org prev = *tail; 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org tail = &(*tail)->next; 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *tail = malloc(sizeof(**tail)); 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (*tail)->prev = prev; 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (*tail)->next = NULL; 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (*tail)->level = level; 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (*tail)->layer = layer; 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (*tail)->need = need; 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/** 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Get an element from the map. 63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \return null if element is not contained in map. 64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct intel_resolve_map* 66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgintel_resolve_map_get(struct intel_resolve_map *head, 67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org uint32_t level, 68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org uint32_t layer) 69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct intel_resolve_map *item = head->next; 71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org while (item) { 73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (item->level == level && item->layer == layer) 74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org break; 75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org else 76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org item = item->next; 77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return item; 80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/** 83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Remove and free an element from the map. 84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgintel_resolve_map_remove(struct intel_resolve_map *elem) 87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (elem->prev) 89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org elem->prev->next = elem->next; 90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (elem->next) 91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org elem->next->prev = elem->prev; 92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org free(elem); 93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/** 96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * \brief Remove and free all elements of the map. 97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid 99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgintel_resolve_map_clear(struct intel_resolve_map *head) 100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct intel_resolve_map *next = head->next; 102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct intel_resolve_map *trash; 103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org while (next) { 105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org trash = next; 106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org next = next->next; 107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org free(trash); 108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org head->next = NULL; 111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 112