<?xml version="1.0" ?>

<!--
Copyright © 2022 Imagination Technologies Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->

<!--
These definitions are based on the ones for the firmware streams found
in the fwif header (pvr_rogue_fwif_stream.h).

TODO: Once the kernel driver is merged upstream, check to see if this comment
needs updating.
-->

<!--
This file is structured as follows:
  - defines
  - enums
  - structs
  - streams

Elements in each section are ordered alphabetically.
-->

<!--
TODO: Currently the sizes for fields are in bits. Those should be changed to
bytes. Might want to do this in conjunction with csbgen being changed from
dword to bytes granular.
-->
<!--
TODO: Allow embedding of struct definitions withing stream elements. And for
structs that might be shared between multiple streams, allow for the field
type to be set to a struct.
-->
<csbgen name="ROGUE" prefix="KMD_STREAM">

  <define name="EXTHDR_DATA_MASK" value="0xFFFFFFF"/>

  <!--
    Note: this does not depend on
    \ref pvr_device_features.has_eight_output_registers .
    It's always 8 catering for the largest size.
  -->
  <!--
    TODO: Instead of defining this, see if we can use something like anvil's
    "group" where a field is repeated n times. That would allow us to get the
    total length of the whole group instead of the driver calculating it by
    multiplying this with the size of the usc reg.
  -->
  <!--
    TODO: This should only be defined for `CMD_FRAG`. Allow the definition of
    `define` elements within structs and streams.
  -->
  <define name="USC_CLEAR_REGISTER_COUNT" value="8"/>

  <enum name="EXTHDR_TYPE_COMPUTE">
    <value name="0" value="0"/>
  </enum>

  <enum name="EXTHDR_TYPE_FRAG">
    <value name="0" value="0"/>
  </enum>

  <enum name="EXTHDR_TYPE_GEOM">
    <value name="0" value="0"/>
  </enum>

  <enum name="PIXEL_PHANTOM_STATE">
    <value name="DISABLED" value="0x0"/>
    <value name="ENABLED"  value="0xF"/>
  </enum>

  <struct name="EXTHDR_COMPUTE0" length="1">
    <field name="type" start="29" end="31" type="EXTHDR_TYPE_COMPUTE" default="0"/>
    <field name="continuation" start="28" end="28" type="bool"/>
    <field name="has_brn49927" start="0" end="0" type="bool"/>
  </struct>

  <struct name="EXTHDR_FRAG0" length="1">
    <field name="type" start="29" end="31" type="EXTHDR_TYPE_FRAG" default="0"/>
    <field name="continuation" start="28" end="28" type="bool"/>
    <field name="has_brn49927" start="1" end="1" type="bool"/>
    <field name="has_brn47217" start="0" end="0" type="bool"/>
  </struct>

  <struct name="EXTHDR_GEOM0" length="1">
    <field name="type" start="29" end="31" type="EXTHDR_TYPE_GEOM" default="0"/>
    <field name="continuation" start="28" end="28" type="bool"/>
    <field name="has_brn49927" start="0" end="0" type="bool"/>
  </struct>

  <struct name="HDR" length="2">
    <field name="length" start="0" end="31" type="uint"/>
  </struct>

  <!--
    Note: if there's an attempt to disable all phantoms, they will all be set
    to their default states (i.e. all enabled).
  -->
  <struct name="PIXEL_PHANTOM" length="1">
    <field name="phantom_1" start="4" end="7" type="PIXEL_PHANTOM_STATE"/>
    <field name="phantom_0" start="0" end="3" type="PIXEL_PHANTOM_STATE"/>
  </struct>

  <struct name="VIEW_IDX" length="1">
    <field name="idx" start="0" end="7" type="uint"/>
  </struct>

  <stream name="CMD_COMPUTE" length="18">
    <field name="tpu_border_colour_table" size="64" type="uint"/>
    <!-- Only present if PVR_FEATURE_CDM_USER_MODE_QUEUE supported on the current device -->
    <field name="cdm_cb_queue" size="64" type="uint" feature="PVR_FEATURE_CDM_USER_MODE_QUEUE"/>
    <!-- Only present if PVR_FEATURE_CDM_USER_MODE_QUEUE supported on the current device -->
    <field name="cbm_cb_base" size="64" type="address" shift="0" feature="PVR_FEATURE_CDM_USER_MODE_QUEUE"/>
    <!-- Only present if PVR_FEATURE_CDM_USER_MODE_QUEUE supported on the current device -->
    <field name="cdm_cb" size="64" type="uint" feature="PVR_FEATURE_CDM_USER_MODE_QUEUE"/>
    <!-- Only present if PVR_FEATURE_CDM_USER_MODE_QUEUE supported on the current device -->
    <field name="cdm_ctrl_stream_base" size="64" type="address" shift="0" feature="PVR_FEATURE_CDM_USER_MODE_QUEUE"/>
    <field name="cdm_context_state_base_addr" size="64" type="address" shift="0"/>
    <field name="cdm_resume_pds1" size="32" type="uint"/>
    <!-- Only present if PVR_FEATURE_COMPUTE_MORTON_CAPABLE supported on the current device -->
    <field name="cdm_item" size="32" type="uint" feature="PVR_FEATURE_COMPUTE_MORTON_CAPABLE"/>
    <!-- Only present if PVR_FEATURE_CLUSTER_GROUPING supported on the current device -->
    <field name="compute_cluster" size="32" type="uint" feature="PVR_FEATURE_CLUSTER_GROUPING"/>
    <!-- Only present if PVR_FEATURE_TPU_DM_GLOBAL_REGISTERS supported on the current device -->
    <field name="tpu_tag_cdm_ctrl" size="32" type="uint" feature="PVR_FEATURE_TPU_DM_GLOBAL_REGISTERS"/>
    <!-- Only present if PVR_FEATURE_CDM_USER_MODE_QUEUE supported on the current device -->
    <field name="stream_start_offset" size="32" type="uint" feature="PVR_FEATURE_CDM_USER_MODE_QUEUE"/>
    <!-- Only present if PVR_FEATURE_GPU_MULTICORE_SUPPORT supported on the current device -->
    <field name="execute_count" size="32" type="uint" feature="PVR_FEATURE_GPU_MULTICORE_SUPPORT"/>
  </stream>

  <stream name="CMD_COMPUTE_EXT_BRN49927" length="1">
    <field name="tpu" size="32" type="uint"/>
  </stream>

  <stream name="CMD_FRAG" length="100">
    <field name="isp_scissor_base" size="64" type="address" shift="0"/>
    <field name="isp_dbias_base" size="64" type="address" shift="0"/>
    <field name="isp_oclqry_base" size="64" type="address" shift="0"/>
    <field name="isp_zlsctl" size="64" type="address" shift="0"/>
    <field name="isp_zload_store_base" size="64" type="address" shift="0"/>
    <field name="isp_stencil_load_store_base" size="64" type="address" shift="0"/>
    <!-- Only present if PVR_FEATURE_REQUIRES_FB_CDC_ZLS_SETUP supported on the current device -->
    <field name="fb_cdc_zls" size="64" type="uint" feature="PVR_FEATURE_REQUIRES_FB_CDC_ZLS_SETUP"/>
    <field name="pbe_word" size="1536" type="uint_array"/>
    <field name="tpu_border_colour_table" size="64" type="uint"/>
    <field name="pds_bgnd" size="192" type="uint_array"/>
    <field name="pds_pr_bgnd" size="192" type="uint_array"/>
    <field name="usc_clear_register" size="256" type="uint_array"/>
    <field name="usc_pixel_output_ctrl" size="32" type="uint"/>
    <field name="isp_bgobjdepth" size="32" type="uint"/>
    <field name="isp_bgobjvals" size="32" type="uint"/>
    <field name="isp_aa" size="32" type="uint"/>
    <!-- Only present if PVR_FEATURE_S7_TOP_INFRASTRUCTURE supported on the current device -->
    <field name="isp_xtp_pipe_enable" size="32" type="uint" feature="PVR_FEATURE_S7_TOP_INFRASTRUCTURE"/>
    <field name="isp_ctl" size="32" type="uint"/>
    <field name="event_pixel_pds_info" size="32" type="uint"/>
    <!-- Only present if PVR_FEATURE_CLUSTER_GROUPING supported on the current device -->
    <field name="pixel_phantom" size="32" type="uint" feature="PVR_FEATURE_CLUSTER_GROUPING"/>
    <field name="view_idx" size="32" type="uint"/>
    <field name="event_pixel_pds_data" size="32" type="uint"/>
    <!-- Only present if PVR_FEATURE_GPU_MULTICORE_SUPPORT supported on the current device -->
    <field name="isp_oclqry_stride" size="32" type="uint" feature="PVR_FEATURE_GPU_MULTICORE_SUPPORT"/>
    <!-- Only present if PVR_FEATURE_ZLS_SUBTILE supported on the current device -->
    <field name="isp_zls_pixels" size="32" type="uint" feature="PVR_FEATURE_ZLS_SUBTILE"/>
    <!-- Only present if PVR_FEATURE_ISP_ZLS_D24_S8_PACKING_OGL_MODE supported on the current device -->
    <field name="rgx_cr_blackpearl_fix" size="32" type="uint" feature="PVR_FEATURE_ISP_ZLS_D24_S8_PACKING_OGL_MODE"/>
    <field name="zls_stride" size="32" type="uint"/>
    <field name="sls_stride" size="32" type="uint"/>
    <!-- Only present if PVR_FEATURE_GPU_MULTICORE_SUPPORT supported on the current device -->
    <field name="execute_count" size="32" type="uint" feature="PVR_FEATURE_GPU_MULTICORE_SUPPORT"/>
  </stream>

  <stream name="CMD_FRAG_EXT_BRN47217" length="1">
    <field name="isp_oclqry_stride" size="32" type="uint"/>
  </stream>

  <stream name="CMD_FRAG_EXT_BRN49927" length="1">
    <field name="tpu" size="32" type="uint"/>
  </stream>

  <stream name="CMD_GEOM" length="13">
    <field name="vdm_ctrl_stream_base" size="64" type="address" shift="0"/>
    <field name="tpu_border_colour_table" size="64" type="uint"/>
    <!-- Only present if PVR_FEATURE_VDM_DRAWINDIRECT supported on the current device -->
    <field name="vdm_draw_indirect0" size="64" type="uint" feature="PVR_FEATURE_VDM_DRAWINDIRECT"/>
    <!-- Only present if PVR_FEATURE_VDM_DRAWINDIRECT supported on the current device -->
    <field name="vdm_draw_indirect1" size="32" type="uint" feature="PVR_FEATURE_VDM_DRAWINDIRECT"/>
    <field name="ppp_ctrl" size="32" type="uint"/>
    <field name="te_psg" size="32" type="uint"/>
    <field name="vdm_context_resume_task0_size" size="32" type="uint"/>
    <!-- Only present if PVR_FEATURE_VDM_OBJECT_LEVEL_LLS supported on the current device -->
    <field name="vdm_context_resume_task3_size" size="32" type="uint" feature="PVR_FEATURE_VDM_OBJECT_LEVEL_LLS"/>
    <field name="view_idx" size="32" type="uint"/>
    <!-- Only present if PVR_FEATURE_TESSELLATION supported on the current device -->
    <field name="pds_coeff_free_prog" size="32" type="uint" feature="PVR_FEATURE_TESSELLATION"/>
  </stream>

  <stream name="CMD_GEOM_EXT_BRN49927" length="1">
    <field name="tpu" size="32" type="uint"/>
  </stream>

  <stream name="CMD_TRANSFER" length="43">
    <field name="pds_bgnd0_base" size="64" type="address" shift="0"/>
    <field name="pds_bgnd1_base" size="64" type="address" shift="0"/>
    <field name="pds_bgnd3_sizeinfo" size="64" type="uint"/>
    <field name="isp_mtile_base" size="64" type="address" shift="0"/>
    <field name="pbr_wordx_mrty" size="576" type="uint_array"/>
    <field name="isp_bgobjvals" size="32" type="uint"/>
    <field name="usc_pixel_output_ctrl" size="32" type="uint"/>
    <field name="usc_clear_register0" size="32" type="uint"/>
    <field name="usc_clear_register1" size="32" type="uint"/>
    <field name="usc_clear_register2" size="32" type="uint"/>
    <field name="usc_clear_register3" size="32" type="uint"/>
    <field name="isp_mtile_size" size="32" type="uint"/>
    <field name="isp_render_origin" size="32" type="uint"/>
    <field name="isp_ctl" size="32" type="uint"/>
    <field name="isp_aa" size="32" type="uint"/>
    <field name="event_pixel_pds_info" size="32" type="uint"/>
    <field name="event_pixel_pds_code" size="32" type="uint"/>
    <field name="event_pixel_pds_data" size="32" type="uint"/>
    <field name="isp_render" size="32" type="uint"/>
    <field name="isp_rgn" size="32" type="uint"/>
    <!-- Only present if PVR_FEATURE_S7_TOP_INFRASTRUCTURE supported on the current device -->
    <field name="isp_xtp_pipe_enable" size="32" type="uint" feature="PVR_FEATURE_S7_TOP_INFRASTRUCTURE"/>
    <!-- Only present if PVR_FEATURE_GPU_MULTICORE_SUPPORT supported on the current device -->
    <field name="frag_screen" size="32" type="uint" feature="PVR_FEATURE_GPU_MULTICORE_SUPPORT"/>
  </stream>

  <stream name="STATIC_COMPUTE_CONTEXT_STATE" length="14">
    <field name="cdm_reg_context_pds0" size="64" type="uint"/>
    <field name="cdm_reg_context_pds1" size="64" type="uint"/>
    <field name="cdm_reg_terminate_pds0" size="64" type="uint"/>
    <field name="cdm_reg_terminate_pds1" size="64" type="uint"/>
    <field name="cdm_reg_resume_pds0" size="64" type="uint"/>
    <field name="cdm_reg_context_pds0_b" size="64" type="uint"/>
    <field name="cdm_reg_resume_pds0_b" size="64" type="uint"/>
  </stream>

  <stream name="STATIC_RENDER_CONTEXT_STATE" length="46">
    <field name="geom_reg_vdm_context_state_base_addr" size="64" type="address" shift="0"/>
    <field name="geom_reg_vdm_context_state_resume_addr" size="64" type="address" shift="0"/>
    <field name="geom_reg_ta_context_state_base_addr" size="64" type="address" shift="0"/>
    <field name="geom_state0_geom_reg_vdm_context_store_task0" size="64" type="uint"/>
    <field name="geom_state0_geom_reg_vdm_context_store_task1" size="64" type="uint"/>
    <field name="geom_state0_geom_reg_vdm_context_store_task2" size="64" type="uint"/>
    <field name="geom_state0_geom_reg_vdm_context_store_task3" size="64" type="uint"/>
    <field name="geom_state0_geom_reg_vdm_context_store_task4" size="64" type="uint"/>
    <field name="geom_state0_geom_reg_vdm_context_resume_task0" size="64" type="uint"/>
    <field name="geom_state0_geom_reg_vdm_context_resume_task1" size="64" type="uint"/>
    <field name="geom_state0_geom_reg_vdm_context_resume_task2" size="64" type="uint"/>
    <field name="geom_state0_geom_reg_vdm_context_resume_task3" size="64" type="uint"/>
    <field name="geom_state0_geom_reg_vdm_context_resume_task4" size="64" type="uint"/>
    <field name="geom_state1_geom_reg_vdm_context_store_task0" size="64" type="uint"/>
    <field name="geom_state1_geom_reg_vdm_context_store_task1" size="64" type="uint"/>
    <field name="geom_state1_geom_reg_vdm_context_store_task2" size="64" type="uint"/>
    <field name="geom_state1_geom_reg_vdm_context_store_task3" size="64" type="uint"/>
    <field name="geom_state1_geom_reg_vdm_context_store_task4" size="64" type="uint"/>
    <field name="geom_state1_geom_reg_vdm_context_resume_task0" size="64" type="uint"/>
    <field name="geom_state1_geom_reg_vdm_context_resume_task1" size="64" type="uint"/>
    <field name="geom_state1_geom_reg_vdm_context_resume_task2" size="64" type="uint"/>
    <field name="geom_state1_geom_reg_vdm_context_resume_task3" size="64" type="uint"/>
    <field name="geom_state1_geom_reg_vdm_context_resume_task4" size="64" type="uint"/>
  </stream>

</csbgen>
