| 264 | } |
| 265 | |
| 266 | static int |
| 267 | device_map_resources(struct rte_platform_device *pdev, unsigned int num) |
| 268 | { |
| 269 | struct rte_platform_resource *res; |
| 270 | unsigned int i; |
| 271 | int ret; |
| 272 | |
| 273 | if (num == 0) { |
| 274 | PLATFORM_LOG(WARNING, "device %s has no resources\n", pdev->name); |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | pdev->resource = calloc(num, sizeof(*pdev->resource)); |
| 279 | if (pdev->resource == NULL) |
| 280 | return -ENOMEM; |
| 281 | |
| 282 | for (i = 0; i < num; i++) { |
| 283 | struct vfio_region_info reg_info = { |
| 284 | .argsz = sizeof(reg_info), |
| 285 | .index = i, |
| 286 | }; |
| 287 | |
| 288 | ret = ioctl(pdev->dev_fd, VFIO_DEVICE_GET_REGION_INFO, ®_info); |
| 289 | if (ret) { |
| 290 | PLATFORM_LOG(ERR, "failed to get region info at %d\n", i); |
| 291 | ret = -errno; |
| 292 | goto out; |
| 293 | } |
| 294 | |
| 295 | res = &pdev->resource[i]; |
| 296 | res->name = of_resource_name(pdev->name, reg_info.index); |
| 297 | res->mem.len = reg_info.size; |
| 298 | ret = device_map_resource_offset(pdev, res, reg_info.offset); |
| 299 | if (ret) { |
| 300 | PLATFORM_LOG(ERR, "failed to ioremap resource at %d\n", i); |
| 301 | goto out; |
| 302 | } |
| 303 | |
| 304 | pdev->num_resource++; |
| 305 | } |
| 306 | |
| 307 | return 0; |
| 308 | out: |
| 309 | device_unmap_resources(pdev); |
| 310 | |
| 311 | return ret; |
| 312 | } |
| 313 | |
| 314 | static void |
| 315 | device_cleanup(struct rte_platform_device *pdev) |
no test coverage detected