~gma500/+junk/emgd160

« back to all changes in this revision

Viewing changes to emgd-dkms-kernel39/emgd/include/rb.h

  • Committer: Luca Forina
  • Date: 2011-05-10 07:28:19 UTC
  • Revision ID: luca.forina@gmail.com-20110510072819-pgj21l6igboa9dsx
emgd-dkms for kernel .39

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- pse-c -*-
 
2
 *-----------------------------------------------------------------------------
 
3
 * Filename: rb.h
 
4
 * $Revision: 1.8 $
 
5
 *-----------------------------------------------------------------------------
 
6
 * Copyright © 2002-2010, Intel Corporation.
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 
9
 * of this software and associated documentation files (the "Software"), to deal
 
10
 * in the Software without restriction, including without limitation the rights
 
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
12
 * copies of the Software, and to permit persons to whom the Software is
 
13
 * furnished to do so, subject to the following conditions:
 
14
 *
 
15
 * The above copyright notice and this permission notice shall be included in
 
16
 * all copies or substantial portions of the Software.
 
17
 *
 
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
24
 * THE SOFTWARE.
 
25
 *
 
26
 *-----------------------------------------------------------------------------
 
27
 * Description:
 
28
 *  This header file describes the inter-module interface for using the
 
29
 *  ring buffer. This is a legacy interface that is not strictly
 
30
 *  device-independent. It is kept here because many legacy chipsets use
 
31
 *  this interface.
 
32
 *-----------------------------------------------------------------------------
 
33
 */
 
34
 
 
35
#ifndef _RB_H
 
36
#define _RB_H
 
37
 
 
38
#include <igd_rb.h>
 
39
#include <igd_errno.h>
 
40
 
 
41
#include <context.h>
 
42
#include <module_init.h>
 
43
#include <mode.h>
 
44
 
 
45
#include <io.h>
 
46
#include <memory.h>
 
47
#include <sched.h>
 
48
 
 
49
 
 
50
/*
 
51
 * The rb_buffer contents should be treated as opaque but are defined
 
52
 * here for the use in the inline functions below.
 
53
 */
 
54
typedef struct _rb_buffer {
 
55
        unsigned int id;       /* ring index */
 
56
        unsigned long size;    /* size of rb in bytes */
 
57
        unsigned long tail_off;
 
58
        unsigned long dead_off;
 
59
        unsigned long avail;
 
60
        unsigned long addr;    /* starting address of rb */
 
61
        unsigned char *virt;    /* virt starting address of rb */
 
62
        unsigned char *start;   /* ring buffer start register offset */
 
63
        unsigned char *head;    /* ring buffer head register offset */
 
64
        unsigned char *tail;    /* ring buffer tail register offset */
 
65
        unsigned char *ctrl;    /* ring buffer ctrl register offset */
 
66
        unsigned char *sync;    /* used to synchronize s/w interface
 
67
                                                                   * code via rb_sync() */
 
68
        unsigned long next_sync;
 
69
        int state;             /* on or off state */
 
70
        unsigned long last_head_value; /* used for checking ring buf lockup,
 
71
                                                                        * keeps last head value*/
 
72
        os_alarm_t last_head_time; /* used for checking ring buf lockup,
 
73
                                                                * keeps last head time*/
 
74
        unsigned long reservation; /* increments upon each rb_reserver(),
 
75
                                                                * reset to zero upon rb_update() */
 
76
        unsigned long sync_wrap;   /* Sync number to wrap at */
 
77
        igd_context_t * context_ptr; /*back pointer to the main driver context */
 
78
        igd_appcontext_h appcontext; /* Appcontext that is current on the ring */
 
79
        unsigned int skip_timeout;  /* skip the timeout check */
 
80
        unsigned int force_reset_rb;  /* force a rb reset */
 
81
} rb_buffer_t;
 
82
 
 
83
 
 
84
#define MODE_GET_RING(d, p) \
 
85
        ((rb_buffer_t *)((igd_display_pipe_t *)((igd_display_context_t *)d)->pipe)->queue[p])
 
86
 
 
87
/*
 
88
 * Flags used exclusively by rb_reserve()
 
89
 */
 
