FIXME: なにをするもの?
drivers/staging/android/ion/tegra/tegra_ion.c が最短でわかりやすい。
エラー処理を全部外して基本的な流れだけ示せば、初期化は下記の通り。
static struct ion_device *idev; static int num_heaps; static struct ion_heap **heaps; static int tegra_ion_probe(struct platform_device *pdev) { struct ion_platform_data *pdata = pdev->dev.platform_data; num_heaps = pdata->nr; heaps = devm_kzalloc(&pdev->dev, sizeof(struct ion_heap *) * pdata->nr, GFP_KERNEL); idev = ion_device_create(NULL); /* create the heaps as specified in the board file */ for (i = 0; i < num_heaps; i++) { struct ion_platform_heap *heap_data = &pdata->heaps[i]; heaps[i] = ion_heap_create(heap_data); ion_device_add_heap(idev, heaps[i]); } platform_set_drvdata(pdev, idev);
終了は下記の通り。
static int tegra_ion_remove(struct platform_device *pdev) { struct ion_device *idev = platform_get_drvdata(pdev); int i; ion_device_destroy(idev); for (i = 0; i < num_heaps; i++) ion_heap_destroy(heaps[i]); return 0; }
Tegra の ION ドライバの場合、ドライバとデバイスの追加は分離されている。
メモリのどこから取るか(= &pdata->heaps[i] に入ってる情報)は、ドライバの外から与える仕組みになっていて、そのコードはカーネル内には存在しないようだ??
FIXME: platform_device_add() するときに渡しているのか?
調査方法。
ユーザー API
$ grep -r ION_IOC_ drivers/staging/android/uapi/ | grep define | grep MAGIC, | less -RS drivers/staging/android/uapi/ion.h:#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \ drivers/staging/android/uapi/ion.h:#define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data) drivers/staging/android/uapi/ion.h:#define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data) drivers/staging/android/uapi/ion.h:#define ION_IOC_SHARE _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data) drivers/staging/android/uapi/ion.h:#define ION_IOC_IMPORT _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data) drivers/staging/android/uapi/ion.h:#define ION_IOC_SYNC _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data) drivers/staging/android/uapi/ion.h:#define ION_IOC_CUSTOM _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
カーネル API
$ grep -r EXPORT_SYMBOL drivers/staging/android/ion/ drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_alloc); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_free); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_phys); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_map_kernel); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_unmap_kernel); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_client_create); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_client_destroy); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_sg_table); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_share_dma_buf); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_share_dma_buf_fd); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_import_dma_buf); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_device_add_heap); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_device_create); drivers/staging/android/ion/ion.c:EXPORT_SYMBOL(ion_device_destroy); drivers/staging/android/ion/ion_heap.c:EXPORT_SYMBOL(ion_heap_create); drivers/staging/android/ion/ion_heap.c:EXPORT_SYMBOL(ion_heap_destroy);