Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Subject: [PATCH 2/5] drm/xe: Add MI_MATH and ALU instruction definitions
Date: Mon,  3 Mar 2025 18:35:19 +0100	[thread overview]
Message-ID: <20250303173522.1822-3-michal.wajdeczko@intel.com> (raw)
In-Reply-To: <20250303173522.1822-1-michal.wajdeczko@intel.com>

The command streamer implements an Arithmetic Logic Unit (ALU)
which supports basic arithmetic and logical operations on two
64-bit operands. Access to this ALU is thru the MI_MATH command
and sixteen General Purpose Register (GPR) 64-bit registers,
which are used as temporary storage.

Bspec: 45737, 60236 # MI
Bspec: 45525, 60132 # ALU
Bspec: 45533, 60309 # GPR
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
---
 .../gpu/drm/xe/instructions/xe_alu_commands.h | 72 +++++++++++++++++++
 .../gpu/drm/xe/instructions/xe_mi_commands.h  |  1 +
 drivers/gpu/drm/xe/regs/xe_engine_regs.h      |  4 ++
 3 files changed, 77 insertions(+)
 create mode 100644 drivers/gpu/drm/xe/instructions/xe_alu_commands.h

diff --git a/drivers/gpu/drm/xe/instructions/xe_alu_commands.h b/drivers/gpu/drm/xe/instructions/xe_alu_commands.h
new file mode 100644
index 000000000000..c4321949f534
--- /dev/null
+++ b/drivers/gpu/drm/xe/instructions/xe_alu_commands.h
@@ -0,0 +1,72 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2025 Intel Corporation
+ */
+
+#ifndef _XE_ALU_COMMANDS_H_
+#define _XE_ALU_COMMANDS_H_
+
+#include "instructions/xe_instr_defs.h"
+
+/* Instruction Opcodes */
+#define CS_ALU_OPCODE_NOOP			0x000
+#define CS_ALU_OPCODE_LOAD			0x080
+#define CS_ALU_OPCODE_LOADINV			0x480
+#define CS_ALU_OPCODE_LOAD0			0x081
+#define CS_ALU_OPCODE_LOAD1			0x481
+#define CS_ALU_OPCODE_ADD			0x100
+#define CS_ALU_OPCODE_SUB			0x101
+#define CS_ALU_OPCODE_AND			0x102
+#define CS_ALU_OPCODE_OR			0x103
+#define CS_ALU_OPCODE_XOR			0x104
+#define CS_ALU_OPCODE_STORE			0x180
+#define CS_ALU_OPCODE_STOREINV			0x580
+
+/* Instruction Operands */
+#define CS_ALU_OPERAND_REG(n)			REG_FIELD_PREP(GENMASK(3, 0), (n))
+#define CS_ALU_OPERAND_REG0			0x0
+#define CS_ALU_OPERAND_REG1			0x1
+#define CS_ALU_OPERAND_REG2			0x2
+#define CS_ALU_OPERAND_REG3			0x3
+#define CS_ALU_OPERAND_REG4			0x4
+#define CS_ALU_OPERAND_REG5			0x5
+#define CS_ALU_OPERAND_REG6			0x6
+#define CS_ALU_OPERAND_REG7			0x7
+#define CS_ALU_OPERAND_REG8			0x8
+#define CS_ALU_OPERAND_REG9			0x9
+#define CS_ALU_OPERAND_REG10			0xa
+#define CS_ALU_OPERAND_REG11			0xb
+#define CS_ALU_OPERAND_REG12			0xc
+#define CS_ALU_OPERAND_REG13			0xd
+#define CS_ALU_OPERAND_REG14			0xe
+#define CS_ALU_OPERAND_REG15			0xf
+#define CS_ALU_OPERAND_SRCA			0x20
+#define CS_ALU_OPERAND_SRCB			0x21
+#define CS_ALU_OPERAND_ACCU			0x31
+#define CS_ALU_OPERAND_ZF			0x32
+#define CS_ALU_OPERAND_CF			0x33
+#define CS_ALU_OPERAND_NA			0 /* N/A operand */
+
+/* Command Streamer ALU Instructions */
+#define CS_ALU_INSTR(opcode, op1, op2)		(REG_FIELD_PREP(GENMASK(31, 20), (opcode)) | \
+						 REG_FIELD_PREP(GENMASK(19, 10), (op1)) | \
+						 REG_FIELD_PREP(GENMASK(9, 0), (op2)))
+
+#define __CS_ALU_INSTR(opcode, op1, op2)	CS_ALU_INSTR(CS_ALU_OPCODE_##opcode, \
+							     CS_ALU_OPERAND_##op1, \
+							     CS_ALU_OPERAND_##op2)
+
+#define CS_ALU_INSTR_NOOP			__CS_ALU_INSTR(NOOP, NA, NA)
+#define CS_ALU_INSTR_LOAD(op1, op2)		__CS_ALU_INSTR(LOAD, op1, op2)
+#define CS_ALU_INSTR_LOADINV(op1, op2)		__CS_ALU_INSTR(LOADINV, op1, op2)
+#define CS_ALU_INSTR_LOAD0(op1)			__CS_ALU_INSTR(LOAD0, op1, NA)
+#define CS_ALU_INSTR_LOAD1(op1)			__CS_ALU_INSTR(LOAD1, op1, NA)
+#define CS_ALU_INSTR_ADD			__CS_ALU_INSTR(ADD, NA, NA)
+#define CS_ALU_INSTR_SUB			__CS_ALU_INSTR(SUB, NA, NA)
+#define CS_ALU_INSTR_AND			__CS_ALU_INSTR(AND, NA, NA)
+#define CS_ALU_INSTR_OR				__CS_ALU_INSTR(OR, NA, NA)
+#define CS_ALU_INSTR_XOR			__CS_ALU_INSTR(XOR, NA, NA)
+#define CS_ALU_INSTR_STORE(op1, op2)		__CS_ALU_INSTR(STORE, op1, op2)
+#define CS_ALU_INSTR_STOREINV(op1, op2)		__CS_ALU_INSTR(STOREINV, op1, op2)
+
+#endif
diff --git a/drivers/gpu/drm/xe/instructions/xe_mi_commands.h b/drivers/gpu/drm/xe/instructions/xe_mi_commands.h
index 526bad9d4bac..eba582058d55 100644
--- a/drivers/gpu/drm/xe/instructions/xe_mi_commands.h
+++ b/drivers/gpu/drm/xe/instructions/xe_mi_commands.h
@@ -32,6 +32,7 @@
 #define MI_BATCH_BUFFER_END		__MI_INSTR(0xA)
 #define MI_TOPOLOGY_FILTER		__MI_INSTR(0xD)
 #define MI_FORCE_WAKEUP			__MI_INSTR(0x1D)
