* miscellaneous debugging code.
*/
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "dev/gen_debug.h"
+#include "git_sha1.h"
#include "util/macros.h"
#include "util/debug.h"
#include "c11/threads.h"
call_once(&process_intel_debug_variable_flag,
brw_process_intel_debug_variable_once);
}
+
+static uint64_t debug_identifier[4] = {
+ 0xffeeddccbbaa9988,
+ 0x7766554433221100,
+ 0xffeeddccbbaa9988,
+ 0x7766554433221100,
+};
+
+void *
+intel_debug_identifier(void)
+{
+ return debug_identifier;
+}
+
+uint32_t
+intel_debug_identifier_size(void)
+{
+ return sizeof(debug_identifier);
+}
+
+uint32_t
+intel_debug_write_identifiers(void *_output,
+ uint32_t output_size,
+ const char *driver_name)
+{
+ void *output = _output, *output_end = _output + output_size;
+
+ assert(output_size > intel_debug_identifier_size());
+
+ memcpy(output, intel_debug_identifier(), intel_debug_identifier_size());
+ output += intel_debug_identifier_size();
+
+ for (uint32_t id = GEN_DEBUG_BLOCK_TYPE_DRIVER; id < GEN_DEBUG_BLOCK_TYPE_MAX; id++) {
+ switch (id) {
+ case GEN_DEBUG_BLOCK_TYPE_DRIVER: {
+ struct gen_debug_block_driver driver_desc = {
+ .base = {
+ .type = id,
+ },
+ };
+ int len = snprintf(output + sizeof(driver_desc),
+ output_end - (output + sizeof(driver_desc)),
+ "%s " PACKAGE_VERSION " build " MESA_GIT_SHA1,
+ driver_name);
+ driver_desc.base.length = sizeof(driver_desc) + len + 1;
+ memcpy(output, &driver_desc, sizeof(driver_desc));
+ output += driver_desc.base.length;
+ break;
+ }
+
+ default:
+ unreachable("Missing identifier write");
+ }
+
+ assert(output < output_end);
+ }
+
+ struct gen_debug_block_base end = {
+ .type = GEN_DEBUG_BLOCK_TYPE_END,
+ .length = sizeof(end),
+ };
+ memcpy(output, &end, sizeof(end));
+ output += sizeof(end);
+
+ assert(output < output_end);
+
+ /* Return the how many bytes where written, so that the rest of the buffer
+ * can be used for other things.
+ */
+ return output - _output;
+}
+
+void *
+intel_debug_get_identifier_block(void *_buffer,
+ uint32_t buffer_size,
+ enum gen_debug_block_type type)
+{
+ void *buffer = _buffer + intel_debug_identifier_size(),
+ *end_buffer = _buffer + buffer_size;
+
+ while (buffer < end_buffer) {
+ struct gen_debug_block_base *item = buffer;
+
+ if (item->type == type)
+ return item;
+ if (item->type == GEN_DEBUG_BLOCK_TYPE_END)
+ return NULL;
+
+ buffer += item->length;
+ }
+
+ return NULL;
+}
extern void brw_process_intel_debug_variable(void);
+/* Below is a list of structure located in the identifier buffer. The driver
+ * can fill those in for debug purposes.
+ */
+
+enum gen_debug_block_type {
+ /* End of the debug blocks */
+ GEN_DEBUG_BLOCK_TYPE_END = 1,
+
+ /* Driver identifier (struct gen_debug_block_driver) */
+ GEN_DEBUG_BLOCK_TYPE_DRIVER,
+
+ /* Internal, never to be written out */
+ GEN_DEBUG_BLOCK_TYPE_MAX,
+};
+
+struct gen_debug_block_base {
+ uint32_t type; /* enum gen_debug_block_type */
+ uint32_t length; /* inclusive of this structure size */
+};
+
+struct gen_debug_block_driver {
+ struct gen_debug_block_base base;
+ uint8_t description[];
+};
+
+extern void *intel_debug_identifier(void);
+extern uint32_t intel_debug_identifier_size(void);
+
+extern uint32_t intel_debug_write_identifiers(void *output,
+ uint32_t output_size,
+ const char *driver_name);
+
+extern void *intel_debug_get_identifier_block(void *buffer,
+ uint32_t buffer_size,
+ enum gen_debug_block_type type);
+
#ifdef __cplusplus
}
#endif