History

habanalabs/goya: move dma direction enum to uapi file

The values in this enum are not used by h/w but are a contract between userspace and the kernel driver so they must be defined in the uapi file.

Oded Gabbay committed 4 years ago

Commit 5125aa31 parent 7659c303 files · +41 −26Browse files

Unified · Split

3 files
  1. drivers/misc/habanalabs/goya/goya.c +14 −14
  2. drivers/misc/habanalabs/include/goya/goya_packets.h +0 −12
  3. include/uapi/misc/habanalabs.h +27 −0
drivers/misc/habanalabs/goya/goya.c+14−14
@@ -3403,7 +3403,7 @@ static int goya_validate_dma_pkt_host(struct hl_device *hdev, · 3402 unmodified lines
34033403 {
34043404 u64 device_memory_addr, addr;
34053405 enum dma_data_direction dir;
3406− enum goya_dma_direction user_dir;
3406+ enum hl_goya_dma_direction user_dir;
34073407 bool sram_addr = true;
34083408 bool skip_host_mem_pin = false;
34093409 bool user_memset;
@@ -3419,7 +3419,7 @@ static int goya_validate_dma_pkt_host(struct hl_device *hdev, · 9 unmodified lines
34193419 GOYA_PKT_LIN_DMA_CTL_MEMSET_SHIFT;
34203420
34213421 switch (user_dir) {
3422− case DMA_HOST_TO_DRAM:
3422+ case HL_DMA_HOST_TO_DRAM:
34233423 dev_dbg(hdev->dev, "DMA direction is HOST --> DRAM\n");
34243424 dir = DMA_TO_DEVICE;
34253425 sram_addr = false;
@@ -3429,7 +3429,7 @@ static int goya_validate_dma_pkt_host(struct hl_device *hdev, · 3 unmodified lines
34293429 skip_host_mem_pin = true;
34303430 break;
34313431
3432− case DMA_DRAM_TO_HOST:
3432+ case HL_DMA_DRAM_TO_HOST:
34333433 dev_dbg(hdev->dev, "DMA direction is DRAM --> HOST\n");
34343434 dir = DMA_FROM_DEVICE;
34353435 sram_addr = false;
@@ -3437,7 +3437,7 @@ static int goya_validate_dma_pkt_host(struct hl_device *hdev, · 1 unmodified line
34373437 device_memory_addr = le64_to_cpu(user_dma_pkt->src_addr);
34383438 break;
34393439
3440− case DMA_HOST_TO_SRAM:
3440+ case HL_DMA_HOST_TO_SRAM:
34413441 dev_dbg(hdev->dev, "DMA direction is HOST --> SRAM\n");
34423442 dir = DMA_TO_DEVICE;
34433443 addr = le64_to_cpu(user_dma_pkt->src_addr);
@@ -3446,14 +3446,14 @@ static int goya_validate_dma_pkt_host(struct hl_device *hdev, · 2 unmodified lines
34463446 skip_host_mem_pin = true;
34473447 break;
34483448
3449− case DMA_SRAM_TO_HOST:
3449+ case HL_DMA_SRAM_TO_HOST:
34503450 dev_dbg(hdev->dev, "DMA direction is SRAM --> HOST\n");
34513451 dir = DMA_FROM_DEVICE;
34523452 addr = le64_to_cpu(user_dma_pkt->dst_addr);
34533453 device_memory_addr = le64_to_cpu(user_dma_pkt->src_addr);
34543454 break;
34553455 default:
3456− dev_err(hdev->dev, "DMA direction is undefined\n");
3456+ dev_err(hdev->dev, "DMA direction %d is unsupported/undefined\n", user_dir);
34573457 return -EFAULT;
34583458 }
34593459
@@ -3505,14 +3505,14 @@ static int goya_validate_dma_pkt_no_host(struct hl_device *hdev, · 45 unmodified lines
35053505 struct packet_lin_dma *user_dma_pkt)
35063506 {
35073507 u64 sram_memory_addr, dram_memory_addr;
3508− enum goya_dma_direction user_dir;
3508+ enum hl_goya_dma_direction user_dir;
35093509 u32 ctl;
35103510
35113511 ctl = le32_to_cpu(user_dma_pkt->ctl);
35123512 user_dir = (ctl & GOYA_PKT_LIN_DMA_CTL_DMA_DIR_MASK) >>
35133513 GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT;
35143514
3515− if (user_dir == DMA_DRAM_TO_SRAM) {
3515+ if (user_dir == HL_DMA_DRAM_TO_SRAM) {
35163516 dev_dbg(hdev->dev, "DMA direction is DRAM --> SRAM\n");
35173517 dram_memory_addr = le64_to_cpu(user_dma_pkt->src_addr);
35183518 sram_memory_addr = le64_to_cpu(user_dma_pkt->dst_addr);
@@ -3549,7 +3549,7 @@ static int goya_validate_dma_pkt_no_mmu(struct hl_device *hdev, · 30 unmodified lines
35493549 struct hl_cs_parser *parser,
35503550 struct packet_lin_dma *user_dma_pkt)
35513551 {
3552− enum goya_dma_direction user_dir;
3552+ enum hl_goya_dma_direction user_dir;
35533553 u32 ctl;
35543554 int rc;
35553555
@@ -3574,7 +3574,7 @@ static int goya_validate_dma_pkt_no_mmu(struct hl_device *hdev, · 18 unmodified lines
35743574 return -EINVAL;
35753575 }
35763576
3577− if ((user_dir == DMA_DRAM_TO_SRAM) || (user_dir == DMA_SRAM_TO_DRAM))
3577+ if ((user_dir == HL_DMA_DRAM_TO_SRAM) || (user_dir == HL_DMA_SRAM_TO_DRAM))
35783578 rc = goya_validate_dma_pkt_no_host(hdev, parser, user_dma_pkt);
35793579 else
35803580 rc = goya_validate_dma_pkt_host(hdev, parser, user_dma_pkt);
@@ -3781,7 +3781,7 @@ static int goya_patch_dma_packet(struct hl_device *hdev, · 200 unmodified lines
37813781 u32 count, dma_desc_cnt;
37823782 u64 len, len_next;
37833783 dma_addr_t dma_addr, dma_addr_next;
3784− enum goya_dma_direction user_dir;
3784+ enum hl_goya_dma_direction user_dir;
37853785 u64 device_memory_addr, addr;
37863786 enum dma_data_direction dir;
37873787 struct sg_table *sgt;
@@ -3797,14 +3797,14 @@ static int goya_patch_dma_packet(struct hl_device *hdev, · 9 unmodified lines
37973797 user_memset = (ctl & GOYA_PKT_LIN_DMA_CTL_MEMSET_MASK) >>
37983798 GOYA_PKT_LIN_DMA_CTL_MEMSET_SHIFT;
37993799
3800− if ((user_dir == DMA_DRAM_TO_SRAM) || (user_dir == DMA_SRAM_TO_DRAM) ||
3800+ if ((user_dir == HL_DMA_DRAM_TO_SRAM) || (user_dir == HL_DMA_SRAM_TO_DRAM) ||
38013801 (user_dma_pkt->tsize == 0)) {
38023802 memcpy(new_dma_pkt, user_dma_pkt, sizeof(*new_dma_pkt));
38033803 *new_dma_pkt_size = sizeof(*new_dma_pkt);
38043804 return 0;
38053805 }
38063806
3807− if ((user_dir == DMA_HOST_TO_DRAM) || (user_dir == DMA_HOST_TO_SRAM)) {
3807+ if ((user_dir == HL_DMA_HOST_TO_DRAM) || (user_dir == HL_DMA_HOST_TO_SRAM)) {
38083808 addr = le64_to_cpu(user_dma_pkt->src_addr);
38093809 device_memory_addr = le64_to_cpu(user_dma_pkt->dst_addr);
38103810 dir = DMA_TO_DEVICE;
@@ -4804,7 +4804,7 @@ static int goya_memset_device_memory(struct hl_device *hdev, u64 addr, u64 size, · 993 unmodified lines
48044804 (1 << GOYA_PKT_LIN_DMA_CTL_WO_SHIFT) |
48054805 (1 << GOYA_PKT_CTL_RB_SHIFT) |
48064806 (1 << GOYA_PKT_CTL_MB_SHIFT));
4807− ctl |= (is_dram ? DMA_HOST_TO_DRAM : DMA_HOST_TO_SRAM) <<
4807+ ctl |= (is_dram ? HL_DMA_HOST_TO_DRAM : HL_DMA_HOST_TO_SRAM) <<
48084808 GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT;
48094809 lin_dma_pkt->ctl = cpu_to_le32(ctl);
48104810
drivers/misc/habanalabs/include/goya/goya_packets.h+0−12
@@ -28,18 +28,6 @@ enum packet_id { · 27 unmodified lines
2828 PACKET_HEADER_PACKET_ID_SHIFT) + 1
2929 };
3030
31−enum goya_dma_direction {
32− DMA_HOST_TO_DRAM,
33− DMA_HOST_TO_SRAM,
34− DMA_DRAM_TO_SRAM,
35− DMA_SRAM_TO_DRAM,
36− DMA_SRAM_TO_HOST,
37− DMA_DRAM_TO_HOST,
38− DMA_DRAM_TO_DRAM,
39− DMA_SRAM_TO_SRAM,
40− DMA_ENUM_MAX
41−};
42−
4331 #define GOYA_PKT_CTL_OPCODE_SHIFT 24
4432 #define GOYA_PKT_CTL_OPCODE_MASK 0x1F000000
4533
include/uapi/misc/habanalabs.h+27−0
@@ -275,6 +275,33 @@ enum hl_gaudi_pll_index { · 274 unmodified lines
275275 HL_GAUDI_PLL_MAX
276276 };
277277
278+/**
279+ * enum hl_goya_dma_direction - Direction of DMA operation inside a LIN_DMA packet that is
280+ * submitted to the GOYA's DMA QMAN. This attribute is not relevant
281+ * to the H/W but the kernel driver use it to parse the packet's
282+ * addresses and patch/validate them.
283+ * @HL_DMA_HOST_TO_DRAM: DMA operation from Host memory to GOYA's DDR.
284+ * @HL_DMA_HOST_TO_SRAM: DMA operation from Host memory to GOYA's SRAM.
285+ * @HL_DMA_DRAM_TO_SRAM: DMA operation from GOYA's DDR to GOYA's SRAM.
286+ * @HL_DMA_SRAM_TO_DRAM: DMA operation from GOYA's SRAM to GOYA's DDR.
287+ * @HL_DMA_SRAM_TO_HOST: DMA operation from GOYA's SRAM to Host memory.
288+ * @HL_DMA_DRAM_TO_HOST: DMA operation from GOYA's DDR to Host memory.
289+ * @HL_DMA_DRAM_TO_DRAM: DMA operation from GOYA's DDR to GOYA's DDR.
290+ * @HL_DMA_SRAM_TO_SRAM: DMA operation from GOYA's SRAM to GOYA's SRAM.
291+ * @HL_DMA_ENUM_MAX: number of values in enum
292+ */
293+enum hl_goya_dma_direction {
294+ HL_DMA_HOST_TO_DRAM,
295+ HL_DMA_HOST_TO_SRAM,
296+ HL_DMA_DRAM_TO_SRAM,
297+ HL_DMA_SRAM_TO_DRAM,
298+ HL_DMA_SRAM_TO_HOST,
299+ HL_DMA_DRAM_TO_HOST,
300+ HL_DMA_DRAM_TO_DRAM,
301+ HL_DMA_SRAM_TO_SRAM,
302+ HL_DMA_ENUM_MAX
303+};
304+
278305 /**
279306 * enum hl_device_status - Device status information.
280307 * @HL_DEVICE_STATUS_OPERATIONAL: Device is operational.