rootnex.h revision 0b7ba6115657ff183e0d3fa2c90c90f7f1cbf6ec
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _SYS_ROOTNEX_H
#define _SYS_ROOTNEX_H
/*
* x86 root nexus implementation specific state
*/
#include <sys/iommulib.h>
#ifdef __cplusplus
extern "C" {
#endif
/* size of buffer used for ctlop reportdev */
#define REPORTDEV_BUFSIZE 1024
/* min and max interrupt vectors */
#define VEC_MIN 1
#define VEC_MAX 255
#ifdef DEBUG
#else
#define ROOTNEX_DPROF_INC(addr)
#define ROOTNEX_DPROF_DEC(addr)
#endif
/* set in dmac_type to signify that this cookie uses the copy buffer */
#define ROOTNEX_USES_COPYBUF 0x80000000
/*
* integer or boolean property name and value. A few static rootnex properties
* are created during rootnex attach from an array of rootnex_intprop_t..
*/
typedef struct rootnex_intprop_s {
char *prop_name;
int prop_value;
/*
* sgl related information which is visible to rootnex_get_sgl(). Trying to
* isolate get_sgl() as much as possible so it can be easily replaced.
*/
typedef struct rootnex_sglinfo_s {
/*
* These are passed into rootnex_get_sgl().
*
* si_min_addr - the minimum physical address
* si_max_addr - the maximum physical address
* si_max_cookie_size - the maximum size of a physically contiguous
* piece of memory that we can handle in a sgl.
* si_segmask - segment mask to determine if we cross a segment boundary
* si_max_pages - max number of pages this sgl could occupy (which
* is also the maximum number of cookies we might see.
*/
/*
* these are returned by rootnex_get_sgl()
*
* si_copybuf_req - amount of copy buffer needed by the buffer.
* si_buf_offset - The initial offset into the first page of the buffer.
* It's set in get sgl and used in the bind slow path to help
* calculate the current page index & offset from the current offset
* which is relative to the start of the buffer.
* si_asp - address space of buffer passed in.
* si_sgl_size - The actual number of cookies in the sgl. This does
* not reflect and sharing that we might do on window boundaries.
*/
/*
* When we have to use the copy buffer, we allocate one of these structures per
* buffer page to track which pages need the copy buffer, what the kernel
* virtual address is (which the device can't reach), and what the copy buffer
* since we can't use seg kpm, we also need to keep the page_t around and state
* if we've currently mapped in the page into KVA space for buffers which don't
* have kva already and when we have multiple windows because we used up all our
* copy buffer space.
*/
typedef struct rootnex_pgmap_s {
#if !defined(__amd64)
#endif
/*
* We only need to trim a buffer when we have multiple windows. Each window has
* trim state. We might have trimmed the end of the previous window, leaving the
* first cookie of this window trimmed[tr_trim_first] (which basically means we
* won't start with a new cookie), or we might need to trim the end of the
* current window [tr_trim_last] (which basically means we won't end with a
* complete cookie). We keep the same state for the first & last cookie in a
* window (a window can have one or more cookies). However, when we trim the
* last cookie, we keep a pointer to the last cookie in the trim state since we
* only need this info when we trim. The pointer to the first cookie in the
* window is in the window state since we need to know what the first cookie in
* the window is in various places.
*
* If we do trim a cookie, we save away the physical address and size of the
* cookie so that we can over write the cookie when we switch windows (the
* space for a cookie which is in two windows is shared between the windows.
* We keep around the same information for the last page in a window.
*
* if we happened to trim on a page that uses the copy buffer, and that page
* is also in the middle of a window boundary because we have filled up the
* copy buffer, we need to remember the copy buffer address for both windows
* since the same page will have different copy buffer addresses in the two
* windows. We need to due the same for kaddr in the 32-bit kernel since we
* have a limited kva space which we map to.
*/
typedef struct rootnex_trim_s {
#if !defined(__amd64)
#endif
/*
* per window state. A bound DMA handle can have multiple windows. Each window
* will have the following state. We track if this window needs to sync,
* the offset into the buffer where the window starts, the size of the window.
* a pointer to the first cookie in the window, the number of cookies in the
* window, and the trim state for the window. For the 32-bit kernel, we keep
* track of if we need to remap the copy buffer when we switch to a this window
*/
typedef struct rootnex_window_s {
#if !defined(__amd64)
#endif
/* per dma handle private state */
typedef struct rootnex_dma_s {
/*
* sgl related state used to build and describe the sgl.
*
* dp_partial_required - used in the bind slow path to identify if we
* need to do a partial mapping or not.
* dp_trim_required - used in the bind slow path to identify if we
* need to trim when switching to a new window. This should only be
* set when partial is set.
* dp_granularity_power_2 - set in alloc handle and used in bind slow
* path to determine if we & or % to calculate the trim.
* dp_dma - copy of dma "object" passed in during bind
* dp_maxxfer - trimmed dma_attr_maxxfer so that it is a whole
* multiple of granularity
* dp_sglinfo - See rootnex_sglinfo_t above.
*/
/*
* Copy buffer related state
*
* dp_copybuf_size - the actual size of the copy buffer that we are
* using. This can be smaller that dp_copybuf_req, i.e. bind size >
* max copy buffer size.
* dp_cbaddr - kernel address of copy buffer. Used to determine where
* dp_cbsize - the "real" size returned from the copy buffer alloc.
* Set in the copybuf alloc and used to free copybuf.
* dp_pgmap - page map used in sync to determine which pages in the
* buffer use the copy buffer and what addresses to use to copy to/
* from.
* dp_cb_remaping - status if this bind causes us to have to remap
* the copybuf when switching to new windows. This is only used in
* the 32-bit kernel since we use seg kpm in the 64-bit kernel for
* this case.
* dp_kva - kernel heap arena vmem space for mapping to buffers which
* the 32-bit kernel since we use seg kpm in the 64-bit kernel for
* this case.
*/
#if !defined(__amd64)
#endif
/*
* window related state. The pointer to the window state array which may
* be a pointer into the pre allocated state, or we may have had to
* allocate the window array on the fly because it wouldn't fit. If
* we allocate it, we'll use dp_need_to_free_window and dp_window_size
* during cleanup. dp_current_win keeps track of the current window.
* dp_max_win is the maximum number of windows we could have.
*/
/* dip of driver which "owns" handle. set to rdip in alloc_handle() */
/*
* dp_mutex and dp_inuse are only used to see if a driver is trying to
* bind to an already bound dma handle. dp_mutex only used for dp_inuse
*/
/*
* cookie related state. The pointer to the cookies (dp_cookies) may
* be a pointer into the pre allocated state, or we may have had to
* allocate the cookie array on the fly because it wouldn't fit. If
* we allocate it, we'll use dp_need_to_free_cookie and dp_cookie_size
* during cleanup. dp_current_cookie is only used in the obsoleted
* interfaces to determine when we've used up all the cookies in a
* window during nextseg()..
*/
/*
* pre allocated space for the bind state, allocated during alloc
* handle. For a lot of devices, this will save us from having to do
* kmem_alloc's during the bind most of the time. kmem_alloc's can be
* expensive on x86 when the cpu count goes up since xcalls are
* expensive on x86.
*/
/*
* intel iommu related state
* dvma_cookies saves the dvma allocated for this handler, it has the
* size of si_max_pages, set when bind handler and freed when unbind
*/
void *dp_dvma_cookies;
/*
* sleep flags set on bind and unset on unbind
*/
int dp_sleep_flags;
/*
* profile/performance counters. Most things will be dtrace probes, but there
* are a couple of things we want to keep track all the time. We track the
* total number of active handles and binds (i.e. an alloc without a free or
* a bind without an unbind) since rootnex attach. We also track the total
* number of binds which have failed since rootnex attach.
*/
typedef enum {
/* This one must be last */
/*
* global driver state.
* r_dmahdl_cache - dma_handle kmem_cache
* r_dvma_call_list_id - ddi_set_callback() id
* r_peekpoke_mutex - serialize peeks and pokes.
* r_dip - rootnex dip
* r_reserved_msg_printed - ctlops reserve message threshold
* r_counters - profile/performance counters
* r_intel_iommu_enabled - intel iommu enabled
*/
typedef struct rootnex_state_s {
#ifdef __cplusplus
}
#endif
#endif /* _SYS_ROOTNEX_H */