Home | History | Annotate | Download | only in etnaviv
      1 /*
      2  * Copyright (c) 2012-2015 Etnaviv Project
      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, sub license,
      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 (including the
     12  * next paragraph) shall be included in all copies or substantial portions
     13  * of the Software.
     14  *
     15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     21  * DEALINGS IN THE SOFTWARE.
     22  *
     23  * Authors:
     24  *    Wladimir J. van der Laan <laanwj (at) gmail.com>
     25  */
     26 
     27 #ifndef H_ETNA_EMIT
     28 #define H_ETNA_EMIT
     29 
     30 #include "etnaviv_screen.h"
     31 #include "etnaviv_util.h"
     32 #include "hw/cmdstream.xml.h"
     33 
     34 struct etna_context;
     35 struct compiled_rs_state;
     36 
     37 static inline void
     38 etna_emit_load_state(struct etna_cmd_stream *stream, const uint16_t offset,
     39                      const uint16_t count, const int fixp)
     40 {
     41    uint32_t v;
     42 
     43    v = VIV_FE_LOAD_STATE_HEADER_OP_LOAD_STATE |
     44        COND(fixp, VIV_FE_LOAD_STATE_HEADER_FIXP) |
     45        VIV_FE_LOAD_STATE_HEADER_OFFSET(offset) |
     46        (VIV_FE_LOAD_STATE_HEADER_COUNT(count) &
     47         VIV_FE_LOAD_STATE_HEADER_COUNT__MASK);
     48 
     49    etna_cmd_stream_emit(stream, v);
     50 }
     51 
     52 static inline void
     53 etna_set_state(struct etna_cmd_stream *stream, uint32_t address, uint32_t value)
     54 {
     55    etna_cmd_stream_reserve(stream, 2);
     56    etna_emit_load_state(stream, address >> 2, 1, 0);
     57    etna_cmd_stream_emit(stream, value);
     58 }
     59 
     60 static inline void
     61 etna_set_state_reloc(struct etna_cmd_stream *stream, uint32_t address,
     62                      struct etna_reloc *reloc)
     63 {
     64    etna_cmd_stream_reserve(stream, 2);
     65    etna_emit_load_state(stream, address >> 2, 1, 0);
     66    etna_cmd_stream_reloc(stream, reloc);
     67 }
     68 
     69 static inline void
     70 etna_set_state_multi(struct etna_cmd_stream *stream, uint32_t base,
     71                      uint32_t num, const uint32_t *values)
     72 {
     73    if (num == 0)
     74       return;
     75 
     76    etna_cmd_stream_reserve(stream, 1 + num + 1); /* 1 extra for potential alignment */
     77    etna_emit_load_state(stream, base >> 2, num, 0);
     78 
     79    for (uint32_t i = 0; i < num; i++)
     80       etna_cmd_stream_emit(stream, values[i]);
     81 
     82    /* add potential padding */
     83    if ((num % 2) == 0)
     84       etna_cmd_stream_emit(stream, 0);
     85 }
     86 
     87 void
     88 etna_stall(struct etna_cmd_stream *stream, uint32_t from, uint32_t to);
     89 
     90 void
     91 etna_submit_rs_state(struct etna_context *ctx, const struct compiled_rs_state *cs);
     92 
     93 static inline void
     94 etna_draw_primitives(struct etna_cmd_stream *stream, uint32_t primitive_type,
     95                      uint32_t start, uint32_t count)
     96 {
     97    etna_cmd_stream_reserve(stream, 4);
     98 
     99    etna_cmd_stream_emit(stream, VIV_FE_DRAW_PRIMITIVES_HEADER_OP_DRAW_PRIMITIVES);
    100    etna_cmd_stream_emit(stream, primitive_type);
    101    etna_cmd_stream_emit(stream, start);
    102    etna_cmd_stream_emit(stream, count);
    103 }
    104 
    105 static inline void
    106 etna_draw_indexed_primitives(struct etna_cmd_stream *stream,
    107                              uint32_t primitive_type, uint32_t start,
    108                              uint32_t count, uint32_t offset)
    109 {
    110    etna_cmd_stream_reserve(stream, 5 + 1);
    111 
    112    etna_cmd_stream_emit(stream, VIV_FE_DRAW_INDEXED_PRIMITIVES_HEADER_OP_DRAW_INDEXED_PRIMITIVES);
    113    etna_cmd_stream_emit(stream, primitive_type);
    114    etna_cmd_stream_emit(stream, start);
    115    etna_cmd_stream_emit(stream, count);
    116    etna_cmd_stream_emit(stream, offset);
    117    etna_cmd_stream_emit(stream, 0);
    118 }
    119 
    120 void
    121 etna_emit_state(struct etna_context *ctx);
    122 
    123 #endif
    124