drivers/accel/ivpu/ivpu_fw_log.c

Source file repositories/reference/linux-study-clean/drivers/accel/ivpu/ivpu_fw_log.c

File Facts

System
Linux kernel
Corpus path
drivers/accel/ivpu/ivpu_fw_log.c
Extension
.c
Size
5083 bytes
Lines
181
Domain
Driver Families
Bucket
drivers/accel
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (*buffer == '\n' || *buffer == 0) {
			line[index] = 0;
			if (index != 0)
				drm_printf(p, "%s\n", line);
			index = 0;
			buffer++;
			continue;
		}
		if (index == IVPU_FW_LOG_LINE_LENGTH - 1) {
			line[index] = 0;
			index = 0;
			drm_printf(p, "%s\n", line);
		}
		if (*buffer != '\r' && (isprint(*buffer) || iscntrl(*buffer)))
			line[index++] = *buffer;
		buffer++;
	}
	line[index] = 0;
	if (index != 0)
		drm_printf(p, "%s", line);
}

static void fw_log_print_buffer(struct vpu_tracing_buffer_header *log, const char *prefix,
				bool only_new_msgs, struct drm_printer *p)
{
	char *log_data = (void *)log + log->header_size;
	u32 data_size = log->size - log->header_size;
	u32 log_start = only_new_msgs ? READ_ONCE(log->read_index) : 0;
	u32 log_end = READ_ONCE(log->write_index);

	if (log_start >= data_size)
		log_start = 0;
	if (log_end > data_size)
		log_end = data_size;

	if (log->wrap_count == log->read_wrap_count) {
		if (log_end <= log_start) {
			drm_printf(p, "==== %s \"%s\" log empty ====\n", prefix, log->name);
			return;
		}
	} else if (log->wrap_count == log->read_wrap_count + 1) {
		if (log_end > log_start)
			log_start = log_end;
	} else {
		log_start = log_end;
	}

	drm_printf(p, "==== %s \"%s\" log start ====\n", prefix, log->name);
	if (log_end > log_start) {
		fw_log_print_lines(log_data + log_start, log_end - log_start, p);
	} else {
		fw_log_print_lines(log_data + log_start, data_size - log_start, p);
		fw_log_print_lines(log_data, log_end, p);
	}
	drm_printf(p, "\n\x1b[0m"); /* add new line and clear formatting */
	drm_printf(p, "==== %s \"%s\" log end   ====\n", prefix, log->name);
}

static void
fw_log_print_all_in_bo(struct ivpu_device *vdev, const char *name,
		       struct ivpu_bo *bo, bool only_new_msgs, struct drm_printer *p)
{
	struct vpu_tracing_buffer_header *log;
	u32 next = 0;

	while (fw_log_from_bo(vdev, bo, &next, &log) == 0)
		fw_log_print_buffer(log, name, only_new_msgs, p);
}

void ivpu_fw_log_print(struct ivpu_device *vdev, bool only_new_msgs, struct drm_printer *p)
{
	fw_log_print_all_in_bo(vdev, "NPU critical", vdev->fw->mem_log_crit, only_new_msgs, p);
	fw_log_print_all_in_bo(vdev, "NPU verbose", vdev->fw->mem_log_verb, only_new_msgs, p);
}

void ivpu_fw_log_mark_read(struct ivpu_device *vdev)
{
	struct vpu_tracing_buffer_header *log;
	u32 next;

	next = 0;
	while (fw_log_from_bo(vdev, vdev->fw->mem_log_crit, &next, &log) == 0) {
		log->read_index = READ_ONCE(log->write_index);
		log->read_wrap_count = READ_ONCE(log->wrap_count);
	}

	next = 0;
	while (fw_log_from_bo(vdev, vdev->fw->mem_log_verb, &next, &log) == 0) {
		log->read_index = READ_ONCE(log->write_index);
		log->read_wrap_count = READ_ONCE(log->wrap_count);

Annotation

Implementation Notes