drm/sman: rip out owner tracking
[deliverable/linux.git] / include / drm / drm_sman.h
CommitLineData
3a1bd924
TH
1/**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * 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 NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 *
27 **************************************************************************/
28/*
29 * Simple memory MANager interface that keeps track on allocate regions on a
30 * per "owner" basis. All regions associated with an "owner" can be released
31 * with a simple call. Typically if the "owner" exists. The owner is any
32 * "unsigned long" identifier. Can typically be a pointer to a file private
33 * struct or a context identifier.
34 *
35 * Authors:
96de0e25 36 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
3a1bd924
TH
37 */
38
39#ifndef DRM_SMAN_H
40#define DRM_SMAN_H
41
42#include "drmP.h"
43#include "drm_hashtab.h"
44
45/*
46 * A class that is an abstration of a simple memory allocator.
47 * The sman implementation provides a default such allocator
48 * using the drm_mm.c implementation. But the user can replace it.
49 * See the SiS implementation, which may use the SiS FB kernel module
50 * for memory management.
51 */
52
9698b4db 53struct drm_sman_mm {
3a1bd924
TH
54 /* private info. If allocated, needs to be destroyed by the destroy
55 function */
56 void *private;
57
58 /* Allocate a memory block with given size and alignment.
59 Return an opaque reference to the memory block */
60
61 void *(*allocate) (void *private, unsigned long size,
62 unsigned alignment);
63
64 /* Free a memory block. "ref" is the opaque reference that we got from
65 the "alloc" function */
66
67 void (*free) (void *private, void *ref);
68
69 /* Free all resources associated with this allocator */
70
71 void (*destroy) (void *private);
72
73 /* Return a memory offset from the opaque reference returned from the
74 "alloc" function */
75
76 unsigned long (*offset) (void *private, void *ref);
9698b4db 77};
3a1bd924 78
9698b4db 79struct drm_memblock_item {
3a1bd924 80 struct list_head owner_list;
e0be428e 81 struct drm_hash_item user_hash;
3a1bd924 82 void *mm_info;
9698b4db 83 struct drm_sman_mm *mm;
3a1bd924 84 struct drm_sman *sman;
9698b4db 85};
3a1bd924 86
9698b4db
DA
87struct drm_sman {
88 struct drm_sman_mm *mm;
3a1bd924 89 int num_managers;
e0be428e 90 struct drm_open_hash user_hash_tab;
9698b4db 91};
3a1bd924
TH
92
93/*
94 * Take down a memory manager. This function should only be called after a
95 * successful init and after a call to drm_sman_cleanup.
96 */
97
9698b4db 98extern void drm_sman_takedown(struct drm_sman * sman);
3a1bd924
TH
99
100/*
101 * Allocate structures for a manager.
102 * num_managers are the number of memory pools to manage. (VRAM, AGP, ....)
103 * user_order is the log2 of the number of buckets in the user hash table.
104 * set this to approximately log2 of the max number of memory regions
105 * that will be allocated for _all_ pools together.
106 * owner_order is the log2 of the number of buckets in the owner hash table.
107 * set this to approximately log2 of
108 * the number of client file connections that will
109 * be using the manager.
110 *
111 */
112
9698b4db 113extern int drm_sman_init(struct drm_sman * sman, unsigned int num_managers,
3a1bd924
TH
114 unsigned int user_order, unsigned int owner_order);
115
116/*
117 * Initialize a drm_mm.c allocator. Should be called only once for each
118 * manager unless a customized allogator is used.
119 */
120
9698b4db 121extern int drm_sman_set_range(struct drm_sman * sman, unsigned int manager,
3a1bd924
TH
122 unsigned long start, unsigned long size);
123
124/*
125 * Initialize a customized allocator for one of the managers.
126 * (See the SiS module). The object pointed to by "allocator" is copied,
127 * so it can be destroyed after this call.
128 */
129
9698b4db
DA
130extern int drm_sman_set_manager(struct drm_sman * sman, unsigned int mananger,
131 struct drm_sman_mm * allocator);
3a1bd924
TH
132
133/*
134 * Allocate a memory block. Aligment is not implemented yet.
135 */
136
9698b4db
DA
137extern struct drm_memblock_item *drm_sman_alloc(struct drm_sman * sman,
138 unsigned int manager,
139 unsigned long size,
140 unsigned alignment,
141 unsigned long owner);
3a1bd924
TH
142/*
143 * Free a memory block identified by its user hash key.
144 */
145
9698b4db 146extern int drm_sman_free_key(struct drm_sman * sman, unsigned int key);
fdc0b8a6 147extern void drm_sman_free(struct drm_memblock_item *item);
3a1bd924 148
3a1bd924
TH
149/*
150 * Frees all stale memory blocks associated with the memory manager.
151 * See idling above.
152 */
153
9698b4db 154extern void drm_sman_cleanup(struct drm_sman * sman);
3a1bd924
TH
155
156#endif
This page took 0.426545 seconds and 5 git commands to generate.