90
#define RB_RESERVE_BLOCK     0x00000000
 
91
#define RB_RESERVE_NONBLOCK  0x00000001
 
92
 
 
93
 
 
94
/*
 
95
 * Determine how much space is available in the ring buffer.
 
96
 */
 
97
unsigned long rb_avail(rb_buffer_t *buffer);
 
98
 
 
99
 
 
100
#define MODE_PIPE_ALLOCED(d) \
 
101
        ((igd_display_pipe_t *)((igd_display_context_t *)d)->pipe)
 
102
 
 
103
extern igd_command_t *rb_slow_reserve(rb_buffer_t *buffer,
 
104
        unsigned long size,
 
105
        unsigned long flags);
 
106
/*
 
107
 * For Debug do not use the inline ring functions. It makes it hard
 
108
 * to add breakpoints.
 
109
 */
 
110
#ifdef DEBUG_BUILD_TYPE
 
111
extern igd_command_t *rb_reserve(rb_buffer_t *buffer,
 
112
        unsigned long size,
 
113
        unsigned long flags);
 
114
 
 
115
extern int rb_update(rb_buffer_t *buffer,
 
116
        igd_command_t *addr);
 
117
 
 
118
#else
 
119
#ifdef CONFIG_CMD
 
120
static __inline igd_command_t *rb_reserve(rb_buffer_t *buffer,
 
121
        unsigned long size,
 
122
        unsigned long flags)
 
123
{
 
124
        if (buffer->state == CMD_CONTROL_OFF) {
 
125
                /* ring buffer is turned off, so don't allow a rb_reserve() */
 
126
                buffer->context_ptr->igd_device_error_no = -IGD_ERROR_PWRDOWN;
 
127
                return(NULL);
 
128
        }
 
129
 
 
130
        /*
 
131
         * Change size to bytes for efficiency.
 
132
         */
 
133
        size = ((size<<2) + 7) & ~7;
 
134
 
 
135
        if(buffer->reservation) {
 
136
                buffer->avail += buffer->reservation;
 
137
        }
 
138
        buffer->reservation = size;
 
139
 
 
140
        if(buffer->avail > size) {
 
141
                buffer->avail -= size;
 
142
                return (igd_command_t *)(buffer->virt + buffer->tail_off);
 
143
        }
 
144
 
 
145
        return rb_slow_reserve(buffer, size, flags);
 
146
}
 
147
 
 
148
 
 
149
static __inline int rb_update(rb_buffer_t *buffer,
 
150
        igd_command_t *addr)
 
151
{
 
152
        unsigned long tail_off;
 
153
/*      tail_off = (addr - buffer->virt); */
 
154
        tail_off = (unsigned long)((unsigned char *)(addr) - buffer->virt);
 
155
 
 
156
        buffer->reservation = 0;
 
157
        buffer->tail_off = tail_off;
 
158
 
 
159
        if(buffer->tail_off & 0x7) {
 
160
                EMGD_WRITE32(0, buffer->virt + buffer->tail_off);
 
161
                buffer->tail_off += 4;
 
162
                buffer->avail -= 4;
 
163
        }
 
164
 
 
165
        EMGD_WRITE32(buffer->tail_off, buffer->tail);
 
166
 
 
167
        return 0;
 
168
}
 
169
#else
 
170
static __inline igd_command_t *rb_reserve(rb_buffer_t *buffer,
 
171
        unsigned long size,
 
172
        unsigned long flags)
 
173
{
 
174
        return NULL;
 
175
}
 
176
 
 
177
static __inline int rb_update(rb_buffer_t *buffer,
 
178
        igd_command_t *addr)
 
179
{
 
180
        return 0;
 
181
}
 
182
#endif /* CONFIG_CMD */
 
183
#endif
 
184
 
 
185
#endif /* _RB_H */
 
186
 
 
187
/*----------------------------------------------------------------------------
 
188
 * File Revision History
 
189
 * $Id: rb.h,v 1.8 2011/02/16 17:04:48 astead Exp $
 
190
 * $Source: /nfs/fm/proj/eia/cvsroot/koheo/linux/egd_drm/emgd/include/rb.h,v $
 
191
 *----------------------------------------------------------------------------
 
192
 */