*参照元 [#r366bf96]
#backlinks

*説明 [#zc8145c8]
-パス: [[linux-2.6.33/include/asm-generic/dma-coherent.h]]

-FIXME: これは何?
--確保した領域は 0 データで埋められる
--確保した領域は 0 データで埋められる。
--コンフィグにより、マクロの場合と関数の場合の 2通りある。


**引数 [#d5af6009]
-struct device *dev
--デバイス
--[[linux-2.6.33/device]]
-ssize_t size
--確保する領域のサイズ
-dma_addr_t *dma_handle
--確保した領域の DMA アドレスを返すためのポインタ
--失敗したときは不定値が返る
--[[linux-2.6.33/dma_addr_t]]
-void **ret
--確保した領域の仮想アドレスを返すためのポインタ
--失敗したときは不定値が返る


**返り値 [#f8c12ac4]
-int
--成功なら 0以外、失敗なら 0


**参考 [#h5efe1a3]
汎用の関数を利用するようにコンフィグを定義しているアーキテクチャは、
arm, mips, sh, x86 の一部に存在する。

 arch/arm/configs/acs5k_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/acs5k_tiny_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/afeb9260_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/am3517_evm_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/bcmring_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/cm_t35_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/cm_x2xx_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/cm_x300_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/colibri_pxa270_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/colibri_pxa300_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/corgi_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/cpu9260_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/cpu9g20_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/cpuat91_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/da8xx_omapl_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/davinci_all_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/dove_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/em_x270_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/ep93xx_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/eseries_pxa_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/ezx_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/h3600_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/h5000_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/htcherald_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/igep0020_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/iop33x_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/jornada720_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/kb9202_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/kirkwood_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/ks8695_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/magician_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/mini2440_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/mv78xx0_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/mx1_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/mx21_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/mx27_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/mx31pdk_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/mx3_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/n8x0_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/neocore926_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/nhk8815_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/nuc910_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/nuc950_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/nuc960_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/omap3_beagle_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/omap3_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/omap3_evm_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/omap3_pandora_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/omap3_touchbook_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/omap_3430sdp_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/omap_3630sdp_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/omap_4430sdp_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/omap_ldp_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/omap_zoom2_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/omap_zoom3_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/orion5x_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/overo_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/palmz72_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/pxa168_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/pxa3xx_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/pxa910_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/realview-smp_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/realview_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/rx51_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/s3c2410_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/s3c6400_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/s5pc100_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/shark_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/spitz_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/stmp378x_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/stmp37xx_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/u300_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/u8500_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/viper_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/xcep_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/arm/configs/zeus_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/mips/configs/fuloong2e_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/mips/configs/ip27_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/mips/configs/lemote2f_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/mips/configs/rbtx49xx_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/ap325rxa_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/cayman_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/dreamcast_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/ecovec24-romimage_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/ecovec24_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/edosk7705_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/edosk7760_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/espt_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/hp6xx_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/kfr2r09-romimage_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/kfr2r09_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/landisk_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/lboxre2_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/magicpanelr2_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/microdev_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/migor_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/polaris_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/r7780mp_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/r7785rp_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/rsk7201_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/rsk7203_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/rts7751r2d1_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/rts7751r2dplus_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/sdk7780_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/se7206_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/se7343_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/se7619_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/se7705_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/se7712_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/se7721_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/se7722_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/se7724_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/se7750_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/se7751_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/se7780_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/sh03_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/sh7710voipgw_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/sh7724_generic_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/sh7763rdp_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/sh7770_generic_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/sh7785lcr_32bit_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/sh7785lcr_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/shmin_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/shx3_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/snapgear_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/systemh_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/titan_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/ul2_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/sh/configs/urquell_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 arch/x86/configs/i386_defconfig:CONFIG_HAVE_GENERIC_DMA_COHERENT=y


*実装 [#fd489f93]

** ヘッダ [#raa13539]
 #ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT
-
--[[linux-2.6.33/CONFIG_HAVE_GENERIC_DMA_COHERENT]]

 /*
  * These two functions are only for dma allocator.
  * Don't use them in device drivers.
  */
 int dma_alloc_from_coherent(struct device *dev, ssize_t size,
 				       dma_addr_t *dma_handle, void **ret);
 (...中略...)
 #else
 #define dma_alloc_from_coherent(dev, size, handle, ret) (0)
-何もせず、失敗を返す。

 (...中略...)
 #endif



** drivers/base/dma-coherent.c: CONFIG_HAVE_GENERIC_DMA_COHERENT が定義される場合 [#s873c4a8]

 /**
  * dma_alloc_from_coherent() - try to allocate memory from the per-device coherent area
  *
  * @dev:	device from which we allocate memory
  * @size:	size of requested memory area
  * @dma_handle:	This will be filled with the correct dma handle
  * @ret:	This pointer will be filled with the virtual address
  *		to allocated area.
  *
  * This function should be only called from per-arch dma_alloc_coherent()
  * to support allocation from per-device coherent memory pools.
  *
  * Returns 0 if dma_alloc_coherent should continue with allocating from
  * generic memory areas, or !0 if dma_alloc_coherent should return @ret.
  */
 int dma_alloc_from_coherent(struct device *dev, ssize_t size,
 				       dma_addr_t *dma_handle, void **ret)
 {
 	struct dma_coherent_mem *mem;
 	int order = get_order(size);
 	int pageno;
 
-
--[[linux-2.6.33/dma_coherent_mem]]
-
--[[linux-2.6.33/get_order()]]

 	if (!dev)
 		return 0;
 	mem = dev->dma_mem;
 	if (!mem)
 		return 0;
 
 	*ret = NULL;
 
 	if (unlikely(size > (mem->size << PAGE_SHIFT)))
 		goto err;
 
-
--[[linux-2.6.33/PAGE_SHIFT]]

 	pageno = bitmap_find_free_region(mem->bitmap, mem->size, order);
 	if (unlikely(pageno < 0))
 		goto err;
 
-
--[[linux-2.6.33/bitmap_find_free_region()]]
-
--[[linux-2.6.33/unlikely()]]

 	/*
 	 * Memory was found in the per-device area.
 	 */
 	*dma_handle = mem->device_base + (pageno << PAGE_SHIFT);
 	*ret = mem->virt_base + (pageno << PAGE_SHIFT);
 	memset(*ret, 0, size);
 
 	return 1;
 
 err:
 	/*
 	 * In the case where the allocation can not be satisfied from the
 	 * per-device area, try to fall back to generic memory if the
 	 * constraints allow it.
 	 */
 	return mem->flags & DMA_MEMORY_EXCLUSIVE;
-
--[[linux-2.6.33/DMA_MEMORY_EXCLUSIVE]]

 }
 EXPORT_SYMBOL(dma_alloc_from_coherent);
-ライセンスに関係なくシンボルを公開する。
--[[linux-2.6.33/EXPORT_SYMBOL()]]



** include/asm-generic/dma-coherent.h: CONFIG_HAVE_GENERIC_DMA_COHERENT が定義されない場合 [#v329bf7d]

 #define dma_alloc_from_coherent(dev, size, handle, ret) (0)
-何もせず、失敗を返す。


*コメント [#v7a5513c]

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS