@@ -182,7 +182,7 @@ static ocxl_err global_mmio_map(ocxl_afu *afu, size_t size, int prot, uint64_t f
182182 * contents of this area are specific each AFU. The size can be discovered with
183183 * ocxl_mmio_size().
184184 *
185- * @pre the AFU has been opened
185+ * @pre the AFU has been opened and attached
186186 *
187187 * @param afu the AFU to operate on
188188 * @param size the size of the MMIO region to map (or 0 to map the full region)
@@ -193,7 +193,7 @@ static ocxl_err global_mmio_map(ocxl_afu *afu, size_t size, int prot, uint64_t f
193193 *
194194 * @retval OCXL_OK on success
195195 * @retval OCXL_NO_MEM if the map failed
196- * @retval OCXL_NO_CONTEXT if the AFU has not been opened
196+ * @retval OCXL_NO_CONTEXT if the AFU has not been opened/attached
197197 * @retval OCXL_INVALID_ARGS if the flags are not valid
198198 */
199199static ocxl_err mmio_map (ocxl_afu * afu , size_t size , int prot , uint64_t flags , off_t offset , ocxl_mmio_h * region )
@@ -206,12 +206,17 @@ static ocxl_err mmio_map(ocxl_afu *afu, size_t size, int prot, uint64_t flags, o
206206
207207 if (afu -> fd < 0 ) {
208208 ocxl_err rc = OCXL_NO_CONTEXT ;
209- errmsg (afu , rc , "Could not map per-PASID MMIO on AFU '%s' as it has not been opened" ,
210- afu -> identifier .afu_name );
209+ errmsg (afu , rc , "Could not map per-PASID MMIO as the AFU has not been opened" );
210+ return rc ;
211+ }
212+
213+ if (!afu -> attached ) {
214+ ocxl_err rc = OCXL_NO_CONTEXT ;
215+ errmsg (afu , rc , "Could not map per-PASID MMIO as the AFU has not been attached" );
211216 return rc ;
212217 }
213218
214- void * addr = mmap (NULL , afu -> per_pasid_mmio . length , prot , MAP_SHARED , afu -> fd , offset );
219+ void * addr = mmap (NULL , size , prot , MAP_SHARED , afu -> fd , offset );
215220 if (addr == MAP_FAILED ) {
216221 ocxl_err rc = OCXL_NO_MEM ;
217222 errmsg (afu , rc , "Could not map per-PASID MMIO: %d: %s" , errno , strerror (errno ));
0 commit comments