@@ -49,6 +49,24 @@ get_driver_config(const pt::ptree& aie_meta)
4949 return driver_config;
5050}
5151
52+ int
53+ xdna_aie_array::
54+ get_aie_partition_fd (const xdna_hwctx* hwctx_obj)
55+ {
56+ int aie_fd = -1 ;
57+ auto dev = const_cast <xdna_hwctx*>(hwctx_obj)->get_device ();
58+
59+ amdxdna_drm_get_array arg = {};
60+ arg.param = DRM_AMDXDNA_HWCTX_AIE_PART_FD;
61+ arg.element_size = sizeof (aie_fd);
62+ arg.num_element = hwctx_obj->get_slotidx (); /* hwctx handle passed via num_element */
63+ arg.buffer = reinterpret_cast <uintptr_t >(&aie_fd);
64+
65+ dev->get_edev ()->ioctl (DRM_IOCTL_AMDXDNA_GET_ARRAY, &arg);
66+
67+ return aie_fd;
68+ }
69+
5270xdna_aie_array::
5371xdna_aie_array (const xrt_core::device* device)
5472{
@@ -72,7 +90,7 @@ xdna_aie_array(const xrt_core::device* device)
7290 int RC = XAie_GetPartitionFdList (&dev_inst_obj);
7391
7492 if (RC != XAIE_OK)
75- throw xrt_core::error (RC," XAie_GetPartitionFdList failed \n " );
93+ throw xrt_core::error (RC, " XAie_GetPartitionFdList failed\n " );
7694
7795 XAie_List *NodePtr;
7896 XAie_PartitionList *ListNode;
@@ -83,10 +101,8 @@ xdna_aie_array(const xrt_core::device* device)
83101
84102 int aie_part_fd = ListNode->PartitionFd ;
85103
86- // int aie_part_fd = fd;
87-
88104 if (aie_part_fd < 0 )
89- throw xrt_core::error (aie_part_fd," fd is NEGATIVE\n " );
105+ throw xrt_core::error (aie_part_fd, " fd is NEGATIVE\n " );
90106
91107 fd = aie_part_fd;
92108 ConfigPtr.PartProp .Handle = fd;
@@ -125,22 +141,10 @@ xdna_aie_array(const xrt_core::device* device, const xdna_hwctx* hwctx_obj)
125141 throw xrt_core::error (-EINVAL, " Failed to setup AIE Partition: " + std::to_string (rc1));
126142 }
127143
128- int RC = XAie_GetPartitionFdList (&dev_inst_obj);
129-
130- if (RC != XAIE_OK)
131- throw xrt_core::error (RC," XAie_GetPartitionFdList failed \n " );
132-
133- XAie_List *NodePtr;
134- XAie_PartitionList *ListNode;
135-
136- NodePtr = (XAie_List *)&dev_inst_obj.PartitionList .Next ->Next ;
137-
138- ListNode = (XAie_PartitionList *)XAIE_CONTAINER_OF (NodePtr, XAie_PartitionList, Node);
139-
140- int aie_part_fd = ListNode->PartitionFd ;
141-
144+ // Get AIE partition FD from kernel via ioctl
145+ int aie_part_fd = get_aie_partition_fd (hwctx_obj);
142146 if (aie_part_fd < 0 )
143- throw xrt_core::error (aie_part_fd," fd is NEGATIVE \n " );
147+ throw xrt_core::error (aie_part_fd, " Failed to get AIE partition FD \n " );
144148
145149 fd = aie_part_fd;
146150 ConfigPtr.PartProp .Handle = fd;
0 commit comments