17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51ae08745Sheppo  * Common Development and Distribution License (the "License").
61ae08745Sheppo  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
211ae08745Sheppo 
227c478bd9Sstevel@tonic-gate /*
23*d2365b01SPavel Tatashin  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _MACH_DESCRIP_H
287c478bd9Sstevel@tonic-gate #define	_MACH_DESCRIP_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef __cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
341ae08745Sheppo #include <sys/kstat.h>
351ae08745Sheppo #include <sys/ksynch.h>
361ae08745Sheppo #include <sys/mdesc.h>
371ae08745Sheppo 
387c478bd9Sstevel@tonic-gate /*
391ae08745Sheppo  * MD memory operations (memops) are of two types:
401ae08745Sheppo  * buf:
411ae08745Sheppo  * 	Buffer allocator routines used to allocate the MD buffer.
421ae08745Sheppo  *	Allocator must support an alignment argument.
431ae08745Sheppo  *
441ae08745Sheppo  * meta:
451ae08745Sheppo  *	Meta allocator routines to allocate meta data strcutures.
461ae08745Sheppo  *	These allocations are small and don't have alignment
471ae08745Sheppo  *	requirements. Examples, md_t handles and the machine_descrip_t
481ae08745Sheppo  *	structure.
497c478bd9Sstevel@tonic-gate  */
501ae08745Sheppo typedef struct machine_descrip_memops {
511ae08745Sheppo 	void 		*(*buf_allocp)(size_t size, size_t align);
521ae08745Sheppo 	void 		(*buf_freep)(void *, size_t size);
531ae08745Sheppo 	void 		*(*meta_allocp)(size_t size);
541ae08745Sheppo 	void 		(*meta_freep)(void *, size_t size);
551ae08745Sheppo } machine_descrip_memops_t;
567c478bd9Sstevel@tonic-gate 
571ae08745Sheppo /*
581ae08745Sheppo  * Common structure/list between kernel and mdesc driver enabling
591ae08745Sheppo  * the current machine description to be retrieved or updated.
601ae08745Sheppo  *
611ae08745Sheppo  * Locks:
621ae08745Sheppo  * The current global MD is protected by the curr_mach_descrip_lock.
631ae08745Sheppo  * Each Machine description has a lock to synchronize its ref count.
641ae08745Sheppo  * The Obsolete MD list is protected by the obs_list_lock.
651ae08745Sheppo  */
661ae08745Sheppo typedef struct machine_descrip_s {
671ae08745Sheppo 	uint64_t	gen;		/* Generation number for MD */
681ae08745Sheppo 	kmutex_t	lock;		/* synchronize access to MD */
691ae08745Sheppo 	void		*va;		/* virtual address */
701ae08745Sheppo 	uint64_t	size;		/* size of MD */
711ae08745Sheppo 	uint64_t	space;		/* space allocated for MD */
721ae08745Sheppo 	int		refcnt;		/* MD ref count */
731ae08745Sheppo 	struct machine_descrip_s *next;	/* Next MD in list */
741ae08745Sheppo 	machine_descrip_memops_t *memops; /* Memory operations for MD */
751ae08745Sheppo } machine_descrip_t;
767c478bd9Sstevel@tonic-gate 
771ae08745Sheppo /*
781ae08745Sheppo  * Utility wrappers to get/fini a handle to the current MD.
791ae08745Sheppo  */
801ae08745Sheppo extern md_t *md_get_handle(void);
811ae08745Sheppo extern int md_fini_handle(md_t *);
821ae08745Sheppo extern caddr_t md_get_md_raw(md_t *);
831ae08745Sheppo extern int md_alloc_scan_dag(md_t *, mde_cookie_t, char *, char *,
841ae08745Sheppo 	    mde_cookie_t **);
851ae08745Sheppo extern void md_free_scan_dag(md_t *, mde_cookie_t **);
86*d2365b01SPavel Tatashin extern uint64_t md_get_current_gen(void);
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #ifdef __cplusplus
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate #endif
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #endif	/* _MACH_DESCRIP_H */
93