Linux Kernel
3.7.1
Main Page
Related Pages
Modules
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
include
drm
ttm
ttm_bo_driver.h
Go to the documentation of this file.
1
/**************************************************************************
2
*
3
* Copyright (c) 2006-2009 Vmware, Inc., Palo Alto, CA., 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
* Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29
*/
30
#ifndef _TTM_BO_DRIVER_H_
31
#define _TTM_BO_DRIVER_H_
32
33
#include <
ttm/ttm_bo_api.h
>
34
#include <
ttm/ttm_memory.h
>
35
#include <
ttm/ttm_module.h
>
36
#include <
drm/drm_mm.h
>
37
#include <
drm/drm_global.h
>
38
#include <
linux/workqueue.h
>
39
#include <linux/fs.h>
40
#include <
linux/spinlock.h
>
41
42
struct
ttm_backend_func
{
54
int
(*
bind
) (
struct
ttm_tt
*ttm,
struct
ttm_mem_reg
*bo_mem);
55
64
int
(*
unbind
) (
struct
ttm_tt
*ttm);
65
74
void
(*
destroy
) (
struct
ttm_tt
*ttm);
75
};
76
77
#define TTM_PAGE_FLAG_WRITE (1 << 3)
78
#define TTM_PAGE_FLAG_SWAPPED (1 << 4)
79
#define TTM_PAGE_FLAG_PERSISTENT_SWAP (1 << 5)
80
#define TTM_PAGE_FLAG_ZERO_ALLOC (1 << 6)
81
#define TTM_PAGE_FLAG_DMA32 (1 << 7)
82
#define TTM_PAGE_FLAG_SG (1 << 8)
83
84
enum
ttm_caching_state
{
85
tt_uncached
,
86
tt_wc
,
87
tt_cached
88
};
89
111
struct
ttm_tt
{
112
struct
ttm_bo_device
*
bdev
;
113
struct
ttm_backend_func
*
func
;
114
struct
page
*
dummy_read_page
;
115
struct
page
**
pages
;
116
uint32_t
page_flags
;
117
unsigned
long
num_pages
;
118
struct
sg_table
*
sg
;
/* for SG objects via dma-buf */
119
struct
ttm_bo_global
*
glob
;
120
struct
file
*
swap_storage
;
121
enum
ttm_caching_state
caching_state
;
122
enum
{
123
tt_bound
,
124
tt_unbound
,
125
tt_unpopulated
,
126
}
state
;
127
};
128
140
struct
ttm_dma_tt
{
141
struct
ttm_tt
ttm
;
142
dma_addr_t
*
dma_address
;
143
struct
list_head
pages_list
;
144
};
145
146
#define TTM_MEMTYPE_FLAG_FIXED (1 << 0)
/* Fixed (on-card) PCI memory */
147
#define TTM_MEMTYPE_FLAG_MAPPABLE (1 << 1)
/* Memory mappable */
148
#define TTM_MEMTYPE_FLAG_CMA (1 << 3)
/* Can't map aperture */
149
150
struct
ttm_mem_type_manager
;
151
152
struct
ttm_mem_type_manager_func
{
164
int
(*
init
)(
struct
ttm_mem_type_manager
*man,
unsigned
long
p_size);
165
174
int
(*
takedown
)(
struct
ttm_mem_type_manager
*man);
175
203
int
(*
get_node
)(
struct
ttm_mem_type_manager
*man,
204
struct
ttm_buffer_object
*bo,
205
struct
ttm_placement
*
placement
,
206
struct
ttm_mem_reg
*
mem
);
207
218
void
(*
put_node
)(
struct
ttm_mem_type_manager
*man,
219
struct
ttm_mem_reg
*
mem
);
220
231
void
(*
debug
)(
struct
ttm_mem_type_manager
*man,
const
char
*
prefix
);
232
};
233
264
struct
ttm_mem_type_manager
{
265
struct
ttm_bo_device
*
bdev
;
266
267
/*
268
* No protection. Constant from start.
269
*/
270
271
bool
has_type
;
272
bool
use_type
;
273
uint32_t
flags
;
274
unsigned
long
gpu_offset
;
275
uint64_t
size
;
276
uint32_t
available_caching
;
277
uint32_t
default_caching
;
278
const
struct
ttm_mem_type_manager_func
*
func
;
279
void
*
priv
;
280
struct
mutex
io_reserve_mutex
;
281
bool
use_io_reserve_lru
;
282
bool
io_reserve_fastpath
;
283
284
/*
285
* Protected by @io_reserve_mutex:
286
*/
287
288
struct
list_head
io_reserve_lru
;
289
290
/*
291
* Protected by the global->lru_lock.
292
*/
293
294
struct
list_head
lru
;
295
};
296
316
struct
ttm_bo_driver
{
330
struct
ttm_tt
*(*ttm_tt_create)(
struct
ttm_bo_device
*bdev,
331
unsigned
long
size
,
332
uint32_t
page_flags,
333
struct
page
*dummy_read_page);
334
344
int
(*
ttm_tt_populate
)(
struct
ttm_tt
*ttm);
345
353
void
(*
ttm_tt_unpopulate
)(
struct
ttm_tt
*ttm);
354
367
int
(*
invalidate_caches
) (
struct
ttm_bo_device
*bdev,
uint32_t
flags
);
368
int
(*
init_mem_type
) (
struct
ttm_bo_device
*bdev,
uint32_t
type
,
369
struct
ttm_mem_type_manager
*man);
380
void
(*
evict_flags
) (
struct
ttm_buffer_object
*bo,
381
struct
ttm_placement
*
placement
);
395
int
(*
move
) (
struct
ttm_buffer_object
*bo,
396
bool
evict,
bool
interruptible,
397
bool
no_wait_reserve,
bool
no_wait_gpu,
398
struct
ttm_mem_reg
*new_mem);
399
412
int
(*
verify_access
) (
struct
ttm_buffer_object
*bo,
413
struct
file
*filp);
414
425
bool
(*
sync_obj_signaled
) (
void
*sync_obj,
void
*sync_arg);
426
int
(*
sync_obj_wait
) (
void
*sync_obj,
void
*sync_arg,
427
bool
lazy,
bool
interruptible);
428
int
(*
sync_obj_flush
) (
void
*sync_obj,
void
*sync_arg);
429
void
(*
sync_obj_unref
) (
void
**sync_obj);
430
void
*(*sync_obj_ref) (
void
*sync_obj);
431
432
/* hook to notify driver about a driver move so it
433
* can do tiling things */
434
void
(*
move_notify
)(
struct
ttm_buffer_object
*bo,
435
struct
ttm_mem_reg
*new_mem);
436
/* notify the driver we are taking a fault on this BO
437
* and have reserved it */
438
int
(*
fault_reserve_notify
)(
struct
ttm_buffer_object
*bo);
439
443
void
(*
swap_notify
) (
struct
ttm_buffer_object
*bo);
444
451
int
(*
io_mem_reserve
)(
struct
ttm_bo_device
*bdev,
struct
ttm_mem_reg
*
mem
);
452
void
(*
io_mem_free
)(
struct
ttm_bo_device
*bdev,
struct
ttm_mem_reg
*
mem
);
453
};
454
459
struct
ttm_bo_global_ref
{
460
struct
drm_global_reference
ref
;
461
struct
ttm_mem_global
*
mem_glob
;
462
};
463
478
struct
ttm_bo_global
{
479
484
struct
kobject
kobj
;
485
struct
ttm_mem_global
*
mem_glob
;
486
struct
page
*
dummy_read_page
;
487
struct
ttm_mem_shrink
shrink
;
488
struct
mutex
device_list_mutex
;
489
spinlock_t
lru_lock
;
490
494
struct
list_head
device_list
;
495
499
struct
list_head
swap_lru
;
500
504
atomic_t
bo_count
;
505
};
506
507
508
#define TTM_NUM_MEM_TYPES 8
509
510
#define TTM_BO_PRIV_FLAG_MOVING 0
/* Buffer object is moving and needs
511
idling before CPU mapping */
512
#define TTM_BO_PRIV_FLAG_MAX 1
513
532
struct
ttm_bo_device
{
533
534
/*
535
* Constant after bo device init / atomic.
536
*/
537
struct
list_head
device_list
;
538
struct
ttm_bo_global
*
glob
;
539
struct
ttm_bo_driver
*
driver
;
540
rwlock_t
vm_lock
;
541
struct
ttm_mem_type_manager
man
[
TTM_NUM_MEM_TYPES
];
542
spinlock_t
fence_lock
;
543
/*
544
* Protected by the vm lock.
545
*/
546
struct
rb_root
addr_space_rb
;
547
struct
drm_mm
addr_space_mm
;
548
549
/*
550
* Protected by the global:lru lock.
551
*/
552
struct
list_head
ddestroy
;
553
uint32_t
val_seq
;
554
555
/*
556
* Protected by load / firstopen / lastclose /unload sync.
557
*/
558
559
bool
nice_mode
;
560
struct
address_space
*
dev_mapping
;
561
562
/*
563
* Internal protection.
564
*/
565
566
struct
delayed_work
wq
;
567
568
bool
need_dma32
;
569
};
570
581
static
inline
uint32_t
582
ttm_flag_masked(
uint32_t
*old,
uint32_t
new
,
uint32_t
mask
)
583
{
584
*old ^= (*old ^
new
) & mask;
585
return
*old;
586
}
587
602
extern
int
ttm_tt_init
(
struct
ttm_tt
*ttm,
struct
ttm_bo_device
*bdev,
603
unsigned
long
size
,
uint32_t
page_flags,
604
struct
page
*dummy_read_page);
605
extern
int
ttm_dma_tt_init
(
struct
ttm_dma_tt
*ttm_dma,
struct
ttm_bo_device
*bdev,
606
unsigned
long
size
,
uint32_t
page_flags,
607
struct
page
*dummy_read_page);
608
616
extern
void
ttm_tt_fini
(
struct
ttm_tt
*ttm);
617
extern
void
ttm_dma_tt_fini
(
struct
ttm_dma_tt
*ttm_dma);
618
627
extern
int
ttm_tt_bind
(
struct
ttm_tt
*ttm,
struct
ttm_mem_reg
*bo_mem);
628
636
extern
void
ttm_tt_destroy
(
struct
ttm_tt
*ttm);
637
645
extern
void
ttm_tt_unbind
(
struct
ttm_tt
*ttm);
646
654
extern
int
ttm_tt_swapin
(
struct
ttm_tt
*ttm);
655
666
extern
void
ttm_tt_cache_flush
(
struct
page
*
pages
[],
unsigned
long
num_pages
);
667
681
extern
int
ttm_tt_set_placement_caching
(
struct
ttm_tt
*ttm,
uint32_t
placement);
682
extern
int
ttm_tt_swapout
(
struct
ttm_tt
*ttm,
683
struct
file
*persistent_swap_storage);
684
685
/*
686
* ttm_bo.c
687
*/
688
698
extern
bool
ttm_mem_reg_is_pci
(
struct
ttm_bo_device
*bdev,
699
struct
ttm_mem_reg
*
mem
);
700
721
extern
int
ttm_bo_mem_space
(
struct
ttm_buffer_object
*bo,
722
struct
ttm_placement
*placement,
723
struct
ttm_mem_reg
*
mem
,
724
bool
interruptible,
725
bool
no_wait_reserve,
bool
no_wait_gpu);
726
727
extern
void
ttm_bo_mem_put
(
struct
ttm_buffer_object
*bo,
728
struct
ttm_mem_reg
*
mem
);
729
extern
void
ttm_bo_mem_put_locked
(
struct
ttm_buffer_object
*bo,
730
struct
ttm_mem_reg
*
mem
);
731
744
extern
int
ttm_bo_wait_cpu
(
struct
ttm_buffer_object
*bo,
bool
no_wait);
745
746
extern
void
ttm_bo_global_release
(
struct
drm_global_reference
*ref);
747
extern
int
ttm_bo_global_init
(
struct
drm_global_reference
*ref);
748
749
extern
int
ttm_bo_device_release
(
struct
ttm_bo_device
*bdev);
750
765
extern
int
ttm_bo_device_init
(
struct
ttm_bo_device
*bdev,
766
struct
ttm_bo_global
*glob,
767
struct
ttm_bo_driver
*
driver
,
768
uint64_t
file_page_offset,
bool
need_dma32);
769
775
extern
void
ttm_bo_unmap_virtual
(
struct
ttm_buffer_object
*bo);
776
784
extern
void
ttm_bo_unmap_virtual_locked
(
struct
ttm_buffer_object
*bo);
785
786
extern
int
ttm_mem_io_reserve_vm
(
struct
ttm_buffer_object
*bo);
787
extern
void
ttm_mem_io_free_vm
(
struct
ttm_buffer_object
*bo);
788
extern
int
ttm_mem_io_lock
(
struct
ttm_mem_type_manager
*man,
789
bool
interruptible);
790
extern
void
ttm_mem_io_unlock
(
struct
ttm_mem_type_manager
*man);
791
792
847
extern
int
ttm_bo_reserve
(
struct
ttm_buffer_object
*bo,
848
bool
interruptible,
849
bool
no_wait,
bool
use_sequence,
uint32_t
sequence
);
850
851
876
extern
int
ttm_bo_reserve_locked
(
struct
ttm_buffer_object
*bo,
877
bool
interruptible,
878
bool
no_wait,
bool
use_sequence,
879
uint32_t
sequence
);
880
888
extern
void
ttm_bo_unreserve
(
struct
ttm_buffer_object
*bo);
889
898
extern
void
ttm_bo_unreserve_locked
(
struct
ttm_buffer_object
*bo);
899
909
extern
int
ttm_bo_wait_unreserved
(
struct
ttm_buffer_object
*bo,
910
bool
interruptible);
911
912
/*
913
* ttm_bo_util.c
914
*/
915
935
extern
int
ttm_bo_move_ttm
(
struct
ttm_buffer_object
*bo,
936
bool
evict,
bool
no_wait_reserve,
937
bool
no_wait_gpu,
struct
ttm_mem_reg
*new_mem);
938
958
extern
int
ttm_bo_move_memcpy
(
struct
ttm_buffer_object
*bo,
959
bool
evict,
bool
no_wait_reserve,
960
bool
no_wait_gpu,
struct
ttm_mem_reg
*new_mem);
961
969
extern
void
ttm_bo_free_old_node
(
struct
ttm_buffer_object
*bo);
970
991
extern
int
ttm_bo_move_accel_cleanup
(
struct
ttm_buffer_object
*bo,
992
void
*sync_obj,
993
void
*sync_obj_arg,
994
bool
evict,
bool
no_wait_reserve,
995
bool
no_wait_gpu,
996
struct
ttm_mem_reg
*new_mem);
1006
extern
pgprot_t
ttm_io_prot
(
uint32_t
caching_flags,
pgprot_t
tmp
);
1007
1008
extern
const
struct
ttm_mem_type_manager_func
ttm_bo_manager_func
;
1009
1010
#if (defined(CONFIG_AGP) || (defined(CONFIG_AGP_MODULE) && defined(MODULE)))
1011
#define TTM_HAS_AGP
1012
#include <
linux/agp_backend.h
>
1013
1028
extern
struct
ttm_tt
*ttm_agp_tt_create(
struct
ttm_bo_device
*
bdev
,
1029
struct
agp_bridge_data
*bridge,
1030
unsigned
long
size
,
uint32_t
page_flags
,
1031
struct
page
*
dummy_read_page
);
1032
int
ttm_agp_tt_populate(
struct
ttm_tt
*ttm);
1033
void
ttm_agp_tt_unpopulate(
struct
ttm_tt
*ttm);
1034
#endif
1035
1036
#endif
Generated on Thu Jan 10 2013 14:51:00 for Linux Kernel by
1.8.2