Subversion Repositories Kolibri OS

Rev

Rev 4075 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1404 serge 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 
29
 */
30
/* Notes:
31
 *
32
 * We store bo pointer in drm_mm_node struct so we know which bo own a
33
 * specific node. There is no protection on the pointer, thus to make
34
 * sure things don't go berserk you have to access this pointer while
35
 * holding the global lru lock and make sure anytime you free a node you
36
 * reset the pointer to NULL.
37
 */
38
 
39
#include "ttm/ttm_module.h"
40
#include "ttm/ttm_bo_driver.h"
41
#include "ttm/ttm_placement.h"
42
#include 
43
 
44
 
45
 
46
int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
47
            unsigned long p_size)
48
{
49
    int ret = -EINVAL;
50
    struct ttm_mem_type_manager *man;
51
 
52
    if (type >= TTM_NUM_MEM_TYPES) {
53
        printk(KERN_ERR TTM_PFX "Illegal memory type %d\n", type);
54
        return ret;
55
    }
56
 
57
    man = &bdev->man[type];
58
    if (man->has_type) {
59
        printk(KERN_ERR TTM_PFX
60
               "Memory manager already initialized for type %d\n",
61
               type);
62
        return ret;
63
    }
64
 
65
    ret = bdev->driver->init_mem_type(bdev, type, man);
66
    if (ret)
67
        return ret;
68
 
69
    ret = 0;
70
    if (type != TTM_PL_SYSTEM) {
71
        if (!p_size) {
72
            printk(KERN_ERR TTM_PFX
73
                   "Zero size memory manager type %d\n",
74
                   type);
75
            return ret;
76
        }
77
        ret = drm_mm_init(&man->manager, 0, p_size);
78
        if (ret)
79
            return ret;
80
    }
81
    man->has_type = true;
82
    man->use_type = true;
83
    man->size = p_size;
84
 
85
    INIT_LIST_HEAD(&man->lru);
86
 
87
    return 0;
88
}
89
EXPORT_SYMBOL(ttm_bo_init_mm);
90
 
91
int ttm_bo_global_init(struct ttm_global_reference *ref)
92
{
93
    struct ttm_bo_global_ref *bo_ref =
94
        container_of(ref, struct ttm_bo_global_ref, ref);
95
    struct ttm_bo_global *glob = ref->object;
96
    int ret;
97
 
98
//    mutex_init(&glob->device_list_mutex);
99
//    spin_lock_init(&glob->lru_lock);
100
    glob->mem_glob = bo_ref->mem_glob;
101
//    glob->dummy_read_page = alloc_page(__GFP_ZERO | GFP_DMA32);
102
 
103
    if (unlikely(glob->dummy_read_page == NULL)) {
104
        ret = -ENOMEM;
105
        goto out_no_drp;
106
    }
107
 
108
    INIT_LIST_HEAD(&glob->swap_lru);
109
    INIT_LIST_HEAD(&glob->device_list);
110
 
111
//    ttm_mem_init_shrink(&glob->shrink, ttm_bo_swapout);
112
    ret = ttm_mem_register_shrink(glob->mem_glob, &glob->shrink);
113
    if (unlikely(ret != 0)) {
114
        printk(KERN_ERR TTM_PFX
115
               "Could not register buffer object swapout.\n");
116
        goto out_no_shrink;
117
    }
118
 
119
    glob->ttm_bo_extra_size =
120
        ttm_round_pot(sizeof(struct ttm_tt)) +
121
        ttm_round_pot(sizeof(struct ttm_backend));
122
 
123
    glob->ttm_bo_size = glob->ttm_bo_extra_size +
124
        ttm_round_pot(sizeof(struct ttm_buffer_object));
125
 
126
    atomic_set(&glob->bo_count, 0);
127
 
128
//    kobject_init(&glob->kobj, &ttm_bo_glob_kobj_type);
129
//    ret = kobject_add(&glob->kobj, ttm_get_kobj(), "buffer_objects");
130
//    if (unlikely(ret != 0))
131
//        kobject_put(&glob->kobj);
132
    return ret;
133
out_no_shrink:
134
    __free_page(glob->dummy_read_page);
135
out_no_drp:
136
    kfree(glob);
137
    return ret;
138
}
139
EXPORT_SYMBOL(ttm_bo_global_init);
140