seg_spt.h revision 2ba723d838804c333c83abc6e074a28f8a07b6c9
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith/*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * CDDL HEADER START
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * The contents of this file are subject to the terms of the
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Common Development and Distribution License (the "License").
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * You may not use this file except in compliance with the License.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * or http://www.opensolaris.org/os/licensing.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * See the License for the specific language governing permissions
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * and limitations under the License.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * When distributing Covered Code, include this CDDL HEADER in each
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * If applicable, add the following below this CDDL HEADER, with the
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * fields enclosed by brackets "[]" replaced with your own identifying
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * information: Portions Copyright [yyyy] [name of copyright owner]
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith *
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * CDDL HEADER END
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith/*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Use is subject to license terms.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#ifndef _VM_SEG_SPT_H
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define _VM_SEG_SPT_H
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#pragma ident "%Z%%M% %I% %E% SMI"
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#ifdef __cplusplus
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmithextern "C" {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#endif
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#ifndef _ASM
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#include <sys/types.h>
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#include <sys/t_lock.h>
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#include <sys/lgrp.h>
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith/*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Passed data when creating spt segment.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmithstruct segspt_crargs {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith struct seg *seg_spt;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith struct anon_map *amp;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith uint_t prot;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith uint_t flags;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith uint_t szc;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith};
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmithtypedef struct spt_data {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith struct vnode *spt_vp;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith struct anon_map *spt_amp;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith size_t spt_realsize;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith struct page **spt_ppa;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith ushort_t *spt_ppa_lckcnt;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith uint_t spt_prot;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith kmutex_t spt_lock;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith size_t spt_pcachecnt; /* # of times in pcache */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith uint_t spt_flags; /* Dynamic ISM or regular ISM */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith kcondvar_t spt_cv;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith ushort_t spt_gen; /* only updated for DISM */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Initial memory allocation policy
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * used during pre-allocation done in shmat()
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith lgrp_mem_policy_info_t spt_policy_info;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith} spt_data_t;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith/*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Private data for spt_shm segment.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmithtypedef struct shm_data {
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith struct as *shm_sptas;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith struct anon_map *shm_amp;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith size_t shm_softlockcnt; /* # outstanding lock operations */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith struct seg *shm_sptseg; /* pointer to spt segment */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith char *shm_vpage; /* indicating locked pages */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith spgcnt_t shm_lckpgs; /* # of locked pages per attached seg */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith /*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Memory allocation policy after shmat()
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith lgrp_mem_policy_info_t shm_policy_info;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith} shm_data_t;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define DISM_PG_LOCKED 0x1 /* DISM page is locked */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define DISM_PPA_CHANGED 0x2 /* DISM new lock, need to rebuild ppa */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define DISM_LOCK_MAX 0xfffe /* max number of locks per DISM page */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#endif
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#ifdef _KERNEL
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#ifndef _ASM
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith/*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * Functions used in shm.c to call ISM.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmithint sptcreate(size_t size, struct seg **sptseg, struct anon_map *amp,
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith uint_t prot, uint_t flags, uint_t szc);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmithvoid sptdestroy(struct as *, struct anon_map *);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmithint segspt_shmattach(struct seg *, caddr_t *);
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define isspt(sp) ((sp)->shm_sptinfo ? (sp)->shm_sptinfo->sptas : NULL)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define spt_locked(a) ((a) & SHM_SHARE_MMU)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define spt_pageable(a) ((a) & SHM_PAGEABLE)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define spt_invalid(a) (spt_locked((a)) && spt_pageable((a)))
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith/*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * This can be applied to a segment with seg->s_ops == &segspt_shmops
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * to determine the real size of the ISM segment.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define spt_realsize(seg) (((struct spt_data *)(((struct shm_data *)\
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith ((seg)->s_data))->shm_sptseg->s_data))->spt_realsize)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith/*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * This can be applied to a segment with seg->s_ops == &segspt_ops
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * to determine the flags of the {D}ISM segment.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define spt_flags(seg) (((struct spt_data *)((seg)->s_data))->spt_flags)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith/*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * For large page support
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmithextern int segvn_anypgsz;
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#endif
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith/*
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * In a 64-bit address space, we'll try to put ISM segments between
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * PREDISM_BASE and PREDISM_BOUND. The HAT may use these constants to
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * predict that a VA is contained by an ISM segment, which may optimize
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * translation. The range must _only_ be treated as advisory; ISM segments
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * may fall outside of the range, and non-ISM segments may be contained
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * within the range.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * In order to avoid collision between ISM/DISM addresses with e.g.
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * process heap addresses we will try to put ISM/DISM segments above
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * PREDISM_1T_BASESHIFT (1T).
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * The HAT is still expecting that any VA larger than PREDISM_BASESHIFT
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * may belong to ISM/DISM (so on tlb miss it will probe first for 4M
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith * translation)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define PREDISM_BASESHIFT 33
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define PREDISM_1T_BASESHIFT 40
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define PREDISM_BASE ((uintptr_t)1 << PREDISM_BASESHIFT)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define PREDISM_1T_BASE ((uintptr_t)1 << PREDISM_1T_BASESHIFT)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#define PREDISM_BOUND ((uintptr_t)1 << 63)
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#endif /* _KERNEL */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#ifdef __cplusplus
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith}
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#endif
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith#endif /* _VM_SEG_SPT_H */
c1bef59b02d89a84c23d29663cc4e6d46148ebd2David Goldsmith