+#define MI_MATH(n)			(__MI_INSTR(0x1A) | XE_INSTR_NUM_DW((n) + 1))
 
 #define MI_STORE_DATA_IMM		__MI_INSTR(0x20)
 #define   MI_SDI_GGTT			REG_BIT(22)
diff --git a/drivers/gpu/drm/xe/regs/xe_engine_regs.h b/drivers/gpu/drm/xe/regs/xe_engine_regs.h
index 4f372dc2cb89..659cf85fa3d6 100644
--- a/drivers/gpu/drm/xe/regs/xe_engine_regs.h
+++ b/drivers/gpu/drm/xe/regs/xe_engine_regs.h
@@ -184,6 +184,10 @@
 #define   PREEMPT_GPGPU_LEVEL_MASK		PREEMPT_GPGPU_LEVEL(1, 1)
 #define   PREEMPT_3D_OBJECT_LEVEL		REG_BIT(0)
 
+#define CS_GPR_DATA(base, n)			XE_REG((base) + 0x600 + (n) * 4)
+#define CS_GPR_REG(base, n)			CS_GPR_DATA((base), (n) * 2)
+#define CS_GPR_REG_UDW(base, n)			CS_GPR_DATA((base), (n) * 2 + 1)
+
 #define VDBOX_CGCTL3F08(base)			XE_REG((base) + 0x3f08)
 #define   CG3DDISHRS_CLKGATE_DIS		REG_BIT(5)
 
