1794 *
1795 * Maximum segment size is the largest physically contiguous chunk of
1796 * memory that we can return from a bind (i.e. the maximum size of a
1797 * single cookie).
1798 */
1799
1800 /* handle the rollover cases */
1801 seg = attr->dma_attr_seg + 1;
1802 if (seg < attr->dma_attr_seg) {
1803 seg = attr->dma_attr_seg;
1804 }
1805 count_max = attr->dma_attr_count_max + 1;
1806 if (count_max < attr->dma_attr_count_max) {
1807 count_max = attr->dma_attr_count_max;
1808 }
1809
1810 /*
1811 * granularity may or may not be a power of two. If it isn't, we can't
1812 * use a simple mask.
1813 */
1814 if (attr->dma_attr_granular & (attr->dma_attr_granular - 1)) {
1815 dma->dp_granularity_power_2 = B_FALSE;
1816 } else {
1817 dma->dp_granularity_power_2 = B_TRUE;
1818 }
1819
1820 /*
1821 * maxxfer should be a whole multiple of granularity. If we're going to
1822 * break up a window because we're greater than maxxfer, we might as
1823 * well make sure it's maxxfer is a whole multiple so we don't have to
1824 * worry about triming the window later on for this case.
1825 */
1826 if (attr->dma_attr_granular > 1) {
1827 if (dma->dp_granularity_power_2) {
1828 dma->dp_maxxfer = attr->dma_attr_maxxfer -
1829 (attr->dma_attr_maxxfer &
1830 (attr->dma_attr_granular - 1));
1831 } else {
1832 dma->dp_maxxfer = attr->dma_attr_maxxfer -
1833 (attr->dma_attr_maxxfer % attr->dma_attr_granular);
1834 }
3852 ASSERT(pidx < sinfo->si_max_pages);
3853
3854 /* if this cookie uses the copy buffer */
3855 if (cookie->dmac_type & ROOTNEX_USES_COPYBUF) {
3856 /*
3857 * NOTE: we know that since this cookie uses the copy buffer, it
3858 * is <= MMU_PAGESIZE.
3859 */
3860
3861 /*
3862 * get the offset into the page. For the 64-bit kernel, get the
3863 * pfn which we'll use with seg kpm.
3864 */
3865 poff = cookie->dmac_laddress & MMU_PAGEOFFSET;
3866 #if defined(__amd64)
3867 /* mfn_to_pfn() is a NOP on i86pc */
3868 pfn = mfn_to_pfn(cookie->dmac_laddress >> MMU_PAGESHIFT);
3869 #endif /* __amd64 */
3870
3871 /* figure out if the copybuf size is a power of 2 */
3872 if (dma->dp_copybuf_size & (dma->dp_copybuf_size - 1)) {
3873 copybuf_sz_power_2 = B_FALSE;
3874 } else {
3875 copybuf_sz_power_2 = B_TRUE;
3876 }
3877
3878 /* This page uses the copy buffer */
3879 dma->dp_pgmap[pidx].pm_uses_copybuf = B_TRUE;
3880
3881 /*
3882 * save the copy buffer KVA that we'll use with this page.
3883 * if we still fit within the copybuf, it's a simple add.
3884 * otherwise, we need to wrap over using & or % accordingly.
3885 */
3886 if ((*copybuf_used + MMU_PAGESIZE) <= dma->dp_copybuf_size) {
3887 dma->dp_pgmap[pidx].pm_cbaddr = dma->dp_cbaddr +
3888 *copybuf_used;
3889 } else {
3890 if (copybuf_sz_power_2) {
3891 dma->dp_pgmap[pidx].pm_cbaddr = (caddr_t)(
3892 (uintptr_t)dma->dp_cbaddr +
|
1794 *
1795 * Maximum segment size is the largest physically contiguous chunk of
1796 * memory that we can return from a bind (i.e. the maximum size of a
1797 * single cookie).
1798 */
1799
1800 /* handle the rollover cases */
1801 seg = attr->dma_attr_seg + 1;
1802 if (seg < attr->dma_attr_seg) {
1803 seg = attr->dma_attr_seg;
1804 }
1805 count_max = attr->dma_attr_count_max + 1;
1806 if (count_max < attr->dma_attr_count_max) {
1807 count_max = attr->dma_attr_count_max;
1808 }
1809
1810 /*
1811 * granularity may or may not be a power of two. If it isn't, we can't
1812 * use a simple mask.
1813 */
1814 if (!ISP2(attr->dma_attr_granular)) {
1815 dma->dp_granularity_power_2 = B_FALSE;
1816 } else {
1817 dma->dp_granularity_power_2 = B_TRUE;
1818 }
1819
1820 /*
1821 * maxxfer should be a whole multiple of granularity. If we're going to
1822 * break up a window because we're greater than maxxfer, we might as
1823 * well make sure it's maxxfer is a whole multiple so we don't have to
1824 * worry about triming the window later on for this case.
1825 */
1826 if (attr->dma_attr_granular > 1) {
1827 if (dma->dp_granularity_power_2) {
1828 dma->dp_maxxfer = attr->dma_attr_maxxfer -
1829 (attr->dma_attr_maxxfer &
1830 (attr->dma_attr_granular - 1));
1831 } else {
1832 dma->dp_maxxfer = attr->dma_attr_maxxfer -
1833 (attr->dma_attr_maxxfer % attr->dma_attr_granular);
1834 }
3852 ASSERT(pidx < sinfo->si_max_pages);
3853
3854 /* if this cookie uses the copy buffer */
3855 if (cookie->dmac_type & ROOTNEX_USES_COPYBUF) {
3856 /*
3857 * NOTE: we know that since this cookie uses the copy buffer, it
3858 * is <= MMU_PAGESIZE.
3859 */
3860
3861 /*
3862 * get the offset into the page. For the 64-bit kernel, get the
3863 * pfn which we'll use with seg kpm.
3864 */
3865 poff = cookie->dmac_laddress & MMU_PAGEOFFSET;
3866 #if defined(__amd64)
3867 /* mfn_to_pfn() is a NOP on i86pc */
3868 pfn = mfn_to_pfn(cookie->dmac_laddress >> MMU_PAGESHIFT);
3869 #endif /* __amd64 */
3870
3871 /* figure out if the copybuf size is a power of 2 */
3872 if (!ISP2(dma->dp_copybuf_size)) {
3873 copybuf_sz_power_2 = B_FALSE;
3874 } else {
3875 copybuf_sz_power_2 = B_TRUE;
3876 }
3877
3878 /* This page uses the copy buffer */
3879 dma->dp_pgmap[pidx].pm_uses_copybuf = B_TRUE;
3880
3881 /*
3882 * save the copy buffer KVA that we'll use with this page.
3883 * if we still fit within the copybuf, it's a simple add.
3884 * otherwise, we need to wrap over using & or % accordingly.
3885 */
3886 if ((*copybuf_used + MMU_PAGESIZE) <= dma->dp_copybuf_size) {
3887 dma->dp_pgmap[pidx].pm_cbaddr = dma->dp_cbaddr +
3888 *copybuf_used;
3889 } else {
3890 if (copybuf_sz_power_2) {
3891 dma->dp_pgmap[pidx].pm_cbaddr = (caddr_t)(
3892 (uintptr_t)dma->dp_cbaddr +
|