Blame view

drivers/gpu/drm/drm_memory.c 4.73 KB
b5e89ed53   Dave Airlie   drm: lindent the ...
1
2
  /**
   * \file drm_memory.c
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
5
6
7
   * Memory management wrappers for DRM
   *
   * \author Rickard E. (Rik) Faith <faith@valinux.com>
   * \author Gareth Hughes <gareth@valinux.com>
   */
b5e89ed53   Dave Airlie   drm: lindent the ...
8
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
   * Created: Thu Feb  4 14:00:34 1999 by faith@valinux.com
   *
   * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
   * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
   * All Rights Reserved.
   *
   * Permission is hereby granted, free of charge, to any person obtaining a
   * copy of this software and associated documentation files (the "Software"),
   * to deal in the Software without restriction, including without limitation
   * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   * and/or sell copies of the Software, and to permit persons to whom the
   * Software is furnished to do so, subject to the following conditions:
   *
   * The above copyright notice and this permission notice (including the next
   * paragraph) shall be included in all copies or substantial portions of the
   * Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
   * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
   * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
   * OTHER DEALINGS IN THE SOFTWARE.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34
  #include <linux/highmem.h>
2d1a8a48a   Paul Gortmaker   gpu: Add export.h...
35
  #include <linux/export.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
  #include "drmP.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
  /**
   * Called when "/proc/dri/%dev%/mem" is read.
b5e89ed53   Dave Airlie   drm: lindent the ...
39
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
42
43
44
45
46
47
   * \param buf output buffer.
   * \param start start of output data.
   * \param offset requested start offset.
   * \param len requested number of bytes.
   * \param eof whether there is no more data to return.
   * \param data private data.
   * \return number of written bytes.
   *
b5e89ed53   Dave Airlie   drm: lindent the ...
48
   * No-op.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
50
   */
  int drm_mem_info(char *buf, char **start, off_t offset,
b5e89ed53   Dave Airlie   drm: lindent the ...
51
  		 int len, int *eof, void *data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
53
54
  {
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
  #if __OS_HAS_AGP
031de96af   Adrian Bunk   drivers/char/drm/...
56
  static void *agp_remap(unsigned long offset, unsigned long size,
84b1fd103   Dave Airlie   drm: remove drm_f...
57
  		       struct drm_device * dev)
31f64bd10   Dave Airlie   drm: deline a few...
58
  {
07613ba2f   Dave Airlie   agp: switch AGP t...
59
  	unsigned long i, num_pages =
31f64bd10   Dave Airlie   drm: deline a few...
60
61
62
  	    PAGE_ALIGN(size) / PAGE_SIZE;
  	struct drm_agp_mem *agpmem;
  	struct page **page_map;
07613ba2f   Dave Airlie   agp: switch AGP t...
63
  	struct page **phys_page_map;
31f64bd10   Dave Airlie   drm: deline a few...
64
65
66
67
68
69
70
  	void *addr;
  
  	size = PAGE_ALIGN(size);
  
  #ifdef __alpha__
  	offset -= dev->hose->mem_space->start;
  #endif
bd1b331fa   Dave Airlie   drm: cleanup use ...
71
  	list_for_each_entry(agpmem, &dev->agp->memory, head)
31f64bd10   Dave Airlie   drm: deline a few...
72
73
74
75
  		if (agpmem->bound <= offset
  		    && (agpmem->bound + (agpmem->pages << PAGE_SHIFT)) >=
  		    (offset + size))
  			break;
404b017d0   Dan Carpenter   drivers/gpu/drm/d...
76
  	if (&agpmem->head == &dev->agp->memory)
31f64bd10   Dave Airlie   drm: deline a few...
77
78
79
80
81
82
83
84
85
86
87
  		return NULL;
  
  	/*
  	 * OK, we're mapping AGP space on a chipset/platform on which memory accesses by
  	 * the CPU do not get remapped by the GART.  We fix this by using the kernel's
  	 * page-table instead (that's probably faster anyhow...).
  	 */
  	/* note: use vmalloc() because num_pages could be large... */
  	page_map = vmalloc(num_pages * sizeof(struct page *));
  	if (!page_map)
  		return NULL;
07613ba2f   Dave Airlie   agp: switch AGP t...
88
  	phys_page_map = (agpmem->memory->pages + (offset - agpmem->bound) / PAGE_SIZE);
31f64bd10   Dave Airlie   drm: deline a few...
89
  	for (i = 0; i < num_pages; ++i)
07613ba2f   Dave Airlie   agp: switch AGP t...
90
  		page_map[i] = phys_page_map[i];
31f64bd10   Dave Airlie   drm: deline a few...
91
92
93
94
95
  	addr = vmap(page_map, num_pages, VM_IOREMAP, PAGE_AGP);
  	vfree(page_map);
  
  	return addr;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
  /** Wrapper around agp_free_memory() */
690bb51b5   Daniel Vetter   drm: drop return ...
97
  void drm_free_agp(DRM_AGP_MEM * handle, int pages)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
  {
89c372647   Daniel Vetter   drm: kill agp ind...
99
  	agp_free_memory(handle);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
  }
673a394b1   Eric Anholt   drm: Add GEM ("gr...
101
  EXPORT_SYMBOL(drm_free_agp);
b5e89ed53   Dave Airlie   drm: lindent the ...
102

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
  /** Wrapper around agp_bind_memory() */
b5e89ed53   Dave Airlie   drm: lindent the ...
104
  int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105
  {
89c372647   Daniel Vetter   drm: kill agp ind...
106
  	return agp_bind_memory(handle, start);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107
  }
b5e89ed53   Dave Airlie   drm: lindent the ...
108

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
  /** Wrapper around agp_unbind_memory() */
b5e89ed53   Dave Airlie   drm: lindent the ...
110
  int drm_unbind_agp(DRM_AGP_MEM * handle)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
  {
89c372647   Daniel Vetter   drm: kill agp ind...
112
  	return agp_unbind_memory(handle);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
113
  }
673a394b1   Eric Anholt   drm: Add GEM ("gr...
114
  EXPORT_SYMBOL(drm_unbind_agp);
031de96af   Adrian Bunk   drivers/char/drm/...
115
116
  
  #else  /*  __OS_HAS_AGP  */
031de96af   Adrian Bunk   drivers/char/drm/...
117
  static inline void *agp_remap(unsigned long offset, unsigned long size,
84b1fd103   Dave Airlie   drm: remove drm_f...
118
  			      struct drm_device * dev)
031de96af   Adrian Bunk   drivers/char/drm/...
119
120
121
  {
  	return NULL;
  }
b5e89ed53   Dave Airlie   drm: lindent the ...
122
  #endif				/* agp */
31f64bd10   Dave Airlie   drm: deline a few...
123

f77d390c9   Benjamin Herrenschmidt   drm: Split drm_ma...
124
  void drm_core_ioremap(struct drm_local_map *map, struct drm_device *dev)
31f64bd10   Dave Airlie   drm: deline a few...
125
  {
004a77274   Christoph Hellwig   drm: remove drm_i...
126
127
128
129
130
  	if (drm_core_has_AGP(dev) &&
  	    dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
  		map->handle = agp_remap(map->offset, map->size, dev);
  	else
  		map->handle = ioremap(map->offset, map->size);
31f64bd10   Dave Airlie   drm: deline a few...
131
  }
004a77274   Christoph Hellwig   drm: remove drm_i...
132
  EXPORT_SYMBOL(drm_core_ioremap);
31f64bd10   Dave Airlie   drm: deline a few...
133

f77d390c9   Benjamin Herrenschmidt   drm: Split drm_ma...
134
  void drm_core_ioremap_wc(struct drm_local_map *map, struct drm_device *dev)
242e3df80   Dave Airlie   drm/radeon: fixup...
135
  {
9b8d5a124   Dave Airlie   drm/radeon: fix i...
136
137
138
139
140
  	if (drm_core_has_AGP(dev) &&
  	    dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
  		map->handle = agp_remap(map->offset, map->size, dev);
  	else
  		map->handle = ioremap_wc(map->offset, map->size);
242e3df80   Dave Airlie   drm/radeon: fixup...
141
142
  }
  EXPORT_SYMBOL(drm_core_ioremap_wc);
9b8d5a124   Dave Airlie   drm/radeon: fix i...
143

f77d390c9   Benjamin Herrenschmidt   drm: Split drm_ma...
144
  void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev)
31f64bd10   Dave Airlie   drm: deline a few...
145
  {
004a77274   Christoph Hellwig   drm: remove drm_i...
146
147
148
149
150
151
152
153
  	if (!map->handle || !map->size)
  		return;
  
  	if (drm_core_has_AGP(dev) &&
  	    dev->agp && dev->agp->cant_use_aperture && map->type == _DRM_AGP)
  		vunmap(map->handle);
  	else
  		iounmap(map->handle);
31f64bd10   Dave Airlie   drm: deline a few...
154
  }
004a77274   Christoph Hellwig   drm: remove drm_i...
155
  EXPORT_SYMBOL(drm_core_ioremapfree);