-- 
2.47.1


  parent reply	other threads:[~2025-03-03 17:35 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-03 17:35 [PATCH 0/5] Use MI_MATH to apply RMW WA in LRC Michal Wajdeczko
2025-03-03 17:35 ` [PATCH 1/5] drm/xe: Add MI_LOAD_REGISTER_REG command definition Michal Wajdeczko
2025-03-03 21:18   ` Matt Roper
2025-03-03 17:35 ` Michal Wajdeczko [this message]
2025-03-03 21:50   ` [PATCH 2/5] drm/xe: Add MI_MATH and ALU instruction definitions Matt Roper
2025-03-04 16:23   ` [PATCH v2 " Michal Wajdeczko
2025-03-03 17:35 ` [PATCH 3/5] drm/xe: Avoid reading RMW registers in emit_wa_job Michal Wajdeczko
2025-03-03 18:06   ` Lucas De Marchi
2025-03-03 18:47     ` Michal Wajdeczko
2025-03-04 16:50       ` Lucas De Marchi
2025-03-03 22:06   ` Matt Roper
2025-03-03 17:35 ` [PATCH 4/5] drm/xe/vf: Stop applying save-restore MMIOs if VF Michal Wajdeczko
2025-03-03 18:09   ` Lucas De Marchi
2025-03-03 22:16     ` Matt Roper
2025-03-03 22:16   ` Matt Roper
2025-03-03 17:35 ` [PATCH 5/5] drm/xe/vf: Unblock xe_rtp_process_to_sr for VFs Michal Wajdeczko
2025-03-03 22:17   ` Matt Roper
2025-03-11 10:52   ` [PATCH v2 " Michal Wajdeczko
2025-03-03 17:44 ` ✓ CI.Patch_applied: success for Use MI_MATH to apply RMW WA in LRC Patchwork
2025-03-03 17:44 ` ✗ CI.checkpatch: warning " Patchwork
2025-03-03 17:46 ` ✓ CI.KUnit: success " Patchwork
2025-03-03 18:02 ` ✓ CI.Build: " Patchwork
2025-03-03 18:05 ` ✓ CI.Hooks: " Patchwork
2025-03-03 18:06 ` ✓ CI.checksparse: " Patchwork
2025-03-03 18:38 ` ✓ Xe.CI.BAT: " Patchwork
2025-03-03 20:12 ` ✗ Xe.CI.Full: failure " Patchwork
2025-03-04 17:27 ` ✓ CI.Patch_applied: success for Use MI_MATH to apply RMW WA in LRC (rev2) Patchwork
2025-03-04 17:27 ` ✗ CI.checkpatch: warning " Patchwork
2025-03-04 17:28 ` ✓ CI.KUnit: success " Patchwork
2025-03-04 17:45 ` ✓ CI.Build: " Patchwork
2025-03-04 17:47 ` ✓ CI.Hooks: " Patchwork
2025-03-04 17:48 ` ✓ CI.checksparse: " Patchwork
2025-03-05  5:43 ` ✗ Xe.CI.BAT: failure " Patchwork
2025-03-07 16:34   ` Michal Wajdeczko
2025-03-07 18:12 ` ✓ CI.Patch_applied: success for Use MI_MATH to apply RMW WA in LRC (rev3) Patchwork
2025-03-07 18:13 ` ✗ CI.checkpatch: warning " Patchwork
2025-03-07 18:14 ` ✓ CI.KUnit: success " Patchwork
2025-03-07 18:36 ` ✓ CI.Build: " Patchwork
2025-03-07 18:39 ` ✓ CI.Hooks: " Patchwork
2025-03-07 18:41 ` ✓ CI.checksparse: " Patchwork
2025-03-07 19:03 ` ✓ Xe.CI.BAT: " Patchwork
2025-03-08 20:46 ` ✗ Xe.CI.Full: failure " Patchwork
2025-03-10 16:31   ` Michal Wajdeczko
2025-03-11 12:55 ` ✓ CI.Patch_applied: success for Use MI_MATH to apply RMW WA in LRC (rev4) Patchwork
2025-03-11 12:55 ` ✗ CI.checkpatch: warning " Patchwork
2025-03-11 12:56 ` ✓ CI.KUnit: success " Patchwork
2025-03-11 13:13 ` ✓ CI.Build: " Patchwork
2025-03-11 13:15 ` ✓ CI.Hooks: " Patchwork
2025-03-11 13:17 ` ✓ CI.checksparse: " Patchwork
2025-03-11 13:37 ` ✓ Xe.CI.BAT: " Patchwork
2025-03-12  5:41 ` ✗ Xe.CI.Full: failure " Patchwork
2025-03-12 10:34   ` Michal Wajdeczko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250303173522.1822-3-michal.wajdeczko@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox