1619 * and for kernel startup to attach to static segments.
1620 */
1621 int
1622 seg_attach(struct as *as, caddr_t base, size_t size, struct seg *seg)
1623 {
1624 seg->s_as = as;
1625 seg->s_base = base;
1626 seg->s_size = size;
1627
1628 /*
1629 * as_addseg() will add the segment at the appropraite point
1630 * in the list. It will return -1 if there is overlap with
1631 * an already existing segment.
1632 */
1633 return (as_addseg(as, seg));
1634 }
1635
1636 /*
1637 * Unmap a segment and free it from its associated address space.
1638 * This should be called by anybody who's finished with a whole segment's
1639 * mapping. Just calls SEGOP_UNMAP() on the whole mapping . It is the
1640 * responsibility of the segment driver to unlink the the segment
1641 * from the address space, and to free public and private data structures
1642 * associated with the segment. (This is typically done by a call to
1643 * seg_free()).
1644 */
1645 void
1646 seg_unmap(struct seg *seg)
1647 {
1648 #ifdef DEBUG
1649 int ret;
1650 #endif /* DEBUG */
1651
1652 ASSERT(seg->s_as && AS_WRITE_HELD(seg->s_as, &seg->s_as->a_lock));
1653
1654 /* Shouldn't have called seg_unmap if mapping isn't yet established */
1655 ASSERT(seg->s_data != NULL);
1656
1657 /* Unmap the whole mapping */
1658 #ifdef DEBUG
1659 ret = SEGOP_UNMAP(seg, seg->s_base, seg->s_size);
1660 ASSERT(ret == 0);
1661 #else
1662 SEGOP_UNMAP(seg, seg->s_base, seg->s_size);
1663 #endif /* DEBUG */
1664 }
1665
1666 /*
1667 * Free the segment from its associated as. This should only be called
1668 * if a mapping to the segment has not yet been established (e.g., if
1669 * an error occurs in the middle of doing an as_map when the segment
1670 * has already been partially set up) or if it has already been deleted
1671 * (e.g., from a segment driver unmap routine if the unmap applies to the
1672 * entire segment). If the mapping is currently set up then seg_unmap() should
1673 * be called instead.
1674 */
1675 void
1676 seg_free(struct seg *seg)
1677 {
1678 register struct as *as = seg->s_as;
1679 struct seg *tseg = as_removeseg(as, seg);
1680
1681 ASSERT(tseg == seg);
1682
1683 /*
1684 * If the segment private data field is NULL,
1685 * then segment driver is not attached yet.
1686 */
1687 if (seg->s_data != NULL)
1688 SEGOP_FREE(seg);
1689
1690 mutex_destroy(&seg->s_pmtx);
1691 ASSERT(seg->s_phead.p_lnext == &seg->s_phead);
1692 ASSERT(seg->s_phead.p_lprev == &seg->s_phead);
1693 kmem_cache_free(seg_cache, seg);
1694 }
1695
1696 /*ARGSUSED*/
1697 static void
1698 seg_p_mem_config_post_add(
1699 void *arg,
1700 pgcnt_t delta_pages)
1701 {
1702 /* Nothing to do. */
1703 }
1704
1705 void
1706 seg_p_enable(void)
1707 {
1708 mutex_enter(&seg_pcache_mtx);
1837 }
1838
1839 /*
1840 * Return swap reserved by a segment backing a private mapping.
1841 */
1842 size_t
1843 seg_swresv(struct seg *seg)
1844 {
1845 struct segvn_data *svd;
1846 size_t swap = 0;
1847
1848 if (seg->s_ops == &segvn_ops) {
1849 svd = (struct segvn_data *)seg->s_data;
1850 if (svd->type == MAP_PRIVATE && svd->swresv > 0)
1851 swap = svd->swresv;
1852 }
1853 return (swap);
1854 }
1855
1856 /*
1857 * General not supported function for SEGOP_INHERIT
1858 */
1859 /* ARGSUSED */
1860 int
1861 seg_inherit_notsup(struct seg *seg, caddr_t addr, size_t len, uint_t op)
1862 {
1863 return (ENOTSUP);
1864 }
1865
1866 /*
1867 * segop wrappers
1868 */
1869 int
1870 segop_dup(struct seg *seg, struct seg *new)
1871 {
1872 VERIFY3P(seg->s_ops->dup, !=, NULL);
1873
1874 return (seg->s_ops->dup(seg, new));
1875 }
1876
1877 int
|
1619 * and for kernel startup to attach to static segments.
1620 */
1621 int
1622 seg_attach(struct as *as, caddr_t base, size_t size, struct seg *seg)
1623 {
1624 seg->s_as = as;
1625 seg->s_base = base;
1626 seg->s_size = size;
1627
1628 /*
1629 * as_addseg() will add the segment at the appropraite point
1630 * in the list. It will return -1 if there is overlap with
1631 * an already existing segment.
1632 */
1633 return (as_addseg(as, seg));
1634 }
1635
1636 /*
1637 * Unmap a segment and free it from its associated address space.
1638 * This should be called by anybody who's finished with a whole segment's
1639 * mapping. Just calls segop_unmap() on the whole mapping . It is the
1640 * responsibility of the segment driver to unlink the the segment
1641 * from the address space, and to free public and private data structures
1642 * associated with the segment. (This is typically done by a call to
1643 * seg_free()).
1644 */
1645 void
1646 seg_unmap(struct seg *seg)
1647 {
1648 #ifdef DEBUG
1649 int ret;
1650 #endif /* DEBUG */
1651
1652 ASSERT(seg->s_as && AS_WRITE_HELD(seg->s_as, &seg->s_as->a_lock));
1653
1654 /* Shouldn't have called seg_unmap if mapping isn't yet established */
1655 ASSERT(seg->s_data != NULL);
1656
1657 /* Unmap the whole mapping */
1658 #ifdef DEBUG
1659 ret = segop_unmap(seg, seg->s_base, seg->s_size);
1660 ASSERT(ret == 0);
1661 #else
1662 segop_unmap(seg, seg->s_base, seg->s_size);
1663 #endif /* DEBUG */
1664 }
1665
1666 /*
1667 * Free the segment from its associated as. This should only be called
1668 * if a mapping to the segment has not yet been established (e.g., if
1669 * an error occurs in the middle of doing an as_map when the segment
1670 * has already been partially set up) or if it has already been deleted
1671 * (e.g., from a segment driver unmap routine if the unmap applies to the
1672 * entire segment). If the mapping is currently set up then seg_unmap() should
1673 * be called instead.
1674 */
1675 void
1676 seg_free(struct seg *seg)
1677 {
1678 register struct as *as = seg->s_as;
1679 struct seg *tseg = as_removeseg(as, seg);
1680
1681 ASSERT(tseg == seg);
1682
1683 /*
1684 * If the segment private data field is NULL,
1685 * then segment driver is not attached yet.
1686 */
1687 if (seg->s_data != NULL)
1688 segop_free(seg);
1689
1690 mutex_destroy(&seg->s_pmtx);
1691 ASSERT(seg->s_phead.p_lnext == &seg->s_phead);
1692 ASSERT(seg->s_phead.p_lprev == &seg->s_phead);
1693 kmem_cache_free(seg_cache, seg);
1694 }
1695
1696 /*ARGSUSED*/
1697 static void
1698 seg_p_mem_config_post_add(
1699 void *arg,
1700 pgcnt_t delta_pages)
1701 {
1702 /* Nothing to do. */
1703 }
1704
1705 void
1706 seg_p_enable(void)
1707 {
1708 mutex_enter(&seg_pcache_mtx);
1837 }
1838
1839 /*
1840 * Return swap reserved by a segment backing a private mapping.
1841 */
1842 size_t
1843 seg_swresv(struct seg *seg)
1844 {
1845 struct segvn_data *svd;
1846 size_t swap = 0;
1847
1848 if (seg->s_ops == &segvn_ops) {
1849 svd = (struct segvn_data *)seg->s_data;
1850 if (svd->type == MAP_PRIVATE && svd->swresv > 0)
1851 swap = svd->swresv;
1852 }
1853 return (swap);
1854 }
1855
1856 /*
1857 * General not supported function for segop_inherit
1858 */
1859 /* ARGSUSED */
1860 int
1861 seg_inherit_notsup(struct seg *seg, caddr_t addr, size_t len, uint_t op)
1862 {
1863 return (ENOTSUP);
1864 }
1865
1866 /*
1867 * segop wrappers
1868 */
1869 int
1870 segop_dup(struct seg *seg, struct seg *new)
1871 {
1872 VERIFY3P(seg->s_ops->dup, !=, NULL);
1873
1874 return (seg->s_ops->dup(seg, new));
1875 }
1876
1877 int
|