<!doctype html>
<html>
<head>
<title>nouveau.c</title>
<style type="text/css">
body { color:#000000; background-color:#ffffff }
body { font-family:Helvetica, sans-serif; font-size:10pt }
h1 { font-size:14pt }
.code { border-collapse:collapse; width:100%; }
.code { font-family: "Monospace", monospace; font-size:10pt }
.code { line-height: 1.2em }
.comment { color: green; font-style: oblique }
.keyword { color: blue }
.string_literal { color: red }
.directive { color: darkmagenta }
.expansion { display: none; }
.macro:hover .expansion { display: block; border: 2px solid #FF0000; padding: 2px; background-color:#FFF0F0; font-weight: normal; -webkit-border-radius:5px; -webkit-box-shadow:1px 1px 7px #000; position: absolute; top: -1em; left:10em; z-index: 1 }
.macro { color: darkmagenta; background-color:LemonChiffon; position: relative }
.num { width:2.5em; padding-right:2ex; background-color:#eeeeee }
.num { text-align:right; font-size:8pt }
.num { color:#444444 }
.line { padding-left: 1ex; border-left: 3px solid #ccc }
.line { white-space: pre }
.msg { -webkit-box-shadow:1px 1px 7px #000 }
.msg { -webkit-border-radius:5px }
.msg { font-family:Helvetica, sans-serif; font-size:8pt }
.msg { float:left }
.msg { padding:0.25em 1ex 0.25em 1ex }
.msg { margin-top:10px; margin-bottom:10px }
.msg { font-weight:bold }
.msg { max-width:60em; word-wrap: break-word; white-space: pre-wrap }
.msgT { padding:0x; spacing:0x }
.msgEvent { background-color:#fff8b4; color:#000000 }
.msgControl { background-color:#bbbbbb; color:#000000 }
.mrange { background-color:#dfddf3 }
.mrange { border-bottom:1px solid #6F9DBE }
.PathIndex { font-weight: bold; padding:0px 5px 0px 5px; margin-right:5px; }
.PathIndex { -webkit-border-radius:8px }
.PathIndexEvent { background-color:#bfba87 }
.PathIndexControl { background-color:#8c8c8c }
.CodeInsertionHint { font-weight: bold; background-color: #10dd10 }
.CodeRemovalHint { background-color:#de1010 }
.CodeRemovalHint { border-bottom:1px solid #6F9DBE }
table.simpletable {
padding: 5px;
font-size:12pt;
margin:20px;
border-collapse: collapse; border-spacing: 0px;
}
td.rowname {
text-align:right; font-weight:bold; color:#444444;
padding-right:2ex; }
</style>
</head>
<body>
<!-- BUGDESC Memory is never released; potential leak of memory pointed to by 'nvdev' -->
<!-- BUGTYPE Memory leak -->
<!-- BUGCATEGORY Memory Error -->
<!-- BUGFILE /home/abuild/rpmbuild/BUILD/libdrm/nouveau/nouveau.c -->
<!-- BUGLINE 97 -->
<!-- BUGPATHLENGTH 6 -->
<!-- BUGMETAEND -->
<!-- REPORTHEADER -->
<h3>Bug Summary</h3>
<table class="simpletable">
<tr><td class="rowname">File:</td><td>nouveau/nouveau.c</td></tr>
<tr><td class="rowname">Location:</td><td><a href="#EndPath">line 97, column 23</a></td></tr>
<tr><td class="rowname">Description:</td><td>Memory is never released; potential leak of memory pointed to by 'nvdev'</td></tr>
</table>
<!-- REPORTSUMMARYEXTRA -->
<h3>Annotated Source Code</h3>
<table class="code">
<tr><td class="num" id="LN1">1</td><td class="line"><span class='comment'>/*</span></td></tr>
<tr><td class="num" id="LN2">2</td><td class="line"> <span class='comment'>* Copyright 2012 Red Hat Inc.</span></td></tr>
<tr><td class="num" id="LN3">3</td><td class="line"> <span class='comment'>*</span></td></tr>
<tr><td class="num" id="LN4">4</td><td class="line"> <span class='comment'>* Permission is hereby granted, free of charge, to any person obtaining a</span></td></tr>
<tr><td class="num" id="LN5">5</td><td class="line"> <span class='comment'>* copy of this software and associated documentation files (the "Software"),</span></td></tr>
<tr><td class="num" id="LN6">6</td><td class="line"> <span class='comment'>* to deal in the Software without restriction, including without limitation</span></td></tr>
<tr><td class="num" id="LN7">7</td><td class="line"> <span class='comment'>* the rights to use, copy, modify, merge, publish, distribute, sublicense,</span></td></tr>
<tr><td class="num" id="LN8">8</td><td class="line"> <span class='comment'>* and/or sell copies of the Software, and to permit persons to whom the</span></td></tr>
<tr><td class="num" id="LN9">9</td><td class="line"> <span class='comment'>* Software is furnished to do so, subject to the following conditions:</span></td></tr>
<tr><td class="num" id="LN10">10</td><td class="line"> <span class='comment'>*</span></td></tr>
<tr><td class="num" id="LN11">11</td><td class="line"> <span class='comment'>* The above copyright notice and this permission notice shall be included in</span></td></tr>
<tr><td class="num" id="LN12">12</td><td class="line"> <span class='comment'>* all copies or substantial portions of the Software.</span></td></tr>
<tr><td class="num" id="LN13">13</td><td class="line"> <span class='comment'>*</span></td></tr>
<tr><td class="num" id="LN14">14</td><td class="line"> <span class='comment'>* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span></td></tr>
<tr><td class="num" id="LN15">15</td><td class="line"> <span class='comment'>* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span></td></tr>
<tr><td class="num" id="LN16">16</td><td class="line"> <span class='comment'>* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</span></td></tr>
<tr><td class="num" id="LN17">17</td><td class="line"> <span class='comment'>* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR</span></td></tr>
<tr><td class="num" id="LN18">18</td><td class="line"> <span class='comment'>* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,</span></td></tr>
<tr><td class="num" id="LN19">19</td><td class="line"> <span class='comment'>* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR</span></td></tr>
<tr><td class="num" id="LN20">20</td><td class="line"> <span class='comment'>* OTHER DEALINGS IN THE SOFTWARE.</span></td></tr>
<tr><td class="num" id="LN21">21</td><td class="line"> <span class='comment'>*</span></td></tr>
<tr><td class="num" id="LN22">22</td><td class="line"> <span class='comment'>* Authors: Ben Skeggs</span></td></tr>
<tr><td class="num" id="LN23">23</td><td class="line"> <span class='comment'>*/</span></td></tr>
<tr><td class="num" id="LN24">24</td><td class="line"> </td></tr>
<tr><td class="num" id="LN25">25</td><td class="line"><span class='directive'>#ifdef <span class='macro'>HAVE_CONFIG_H<span class='expansion'>1</span></span></span></td></tr>
<tr><td class="num" id="LN26">26</td><td class="line"><span class='directive'>#include <config.h></span></td></tr>
<tr><td class="num" id="LN27">27</td><td class="line"><span class='directive'>#endif</span></td></tr>
<tr><td class="num" id="LN28">28</td><td class="line"> </td></tr>
<tr><td class="num" id="LN29">29</td><td class="line"><span class='directive'>#include <stdio.h></span></td></tr>
<tr><td class="num" id="LN30">30</td><td class="line"><span class='directive'>#include <stdlib.h></span></td></tr>
<tr><td class="num" id="LN31">31</td><td class="line"><span class='directive'>#include <stdint.h></span></td></tr>
<tr><td class="num" id="LN32">32</td><td class="line"><span class='directive'>#include <string.h></span></td></tr>
<tr><td class="num" id="LN33">33</td><td class="line"><span class='directive'>#include <stdbool.h></span></td></tr>
<tr><td class="num" id="LN34">34</td><td class="line"><span class='directive'>#include <assert.h></span></td></tr>
<tr><td class="num" id="LN35">35</td><td class="line"><span class='directive'>#include <<span class='macro'>errno<span class='expansion'>(*__errno_location ())</span></span>.h></span></td></tr>
<tr><td class="num" id="LN36">36</td><td class="line"><span class='directive'>#include <sys/mman.h></span></td></tr>
<tr><td class="num" id="LN37">37</td><td class="line"> </td></tr>
<tr><td class="num" id="LN38">38</td><td class="line"><span class='directive'>#include <xf86drm.h></span></td></tr>
<tr><td class="num" id="LN39">39</td><td class="line"><span class='directive'>#include <xf86atomic.h></span></td></tr>
<tr><td class="num" id="LN40">40</td><td class="line"><span class='directive'>#include "libdrm_lists.h"</span></td></tr>
<tr><td class="num" id="LN41">41</td><td class="line"><span class='directive'>#include "nouveau_drm.h"</span></td></tr>
<tr><td class="num" id="LN42">42</td><td class="line"> </td></tr>
<tr><td class="num" id="LN43">43</td><td class="line"><span class='directive'>#include "nouveau.h"</span></td></tr>
<tr><td class="num" id="LN44">44</td><td class="line"><span class='directive'>#include "private.h"</span></td></tr>
<tr><td class="num" id="LN45">45</td><td class="line"> </td></tr>
<tr><td class="num" id="LN46">46</td><td class="line"><span class='directive'>#ifdef <span class='macro'>DEBUG<span class='expansion'>1</span></span></span></td></tr>
<tr><td class="num" id="LN47">47</td><td class="line">uint32_t nouveau_debug = 0;</td></tr>
<tr><td class="num" id="LN48">48</td><td class="line"> </td></tr>
<tr><td class="num" id="LN49">49</td><td class="line"><span class='keyword'>static</span> <span class='keyword'>void</span></td></tr>
<tr><td class="num" id="LN50">50</td><td class="line">debug_init(<span class='keyword'>char</span> *args)</td></tr>
<tr><td class="num" id="LN51">51</td><td class="line">{</td></tr>
<tr><td class="num" id="LN52">52</td><td class="line"> <span class='keyword'>if</span> (args) {</td></tr>
<tr><td class="num" id="LN53">53</td><td class="line"> <span class='keyword'>int</span> n = strtol(args, <span class='macro'>NULL<span class='expansion'>((void *)0)</span></span>, 0);</td></tr>
<tr><td class="num" id="LN54">54</td><td class="line"> <span class='keyword'>if</span> (n >= 0)</td></tr>
<tr><td class="num" id="LN55">55</td><td class="line"> nouveau_debug = n;</td></tr>
<tr><td class="num" id="LN56">56</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN57">57</td><td class="line">}</td></tr>
<tr><td class="num" id="LN58">58</td><td class="line"><span class='directive'>#endif</span></td></tr>
<tr><td class="num" id="LN59">59</td><td class="line"> </td></tr>
<tr><td class="num" id="LN60">60</td><td class="line"><span class='comment'>/* this is the old libdrm's version of nouveau_device_wrap(), the symbol</span></td></tr>
<tr><td class="num" id="LN61">61</td><td class="line"> <span class='comment'>* is kept here to prevent AIGLX from crashing if the DDX is linked against</span></td></tr>
<tr><td class="num" id="LN62">62</td><td class="line"> <span class='comment'>* the new libdrm, but the DRI driver against the old</span></td></tr>
<tr><td class="num" id="LN63">63</td><td class="line"> <span class='comment'>*/</span></td></tr>
<tr><td class="num" id="LN64">64</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN65">65</td><td class="line">nouveau_device_open_existing(<span class='keyword'>struct</span> nouveau_device **pdev, <span class='keyword'>int</span> close, <span class='keyword'>int</span> fd,</td></tr>
<tr><td class="num" id="LN66">66</td><td class="line"> drm_context_t ctx)</td></tr>
<tr><td class="num" id="LN67">67</td><td class="line">{</td></tr>
<tr><td class="num" id="LN68">68</td><td class="line"> <span class='keyword'>return</span> -<span class='macro'>EACCES<span class='expansion'>13</span></span>;</td></tr>
<tr><td class="num" id="LN69">69</td><td class="line">}</td></tr>
<tr><td class="num" id="LN70">70</td><td class="line"> </td></tr>
<tr><td class="num" id="LN71">71</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN72">72</td><td class="line">nouveau_device_wrap(<span class='keyword'>int</span> fd, <span class='keyword'>int</span> close, <span class='keyword'>struct</span> nouveau_device **pdev)</td></tr>
<tr><td class="num" id="LN73">73</td><td class="line">{</td></tr>
<tr><td class="num" id="LN74">74</td><td class="line"> <span class='keyword'>struct</span> nouveau_device_priv *nvdev = <span class="mrange">calloc(1, <span class='keyword'>sizeof</span>(*nvdev))</span>;</td></tr>
<tr><td class="num"></td><td class="line"><div id="Path1" class="msg msgEvent" style="margin-left:45ex"><table class="msgT"><tr><td valign="top"><div class="PathIndex PathIndexEvent">1</div></td><td>Memory is allocated</td></tr></table></div></td></tr>
<tr><td class="num" id="LN75">75</td><td class="line"> <span class='keyword'>struct</span> nouveau_device *dev = &nvdev->base;</td></tr>
<tr><td class="num" id="LN76">76</td><td class="line"> uint64_t chipset, vram, gart, bousage;</td></tr>
<tr><td class="num" id="LN77">77</td><td class="line"> drmVersionPtr ver;</td></tr>
<tr><td class="num" id="LN78">78</td><td class="line"> <span class='keyword'>int</span> ret;</td></tr>
<tr><td class="num" id="LN79">79</td><td class="line"> </td></tr>
<tr><td class="num" id="LN80">80</td><td class="line"><span class='directive'>#ifdef <span class='macro'>DEBUG<span class='expansion'>1</span></span></span></td></tr>
<tr><td class="num" id="LN81">81</td><td class="line"> debug_init(getenv(<span class='string_literal'>"NOUVEAU_LIBDRM_DEBUG"</span>));</td></tr>
<tr><td class="num" id="LN82">82</td><td class="line"><span class='directive'>#endif</span></td></tr>
<tr><td class="num" id="LN83">83</td><td class="line"> </td></tr>
<tr><td class="num" id="LN84">84</td><td class="line"> <span class='keyword'>if</span> (<span class="mrange">!nvdev</span>)</td></tr>
<tr><td class="num"></td><td class="line"><div id="Path2" class="msg msgEvent" style="margin-left:13ex"><table class="msgT"><tr><td valign="top"><div class="PathIndex PathIndexEvent">2</div></td><td>Assuming 'nvdev' is non-null</td></tr></table></div></td></tr>
<tr><td class="num"></td><td class="line"><div id="Path3" class="msg msgControl" style="margin-left:9ex"><table class="msgT"><tr><td valign="top"><div class="PathIndex PathIndexControl">3</div></td><td>Taking false branch</td></tr></table></div></td></tr>
<tr><td class="num" id="LN85">85</td><td class="line"> <span class='keyword'>return</span> -<span class='macro'>ENOMEM<span class='expansion'>12</span></span>;</td></tr>
<tr><td class="num" id="LN86">86</td><td class="line"> nvdev->base.fd = fd;</td></tr>
<tr><td class="num" id="LN87">87</td><td class="line"> </td></tr>
<tr><td class="num" id="LN88">88</td><td class="line"> ver = drmGetVersion(fd);</td></tr>
<tr><td class="num" id="LN89">89</td><td class="line"> <span class='keyword'>if</span> (ver) dev->drm_version = (ver->version_major << 24) |</td></tr>
<tr><td class="num"></td><td class="line"><div id="Path4" class="msg msgControl" style="margin-left:9ex"><table class="msgT"><tr><td valign="top"><div class="PathIndex PathIndexControl">4</div></td><td>Taking false branch</td></tr></table></div></td></tr>
<tr><td class="num" id="LN90">90</td><td class="line"> (ver->version_minor << 8) |</td></tr>
<tr><td class="num" id="LN91">91</td><td class="line"> ver->version_patchlevel;</td></tr>
<tr><td class="num" id="LN92">92</td><td class="line"> drmFreeVersion(ver);</td></tr>
<tr><td class="num" id="LN93">93</td><td class="line"> </td></tr>
<tr><td class="num" id="LN94">94</td><td class="line"> <span class='keyword'>if</span> ( dev->drm_version != 0x00000010 &&</td></tr>
<tr><td class="num"></td><td class="line"><div id="Path5" class="msg msgControl" style="margin-left:9ex"><table class="msgT"><tr><td valign="top"><div class="PathIndex PathIndexControl">5</div></td><td>Taking true branch</td></tr></table></div></td></tr>
<tr><td class="num" id="LN95">95</td><td class="line"> (dev->drm_version < 0x01000000 ||</td></tr>
<tr><td class="num" id="LN96">96</td><td class="line"> dev->drm_version >= 0x02000000)) {</td></tr>
<tr><td class="num" id="LN97">97</td><td class="line"> nouveau_device_del(&dev);</td></tr>
<tr><td class="num"></td><td class="line"><div id="EndPath" class="msg msgEvent" style="margin-left:37ex"><table class="msgT"><tr><td valign="top"><div class="PathIndex PathIndexEvent">6</div></td><td>Memory is never released; potential leak of memory pointed to by 'nvdev'</td></tr></table></div></td></tr>
<tr><td class="num" id="LN98">98</td><td class="line"> <span class='keyword'>return</span> -<span class='macro'>EINVAL<span class='expansion'>22</span></span>;</td></tr>
<tr><td class="num" id="LN99">99</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN100">100</td><td class="line"> </td></tr>
<tr><td class="num" id="LN101">101</td><td class="line"> ret = nouveau_getparam(dev, <span class='macro'>NOUVEAU_GETPARAM_CHIPSET_ID<span class='expansion'>11</span></span>, &chipset);</td></tr>
<tr><td class="num" id="LN102">102</td><td class="line"> <span class='keyword'>if</span> (ret == 0)</td></tr>
<tr><td class="num" id="LN103">103</td><td class="line"> ret = nouveau_getparam(dev, <span class='macro'>NOUVEAU_GETPARAM_FB_SIZE<span class='expansion'>8</span></span>, &vram);</td></tr>
<tr><td class="num" id="LN104">104</td><td class="line"> <span class='keyword'>if</span> (ret == 0)</td></tr>
<tr><td class="num" id="LN105">105</td><td class="line"> ret = nouveau_getparam(dev, <span class='macro'>NOUVEAU_GETPARAM_AGP_SIZE<span class='expansion'>9</span></span>, &gart);</td></tr>
<tr><td class="num" id="LN106">106</td><td class="line"> <span class='keyword'>if</span> (ret) {</td></tr>
<tr><td class="num" id="LN107">107</td><td class="line"> nouveau_device_del(&dev);</td></tr>
<tr><td class="num" id="LN108">108</td><td class="line"> <span class='keyword'>return</span> ret;</td></tr>
<tr><td class="num" id="LN109">109</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN110">110</td><td class="line"> </td></tr>
<tr><td class="num" id="LN111">111</td><td class="line"> ret = nouveau_getparam(dev, <span class='macro'>NOUVEAU_GETPARAM_HAS_BO_USAGE<span class='expansion'>15</span></span>, &bousage);</td></tr>
<tr><td class="num" id="LN112">112</td><td class="line"> <span class='keyword'>if</span> (ret == 0)</td></tr>
<tr><td class="num" id="LN113">113</td><td class="line"> nvdev->have_bo_usage = (bousage != 0);</td></tr>
<tr><td class="num" id="LN114">114</td><td class="line"> </td></tr>
<tr><td class="num" id="LN115">115</td><td class="line"> nvdev->close = close;</td></tr>
<tr><td class="num" id="LN116">116</td><td class="line"> <span class='macro'>DRMINITLISTHEAD(&nvdev->bo_list)<span class='expansion'>do{ (&nvdev->bo_list)->prev = (&nvdev->bo_list<br>); (&nvdev->bo_list)->next = (&nvdev->bo_list<br>); } while (0)</span></span>;</td></tr>
<tr><td class="num" id="LN117">117</td><td class="line"> nvdev->base.object.oclass = <span class='macro'>NOUVEAU_DEVICE_CLASS<span class='expansion'>0x80000000</span></span>;</td></tr>
<tr><td class="num" id="LN118">118</td><td class="line"> nvdev->base.lib_version = 0x01000000;</td></tr>
<tr><td class="num" id="LN119">119</td><td class="line"> nvdev->base.chipset = chipset;</td></tr>
<tr><td class="num" id="LN120">120</td><td class="line"> nvdev->base.vram_size = vram;</td></tr>
<tr><td class="num" id="LN121">121</td><td class="line"> nvdev->base.gart_size = gart;</td></tr>
<tr><td class="num" id="LN122">122</td><td class="line"> nvdev->base.vram_limit = (nvdev->base.vram_size * 80) / 100;</td></tr>
<tr><td class="num" id="LN123">123</td><td class="line"> nvdev->base.gart_limit = (nvdev->base.gart_size * 80) / 100;</td></tr>
<tr><td class="num" id="LN124">124</td><td class="line"> </td></tr>
<tr><td class="num" id="LN125">125</td><td class="line"> *pdev = &nvdev->base;</td></tr>
<tr><td class="num" id="LN126">126</td><td class="line"> <span class='keyword'>return</span> 0;</td></tr>
<tr><td class="num" id="LN127">127</td><td class="line">}</td></tr>
<tr><td class="num" id="LN128">128</td><td class="line"> </td></tr>
<tr><td class="num" id="LN129">129</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN130">130</td><td class="line">nouveau_device_open(<span class='keyword'>const</span> <span class='keyword'>char</span> *busid, <span class='keyword'>struct</span> nouveau_device **pdev)</td></tr>
<tr><td class="num" id="LN131">131</td><td class="line">{</td></tr>
<tr><td class="num" id="LN132">132</td><td class="line"> <span class='keyword'>int</span> ret = -<span class='macro'>ENODEV<span class='expansion'>19</span></span>, fd = drmOpen(<span class='string_literal'>"nouveau"</span>, busid);</td></tr>
<tr><td class="num" id="LN133">133</td><td class="line"> <span class='keyword'>if</span> (fd >= 0) {</td></tr>
<tr><td class="num" id="LN134">134</td><td class="line"> ret = nouveau_device_wrap(fd, 1, pdev);</td></tr>
<tr><td class="num" id="LN135">135</td><td class="line"> <span class='keyword'>if</span> (ret)</td></tr>
<tr><td class="num" id="LN136">136</td><td class="line"> drmClose(fd);</td></tr>
<tr><td class="num" id="LN137">137</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN138">138</td><td class="line"> <span class='keyword'>return</span> ret;</td></tr>
<tr><td class="num" id="LN139">139</td><td class="line">}</td></tr>
<tr><td class="num" id="LN140">140</td><td class="line"> </td></tr>
<tr><td class="num" id="LN141">141</td><td class="line"><span class='keyword'>void</span></td></tr>
<tr><td class="num" id="LN142">142</td><td class="line">nouveau_device_del(<span class='keyword'>struct</span> nouveau_device **pdev)</td></tr>
<tr><td class="num" id="LN143">143</td><td class="line">{</td></tr>
<tr><td class="num" id="LN144">144</td><td class="line"> <span class='keyword'>struct</span> nouveau_device_priv *nvdev = nouveau_device(*pdev);</td></tr>
<tr><td class="num" id="LN145">145</td><td class="line"> <span class='keyword'>if</span> (nvdev) {</td></tr>
<tr><td class="num" id="LN146">146</td><td class="line"> <span class='keyword'>if</span> (nvdev->close)</td></tr>
<tr><td class="num" id="LN147">147</td><td class="line"> drmClose(nvdev->base.fd);</td></tr>
<tr><td class="num" id="LN148">148</td><td class="line"> free(nvdev->client);</td></tr>
<tr><td class="num" id="LN149">149</td><td class="line"> free(nvdev);</td></tr>
<tr><td class="num" id="LN150">150</td><td class="line"> *pdev = <span class='macro'>NULL<span class='expansion'>((void *)0)</span></span>;</td></tr>
<tr><td class="num" id="LN151">151</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN152">152</td><td class="line">}</td></tr>
<tr><td class="num" id="LN153">153</td><td class="line"> </td></tr>
<tr><td class="num" id="LN154">154</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN155">155</td><td class="line">nouveau_getparam(<span class='keyword'>struct</span> nouveau_device *dev, uint64_t param, uint64_t *value)</td></tr>
<tr><td class="num" id="LN156">156</td><td class="line">{</td></tr>
<tr><td class="num" id="LN157">157</td><td class="line"> <span class='keyword'>struct</span> drm_nouveau_getparam r = { param, 0 };</td></tr>
<tr><td class="num" id="LN158">158</td><td class="line"> <span class='keyword'>int</span> fd = dev->fd, ret =</td></tr>
<tr><td class="num" id="LN159">159</td><td class="line"> drmCommandWriteRead(fd, <span class='macro'>DRM_NOUVEAU_GETPARAM<span class='expansion'>0x00</span></span>, &r, <span class='keyword'>sizeof</span>(r));</td></tr>
<tr><td class="num" id="LN160">160</td><td class="line"> *value = r.value;</td></tr>
<tr><td class="num" id="LN161">161</td><td class="line"> <span class='keyword'>return</span> ret;</td></tr>
<tr><td class="num" id="LN162">162</td><td class="line">}</td></tr>
<tr><td class="num" id="LN163">163</td><td class="line"> </td></tr>
<tr><td class="num" id="LN164">164</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN165">165</td><td class="line">nouveau_setparam(<span class='keyword'>struct</span> nouveau_device *dev, uint64_t param, uint64_t value)</td></tr>
<tr><td class="num" id="LN166">166</td><td class="line">{</td></tr>
<tr><td class="num" id="LN167">167</td><td class="line"> <span class='keyword'>struct</span> drm_nouveau_setparam r = { param, value };</td></tr>
<tr><td class="num" id="LN168">168</td><td class="line"> <span class='keyword'>return</span> drmCommandWrite(dev->fd, <span class='macro'>DRM_NOUVEAU_SETPARAM<span class='expansion'>0x01</span></span>, &r, <span class='keyword'>sizeof</span>(r));</td></tr>
<tr><td class="num" id="LN169">169</td><td class="line">}</td></tr>
<tr><td class="num" id="LN170">170</td><td class="line"> </td></tr>
<tr><td class="num" id="LN171">171</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN172">172</td><td class="line">nouveau_client_new(<span class='keyword'>struct</span> nouveau_device *dev, <span class='keyword'>struct</span> nouveau_client **pclient)</td></tr>
<tr><td class="num" id="LN173">173</td><td class="line">{</td></tr>
<tr><td class="num" id="LN174">174</td><td class="line"> <span class='keyword'>struct</span> nouveau_device_priv *nvdev = nouveau_device(dev);</td></tr>
<tr><td class="num" id="LN175">175</td><td class="line"> <span class='keyword'>struct</span> nouveau_client_priv *pcli;</td></tr>
<tr><td class="num" id="LN176">176</td><td class="line"> <span class='keyword'>int</span> id = 0, i, ret = -<span class='macro'>ENOMEM<span class='expansion'>12</span></span>;</td></tr>
<tr><td class="num" id="LN177">177</td><td class="line"> uint32_t *clients;</td></tr>
<tr><td class="num" id="LN178">178</td><td class="line"> </td></tr>
<tr><td class="num" id="LN179">179</td><td class="line"> <span class='keyword'>for</span> (i = 0; i < nvdev->nr_client; i++) {</td></tr>
<tr><td class="num" id="LN180">180</td><td class="line"> id = ffs(nvdev->client[i]) - 1;</td></tr>
<tr><td class="num" id="LN181">181</td><td class="line"> <span class='keyword'>if</span> (id >= 0)</td></tr>
<tr><td class="num" id="LN182">182</td><td class="line"> <span class='keyword'>goto</span> out;</td></tr>
<tr><td class="num" id="LN183">183</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN184">184</td><td class="line"> </td></tr>
<tr><td class="num" id="LN185">185</td><td class="line"> clients = realloc(nvdev->client, <span class='keyword'>sizeof</span>(uint32_t) * (i + 1));</td></tr>
<tr><td class="num" id="LN186">186</td><td class="line"> <span class='keyword'>if</span> (!clients)</td></tr>
<tr><td class="num" id="LN187">187</td><td class="line"> <span class='keyword'>return</span> ret;</td></tr>
<tr><td class="num" id="LN188">188</td><td class="line"> nvdev->client = clients;</td></tr>
<tr><td class="num" id="LN189">189</td><td class="line"> nvdev->client[i] = 0;</td></tr>
<tr><td class="num" id="LN190">190</td><td class="line"> nvdev->nr_client++;</td></tr>
<tr><td class="num" id="LN191">191</td><td class="line"> </td></tr>
<tr><td class="num" id="LN192">192</td><td class="line">out:</td></tr>
<tr><td class="num" id="LN193">193</td><td class="line"> pcli = calloc(1, <span class='keyword'>sizeof</span>(*pcli));</td></tr>
<tr><td class="num" id="LN194">194</td><td class="line"> <span class='keyword'>if</span> (pcli) {</td></tr>
<tr><td class="num" id="LN195">195</td><td class="line"> nvdev->client[i] |= (1 << id);</td></tr>
<tr><td class="num" id="LN196">196</td><td class="line"> pcli->base.device = dev;</td></tr>
<tr><td class="num" id="LN197">197</td><td class="line"> pcli->base.id = (i * 32) + id;</td></tr>
<tr><td class="num" id="LN198">198</td><td class="line"> ret = 0;</td></tr>
<tr><td class="num" id="LN199">199</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN200">200</td><td class="line"> </td></tr>
<tr><td class="num" id="LN201">201</td><td class="line"> *pclient = &pcli->base;</td></tr>
<tr><td class="num" id="LN202">202</td><td class="line"> <span class='keyword'>return</span> ret;</td></tr>
<tr><td class="num" id="LN203">203</td><td class="line">}</td></tr>
<tr><td class="num" id="LN204">204</td><td class="line"> </td></tr>
<tr><td class="num" id="LN205">205</td><td class="line"><span class='keyword'>void</span></td></tr>
<tr><td class="num" id="LN206">206</td><td class="line">nouveau_client_del(<span class='keyword'>struct</span> nouveau_client **pclient)</td></tr>
<tr><td class="num" id="LN207">207</td><td class="line">{</td></tr>
<tr><td class="num" id="LN208">208</td><td class="line"> <span class='keyword'>struct</span> nouveau_client_priv *pcli = nouveau_client(*pclient);</td></tr>
<tr><td class="num" id="LN209">209</td><td class="line"> <span class='keyword'>struct</span> nouveau_device_priv *nvdev;</td></tr>
<tr><td class="num" id="LN210">210</td><td class="line"> <span class='keyword'>if</span> (pcli) {</td></tr>
<tr><td class="num" id="LN211">211</td><td class="line"> <span class='keyword'>int</span> id = pcli->base.id;</td></tr>
<tr><td class="num" id="LN212">212</td><td class="line"> nvdev = nouveau_device(pcli->base.device);</td></tr>
<tr><td class="num" id="LN213">213</td><td class="line"> nvdev->client[id / 32] &= ~(1 << (id % 32));</td></tr>
<tr><td class="num" id="LN214">214</td><td class="line"> free(pcli->kref);</td></tr>
<tr><td class="num" id="LN215">215</td><td class="line"> free(pcli);</td></tr>
<tr><td class="num" id="LN216">216</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN217">217</td><td class="line">}</td></tr>
<tr><td class="num" id="LN218">218</td><td class="line"> </td></tr>
<tr><td class="num" id="LN219">219</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN220">220</td><td class="line">nouveau_object_new(<span class='keyword'>struct</span> nouveau_object *parent, uint64_t handle,</td></tr>
<tr><td class="num" id="LN221">221</td><td class="line"> uint32_t oclass, <span class='keyword'>void</span> *data, uint32_t length,</td></tr>
<tr><td class="num" id="LN222">222</td><td class="line"> <span class='keyword'>struct</span> nouveau_object **pobj)</td></tr>
<tr><td class="num" id="LN223">223</td><td class="line">{</td></tr>
<tr><td class="num" id="LN224">224</td><td class="line"> <span class='keyword'>struct</span> nouveau_device *dev;</td></tr>
<tr><td class="num" id="LN225">225</td><td class="line"> <span class='keyword'>struct</span> nouveau_object *obj;</td></tr>
<tr><td class="num" id="LN226">226</td><td class="line"> <span class='keyword'>int</span> ret = -<span class='macro'>EINVAL<span class='expansion'>22</span></span>;</td></tr>
<tr><td class="num" id="LN227">227</td><td class="line"> </td></tr>
<tr><td class="num" id="LN228">228</td><td class="line"> <span class='keyword'>if</span> (length == 0)</td></tr>
<tr><td class="num" id="LN229">229</td><td class="line"> length = <span class='keyword'>sizeof</span>(<span class='keyword'>struct</span> nouveau_object *);</td></tr>
<tr><td class="num" id="LN230">230</td><td class="line"> obj = malloc(<span class='keyword'>sizeof</span>(*obj) + length);</td></tr>
<tr><td class="num" id="LN231">231</td><td class="line"> obj->parent = parent;</td></tr>
<tr><td class="num" id="LN232">232</td><td class="line"> obj->handle = handle;</td></tr>
<tr><td class="num" id="LN233">233</td><td class="line"> obj->oclass = oclass;</td></tr>
<tr><td class="num" id="LN234">234</td><td class="line"> obj->length = length;</td></tr>
<tr><td class="num" id="LN235">235</td><td class="line"> obj->data = obj + 1;</td></tr>
<tr><td class="num" id="LN236">236</td><td class="line"> <span class='keyword'>if</span> (data)</td></tr>
<tr><td class="num" id="LN237">237</td><td class="line"> memcpy(obj->data, data, length);</td></tr>
<tr><td class="num" id="LN238">238</td><td class="line"> *(<span class='keyword'>struct</span> nouveau_object **)obj->data = obj;</td></tr>
<tr><td class="num" id="LN239">239</td><td class="line"> </td></tr>
<tr><td class="num" id="LN240">240</td><td class="line"> dev = nouveau_object_find(obj, <span class='macro'>NOUVEAU_DEVICE_CLASS<span class='expansion'>0x80000000</span></span>);</td></tr>
<tr><td class="num" id="LN241">241</td><td class="line"> <span class='keyword'>switch</span> (parent->oclass) {</td></tr>
<tr><td class="num" id="LN242">242</td><td class="line"> <span class='keyword'>case</span> <span class='macro'>NOUVEAU_DEVICE_CLASS<span class='expansion'>0x80000000</span></span>:</td></tr>
<tr><td class="num" id="LN243">243</td><td class="line"> <span class='keyword'>switch</span> (obj->oclass) {</td></tr>
<tr><td class="num" id="LN244">244</td><td class="line"> <span class='keyword'>case</span> <span class='macro'>NOUVEAU_FIFO_CHANNEL_CLASS<span class='expansion'>0x80000001</span></span>:</td></tr>
<tr><td class="num" id="LN245">245</td><td class="line"> {</td></tr>
<tr><td class="num" id="LN246">246</td><td class="line"> <span class='keyword'>if</span> (dev->chipset < 0xc0)</td></tr>
<tr><td class="num" id="LN247">247</td><td class="line"> ret = abi16_chan_nv04(obj);</td></tr>
<tr><td class="num" id="LN248">248</td><td class="line"> <span class='keyword'>else</span></td></tr>
<tr><td class="num" id="LN249">249</td><td class="line"> ret = abi16_chan_nvc0(obj);</td></tr>
<tr><td class="num" id="LN250">250</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN251">251</td><td class="line"> <span class='keyword'>break</span>;</td></tr>
<tr><td class="num" id="LN252">252</td><td class="line"> <span class='keyword'>default</span>:</td></tr>
<tr><td class="num" id="LN253">253</td><td class="line"> <span class='keyword'>break</span>;</td></tr>
<tr><td class="num" id="LN254">254</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN255">255</td><td class="line"> <span class='keyword'>break</span>;</td></tr>
<tr><td class="num" id="LN256">256</td><td class="line"> <span class='keyword'>case</span> <span class='macro'>NOUVEAU_FIFO_CHANNEL_CLASS<span class='expansion'>0x80000001</span></span>:</td></tr>
<tr><td class="num" id="LN257">257</td><td class="line"> <span class='keyword'>switch</span> (obj->oclass) {</td></tr>
<tr><td class="num" id="LN258">258</td><td class="line"> <span class='keyword'>case</span> <span class='macro'>NOUVEAU_NOTIFIER_CLASS<span class='expansion'>0x80000002</span></span>:</td></tr>
<tr><td class="num" id="LN259">259</td><td class="line"> ret = abi16_ntfy(obj);</td></tr>
<tr><td class="num" id="LN260">260</td><td class="line"> <span class='keyword'>break</span>;</td></tr>
<tr><td class="num" id="LN261">261</td><td class="line"> <span class='keyword'>default</span>:</td></tr>
<tr><td class="num" id="LN262">262</td><td class="line"> ret = abi16_engobj(obj);</td></tr>
<tr><td class="num" id="LN263">263</td><td class="line"> <span class='keyword'>break</span>;</td></tr>
<tr><td class="num" id="LN264">264</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN265">265</td><td class="line"> <span class='keyword'>default</span>:</td></tr>
<tr><td class="num" id="LN266">266</td><td class="line"> <span class='keyword'>break</span>;</td></tr>
<tr><td class="num" id="LN267">267</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN268">268</td><td class="line"> </td></tr>
<tr><td class="num" id="LN269">269</td><td class="line"> <span class='keyword'>if</span> (ret) {</td></tr>
<tr><td class="num" id="LN270">270</td><td class="line"> free(obj);</td></tr>
<tr><td class="num" id="LN271">271</td><td class="line"> <span class='keyword'>return</span> ret;</td></tr>
<tr><td class="num" id="LN272">272</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN273">273</td><td class="line"> </td></tr>
<tr><td class="num" id="LN274">274</td><td class="line"> *pobj = obj;</td></tr>
<tr><td class="num" id="LN275">275</td><td class="line"> <span class='keyword'>return</span> 0;</td></tr>
<tr><td class="num" id="LN276">276</td><td class="line">}</td></tr>
<tr><td class="num" id="LN277">277</td><td class="line"> </td></tr>
<tr><td class="num" id="LN278">278</td><td class="line"><span class='keyword'>void</span></td></tr>
<tr><td class="num" id="LN279">279</td><td class="line">nouveau_object_del(<span class='keyword'>struct</span> nouveau_object **pobj)</td></tr>
<tr><td class="num" id="LN280">280</td><td class="line">{</td></tr>
<tr><td class="num" id="LN281">281</td><td class="line"> <span class='keyword'>struct</span> nouveau_object *obj = *pobj;</td></tr>
<tr><td class="num" id="LN282">282</td><td class="line"> <span class='keyword'>struct</span> nouveau_device *dev;</td></tr>
<tr><td class="num" id="LN283">283</td><td class="line"> <span class='keyword'>if</span> (obj) {</td></tr>
<tr><td class="num" id="LN284">284</td><td class="line"> dev = nouveau_object_find(obj, <span class='macro'>NOUVEAU_DEVICE_CLASS<span class='expansion'>0x80000000</span></span>);</td></tr>
<tr><td class="num" id="LN285">285</td><td class="line"> <span class='keyword'>if</span> (obj->oclass == <span class='macro'>NOUVEAU_FIFO_CHANNEL_CLASS<span class='expansion'>0x80000001</span></span>) {</td></tr>
<tr><td class="num" id="LN286">286</td><td class="line"> <span class='keyword'>struct</span> drm_nouveau_channel_free req;</td></tr>
<tr><td class="num" id="LN287">287</td><td class="line"> req.channel = obj->handle;</td></tr>
<tr><td class="num" id="LN288">288</td><td class="line"> drmCommandWrite(dev->fd, <span class='macro'>DRM_NOUVEAU_CHANNEL_FREE<span class='expansion'>0x03</span></span>,</td></tr>
<tr><td class="num" id="LN289">289</td><td class="line"> &req, <span class='keyword'>sizeof</span>(req));</td></tr>
<tr><td class="num" id="LN290">290</td><td class="line"> } <span class='keyword'>else</span> {</td></tr>
<tr><td class="num" id="LN291">291</td><td class="line"> <span class='keyword'>struct</span> drm_nouveau_gpuobj_free req;</td></tr>
<tr><td class="num" id="LN292">292</td><td class="line"> req.channel = obj->parent->handle;</td></tr>
<tr><td class="num" id="LN293">293</td><td class="line"> req.handle = obj->handle;</td></tr>
<tr><td class="num" id="LN294">294</td><td class="line"> drmCommandWrite(dev->fd, <span class='macro'>DRM_NOUVEAU_GPUOBJ_FREE<span class='expansion'>0x06</span></span>,</td></tr>
<tr><td class="num" id="LN295">295</td><td class="line"> &req, <span class='keyword'>sizeof</span>(req));</td></tr>
<tr><td class="num" id="LN296">296</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN297">297</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN298">298</td><td class="line"> free(obj);</td></tr>
<tr><td class="num" id="LN299">299</td><td class="line"> *pobj = <span class='macro'>NULL<span class='expansion'>((void *)0)</span></span>;</td></tr>
<tr><td class="num" id="LN300">300</td><td class="line">}</td></tr>
<tr><td class="num" id="LN301">301</td><td class="line"> </td></tr>
<tr><td class="num" id="LN302">302</td><td class="line"><span class='keyword'>void</span> *</td></tr>
<tr><td class="num" id="LN303">303</td><td class="line">nouveau_object_find(<span class='keyword'>struct</span> nouveau_object *obj, uint32_t pclass)</td></tr>
<tr><td class="num" id="LN304">304</td><td class="line">{</td></tr>
<tr><td class="num" id="LN305">305</td><td class="line"> <span class='keyword'>while</span> (obj && obj->oclass != pclass) {</td></tr>
<tr><td class="num" id="LN306">306</td><td class="line"> obj = obj->parent;</td></tr>
<tr><td class="num" id="LN307">307</td><td class="line"> <span class='keyword'>if</span> (pclass == <span class='macro'>NOUVEAU_PARENT_CLASS<span class='expansion'>0xffffffff</span></span>)</td></tr>
<tr><td class="num" id="LN308">308</td><td class="line"> <span class='keyword'>break</span>;</td></tr>
<tr><td class="num" id="LN309">309</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN310">310</td><td class="line"> <span class='keyword'>return</span> obj;</td></tr>
<tr><td class="num" id="LN311">311</td><td class="line">}</td></tr>
<tr><td class="num" id="LN312">312</td><td class="line"> </td></tr>
<tr><td class="num" id="LN313">313</td><td class="line"><span class='keyword'>static</span> <span class='keyword'>void</span></td></tr>
<tr><td class="num" id="LN314">314</td><td class="line">nouveau_bo_del(<span class='keyword'>struct</span> nouveau_bo *bo)</td></tr>
<tr><td class="num" id="LN315">315</td><td class="line">{</td></tr>
<tr><td class="num" id="LN316">316</td><td class="line"> <span class='keyword'>struct</span> nouveau_bo_priv *nvbo = nouveau_bo(bo);</td></tr>
<tr><td class="num" id="LN317">317</td><td class="line"> <span class='keyword'>struct</span> drm_gem_close req = { bo->handle };</td></tr>
<tr><td class="num" id="LN318">318</td><td class="line"> <span class='macro'>DRMLISTDEL(&nvbo->head)<span class='expansion'>do { (&nvbo->head)->prev->next = (&nvbo-><br>head)->next; (&nvbo->head)->next->prev = (&<br>nvbo->head)->prev; } while(0)</span></span>;</td></tr>
<tr><td class="num" id="LN319">319</td><td class="line"> <span class='keyword'>if</span> (bo->map)</td></tr>
<tr><td class="num" id="LN320">320</td><td class="line"> munmap(bo->map, bo->size);</td></tr>
<tr><td class="num" id="LN321">321</td><td class="line"> drmIoctl(bo->device->fd, <span class='macro'>DRM_IOCTL_GEM_CLOSE<span class='expansion'>(((1U) << (((0 +8)+8)+14)) | ((('d')) << (0 +8)) |<br> (((0x09)) << 0) | ((((sizeof(struct drm_gem_close)))) <<<br> ((0 +8)+8)))</span></span>, &req);</td></tr>
<tr><td class="num" id="LN322">322</td><td class="line"> free(nvbo);</td></tr>
<tr><td class="num" id="LN323">323</td><td class="line">}</td></tr>
<tr><td class="num" id="LN324">324</td><td class="line"> </td></tr>
<tr><td class="num" id="LN325">325</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN326">326</td><td class="line">nouveau_bo_new(<span class='keyword'>struct</span> nouveau_device *dev, uint32_t flags, uint32_t align,</td></tr>
<tr><td class="num" id="LN327">327</td><td class="line"> uint64_t size, <span class='keyword'>union</span> nouveau_bo_config *config,</td></tr>
<tr><td class="num" id="LN328">328</td><td class="line"> <span class='keyword'>struct</span> nouveau_bo **pbo)</td></tr>
<tr><td class="num" id="LN329">329</td><td class="line">{</td></tr>
<tr><td class="num" id="LN330">330</td><td class="line"> <span class='keyword'>struct</span> nouveau_device_priv *nvdev = nouveau_device(dev);</td></tr>
<tr><td class="num" id="LN331">331</td><td class="line"> <span class='keyword'>struct</span> nouveau_bo_priv *nvbo = calloc(1, <span class='keyword'>sizeof</span>(*nvbo));</td></tr>
<tr><td class="num" id="LN332">332</td><td class="line"> <span class='keyword'>struct</span> nouveau_bo *bo = &nvbo->base;</td></tr>
<tr><td class="num" id="LN333">333</td><td class="line"> <span class='keyword'>int</span> ret;</td></tr>
<tr><td class="num" id="LN334">334</td><td class="line"> </td></tr>
<tr><td class="num" id="LN335">335</td><td class="line"> <span class='keyword'>if</span> (!nvbo)</td></tr>
<tr><td class="num" id="LN336">336</td><td class="line"> <span class='keyword'>return</span> -<span class='macro'>ENOMEM<span class='expansion'>12</span></span>;</td></tr>
<tr><td class="num" id="LN337">337</td><td class="line"> <span class='macro'>atomic_set(&nvbo->refcnt, 1)<span class='expansion'>((&nvbo->refcnt)->atomic = (1))</span></span>;</td></tr>
<tr><td class="num" id="LN338">338</td><td class="line"> bo->device = dev;</td></tr>
<tr><td class="num" id="LN339">339</td><td class="line"> bo->flags = flags;</td></tr>
<tr><td class="num" id="LN340">340</td><td class="line"> bo->size = size;</td></tr>
<tr><td class="num" id="LN341">341</td><td class="line"> </td></tr>
<tr><td class="num" id="LN342">342</td><td class="line"> ret = abi16_bo_init(bo, align, config);</td></tr>
<tr><td class="num" id="LN343">343</td><td class="line"> <span class='keyword'>if</span> (ret) {</td></tr>
<tr><td class="num" id="LN344">344</td><td class="line"> free(nvbo);</td></tr>
<tr><td class="num" id="LN345">345</td><td class="line"> <span class='keyword'>return</span> ret;</td></tr>
<tr><td class="num" id="LN346">346</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN347">347</td><td class="line"> </td></tr>
<tr><td class="num" id="LN348">348</td><td class="line"> <span class='macro'>DRMLISTADD(&nvbo->head, &nvdev->bo_list)<span class='expansion'>do { (&nvbo->head)->prev = (&nvdev->bo_list)<br>; (&nvbo->head)->next = (&nvdev->bo_list)-><br>next; (&nvdev->bo_list)->next->prev = (&nvbo<br>->head); (&nvdev->bo_list)->next = (&nvbo-><br>head); } while (0)</span></span>;</td></tr>
<tr><td class="num" id="LN349">349</td><td class="line"> </td></tr>
<tr><td class="num" id="LN350">350</td><td class="line"> *pbo = bo;</td></tr>
<tr><td class="num" id="LN351">351</td><td class="line"> <span class='keyword'>return</span> 0;</td></tr>
<tr><td class="num" id="LN352">352</td><td class="line">}</td></tr>
<tr><td class="num" id="LN353">353</td><td class="line"> </td></tr>
<tr><td class="num" id="LN354">354</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN355">355</td><td class="line">nouveau_bo_wrap(<span class='keyword'>struct</span> nouveau_device *dev, uint32_t handle,</td></tr>
<tr><td class="num" id="LN356">356</td><td class="line"> <span class='keyword'>struct</span> nouveau_bo **pbo)</td></tr>
<tr><td class="num" id="LN357">357</td><td class="line">{</td></tr>
<tr><td class="num" id="LN358">358</td><td class="line"> <span class='keyword'>struct</span> nouveau_device_priv *nvdev = nouveau_device(dev);</td></tr>
<tr><td class="num" id="LN359">359</td><td class="line"> <span class='keyword'>struct</span> drm_nouveau_gem_info req = { .handle = handle };</td></tr>
<tr><td class="num" id="LN360">360</td><td class="line"> <span class='keyword'>struct</span> nouveau_bo_priv *nvbo;</td></tr>
<tr><td class="num" id="LN361">361</td><td class="line"> <span class='keyword'>int</span> ret;</td></tr>
<tr><td class="num" id="LN362">362</td><td class="line"> </td></tr>
<tr><td class="num" id="LN363">363</td><td class="line"> <span class='macro'>DRMLISTFOREACHENTRY(nvbo, &nvdev->bo_list, head)<span class='expansion'>for ((nvbo) = ((typeof(*nvbo) *)(((char *) ((&nvdev->bo_list<br>)->next)) - __builtin_offsetof(typeof(*nvbo), head))); &<br>(nvbo)->head != (&nvdev->bo_list); (nvbo) = ((typeof<br>(*nvbo) *)(((char *) ((nvbo)->head.next)) - __builtin_offsetof<br>(typeof(*nvbo), head))))</span></span> {</td></tr>
<tr><td class="num" id="LN364">364</td><td class="line"> <span class='keyword'>if</span> (nvbo->base.handle == handle) {</td></tr>
<tr><td class="num" id="LN365">365</td><td class="line"> *pbo = <span class='macro'>NULL<span class='expansion'>((void *)0)</span></span>;</td></tr>
<tr><td class="num" id="LN366">366</td><td class="line"> nouveau_bo_ref(&nvbo->base, pbo);</td></tr>
<tr><td class="num" id="LN367">367</td><td class="line"> <span class='keyword'>return</span> 0;</td></tr>
<tr><td class="num" id="LN368">368</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN369">369</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN370">370</td><td class="line"> </td></tr>
<tr><td class="num" id="LN371">371</td><td class="line"> ret = drmCommandWriteRead(dev->fd, <span class='macro'>DRM_NOUVEAU_GEM_INFO<span class='expansion'>0x44</span></span>,</td></tr>
<tr><td class="num" id="LN372">372</td><td class="line"> &req, <span class='keyword'>sizeof</span>(req));</td></tr>
<tr><td class="num" id="LN373">373</td><td class="line"> <span class='keyword'>if</span> (ret)</td></tr>
<tr><td class="num" id="LN374">374</td><td class="line"> <span class='keyword'>return</span> ret;</td></tr>
<tr><td class="num" id="LN375">375</td><td class="line"> </td></tr>
<tr><td class="num" id="LN376">376</td><td class="line"> nvbo = calloc(1, <span class='keyword'>sizeof</span>(*nvbo));</td></tr>
<tr><td class="num" id="LN377">377</td><td class="line"> <span class='keyword'>if</span> (nvbo) {</td></tr>
<tr><td class="num" id="LN378">378</td><td class="line"> <span class='macro'>atomic_set(&nvbo->refcnt, 1)<span class='expansion'>((&nvbo->refcnt)->atomic = (1))</span></span>;</td></tr>
<tr><td class="num" id="LN379">379</td><td class="line"> nvbo->base.device = dev;</td></tr>
<tr><td class="num" id="LN380">380</td><td class="line"> abi16_bo_info(&nvbo->base, &req);</td></tr>
<tr><td class="num" id="LN381">381</td><td class="line"> <span class='macro'>DRMLISTADD(&nvbo->head, &nvdev->bo_list)<span class='expansion'>do { (&nvbo->head)->prev = (&nvdev->bo_list)<br>; (&nvbo->head)->next = (&nvdev->bo_list)-><br>next; (&nvdev->bo_list)->next->prev = (&nvbo<br>->head); (&nvdev->bo_list)->next = (&nvbo-><br>head); } while (0)</span></span>;</td></tr>
<tr><td class="num" id="LN382">382</td><td class="line"> *pbo = &nvbo->base;</td></tr>
<tr><td class="num" id="LN383">383</td><td class="line"> <span class='keyword'>return</span> 0;</td></tr>
<tr><td class="num" id="LN384">384</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN385">385</td><td class="line"> </td></tr>
<tr><td class="num" id="LN386">386</td><td class="line"> <span class='keyword'>return</span> -<span class='macro'>ENOMEM<span class='expansion'>12</span></span>;</td></tr>
<tr><td class="num" id="LN387">387</td><td class="line">}</td></tr>
<tr><td class="num" id="LN388">388</td><td class="line"> </td></tr>
<tr><td class="num" id="LN389">389</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN390">390</td><td class="line">nouveau_bo_name_ref(<span class='keyword'>struct</span> nouveau_device *dev, uint32_t name,</td></tr>
<tr><td class="num" id="LN391">391</td><td class="line"> <span class='keyword'>struct</span> nouveau_bo **pbo)</td></tr>
<tr><td class="num" id="LN392">392</td><td class="line">{</td></tr>
<tr><td class="num" id="LN393">393</td><td class="line"> <span class='keyword'>struct</span> nouveau_device_priv *nvdev = nouveau_device(dev);</td></tr>
<tr><td class="num" id="LN394">394</td><td class="line"> <span class='keyword'>struct</span> nouveau_bo_priv *nvbo;</td></tr>
<tr><td class="num" id="LN395">395</td><td class="line"> <span class='keyword'>struct</span> drm_gem_open req = { .name = name };</td></tr>
<tr><td class="num" id="LN396">396</td><td class="line"> <span class='keyword'>int</span> ret;</td></tr>
<tr><td class="num" id="LN397">397</td><td class="line"> </td></tr>
<tr><td class="num" id="LN398">398</td><td class="line"> <span class='macro'>DRMLISTFOREACHENTRY(nvbo, &nvdev->bo_list, head)<span class='expansion'>for ((nvbo) = ((typeof(*nvbo) *)(((char *) ((&nvdev->bo_list<br>)->next)) - __builtin_offsetof(typeof(*nvbo), head))); &<br>(nvbo)->head != (&nvdev->bo_list); (nvbo) = ((typeof<br>(*nvbo) *)(((char *) ((nvbo)->head.next)) - __builtin_offsetof<br>(typeof(*nvbo), head))))</span></span> {</td></tr>
<tr><td class="num" id="LN399">399</td><td class="line"> <span class='keyword'>if</span> (nvbo->name == name) {</td></tr>
<tr><td class="num" id="LN400">400</td><td class="line"> *pbo = <span class='macro'>NULL<span class='expansion'>((void *)0)</span></span>;</td></tr>
<tr><td class="num" id="LN401">401</td><td class="line"> nouveau_bo_ref(&nvbo->base, pbo);</td></tr>
<tr><td class="num" id="LN402">402</td><td class="line"> <span class='keyword'>return</span> 0;</td></tr>
<tr><td class="num" id="LN403">403</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN404">404</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN405">405</td><td class="line"> </td></tr>
<tr><td class="num" id="LN406">406</td><td class="line"> ret = drmIoctl(dev->fd, <span class='macro'>DRM_IOCTL_GEM_OPEN<span class='expansion'>(((2U|1U) << (((0 +8)+8)+14)) | ((('d')) << (0 +8<br>)) | (((0x0b)) << 0) | ((((sizeof(struct drm_gem_open))<br>)) << ((0 +8)+8)))</span></span>, &req);</td></tr>
<tr><td class="num" id="LN407">407</td><td class="line"> <span class='keyword'>if</span> (ret == 0) {</td></tr>
<tr><td class="num" id="LN408">408</td><td class="line"> ret = nouveau_bo_wrap(dev, req.handle, pbo);</td></tr>
<tr><td class="num" id="LN409">409</td><td class="line"> nouveau_bo((*pbo))->name = name;</td></tr>
<tr><td class="num" id="LN410">410</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN411">411</td><td class="line"> </td></tr>
<tr><td class="num" id="LN412">412</td><td class="line"> <span class='keyword'>return</span> ret;</td></tr>
<tr><td class="num" id="LN413">413</td><td class="line">}</td></tr>
<tr><td class="num" id="LN414">414</td><td class="line"> </td></tr>
<tr><td class="num" id="LN415">415</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN416">416</td><td class="line">nouveau_bo_name_get(<span class='keyword'>struct</span> nouveau_bo *bo, uint32_t *name)</td></tr>
<tr><td class="num" id="LN417">417</td><td class="line">{</td></tr>
<tr><td class="num" id="LN418">418</td><td class="line"> <span class='keyword'>struct</span> drm_gem_flink req = { .handle = bo->handle };</td></tr>
<tr><td class="num" id="LN419">419</td><td class="line"> <span class='keyword'>struct</span> nouveau_bo_priv *nvbo = nouveau_bo(bo);</td></tr>
<tr><td class="num" id="LN420">420</td><td class="line"> <span class='keyword'>if</span> (!nvbo->name) {</td></tr>
<tr><td class="num" id="LN421">421</td><td class="line"> <span class='keyword'>int</span> ret = drmIoctl(bo->device->fd, <span class='macro'>DRM_IOCTL_GEM_FLINK<span class='expansion'>(((2U|1U) << (((0 +8)+8)+14)) | ((('d')) << (0 +8<br>)) | (((0x0a)) << 0) | ((((sizeof(struct drm_gem_flink)<br>))) << ((0 +8)+8)))</span></span>, &req);</td></tr>
<tr><td class="num" id="LN422">422</td><td class="line"> <span class='keyword'>if</span> (ret)</td></tr>
<tr><td class="num" id="LN423">423</td><td class="line"> <span class='keyword'>return</span> ret;</td></tr>
<tr><td class="num" id="LN424">424</td><td class="line"> nvbo->name = req.name;</td></tr>
<tr><td class="num" id="LN425">425</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN426">426</td><td class="line"> *name = nvbo->name;</td></tr>
<tr><td class="num" id="LN427">427</td><td class="line"> <span class='keyword'>return</span> 0;</td></tr>
<tr><td class="num" id="LN428">428</td><td class="line">}</td></tr>
<tr><td class="num" id="LN429">429</td><td class="line"> </td></tr>
<tr><td class="num" id="LN430">430</td><td class="line"><span class='keyword'>void</span></td></tr>
<tr><td class="num" id="LN431">431</td><td class="line">nouveau_bo_ref(<span class='keyword'>struct</span> nouveau_bo *bo, <span class='keyword'>struct</span> nouveau_bo **pref)</td></tr>
<tr><td class="num" id="LN432">432</td><td class="line">{</td></tr>
<tr><td class="num" id="LN433">433</td><td class="line"> <span class='keyword'>struct</span> nouveau_bo *ref = *pref;</td></tr>
<tr><td class="num" id="LN434">434</td><td class="line"> <span class='keyword'>if</span> (bo) {</td></tr>
<tr><td class="num" id="LN435">435</td><td class="line"> <span class='macro'>atomic_inc(&nouveau_bo(bo)->refcnt)<span class='expansion'>((void) __sync_fetch_and_add (&(&nouveau_bo(bo)->refcnt<br>)->atomic, 1))</span></span>;</td></tr>
<tr><td class="num" id="LN436">436</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN437">437</td><td class="line"> <span class='keyword'>if</span> (ref) {</td></tr>
<tr><td class="num" id="LN438">438</td><td class="line"> <span class='keyword'>if</span> (<span class='macro'>atomic_dec_and_test(&nouveau_bo(ref)->refcnt)<span class='expansion'>(__sync_fetch_and_add (&(&nouveau_bo(ref)->refcnt)<br>->atomic, -1) == 1)</span></span>)</td></tr>
<tr><td class="num" id="LN439">439</td><td class="line"> nouveau_bo_del(ref);</td></tr>
<tr><td class="num" id="LN440">440</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN441">441</td><td class="line"> *pref = bo;</td></tr>
<tr><td class="num" id="LN442">442</td><td class="line">}</td></tr>
<tr><td class="num" id="LN443">443</td><td class="line"> </td></tr>
<tr><td class="num" id="LN444">444</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN445">445</td><td class="line">nouveau_bo_wait(<span class='keyword'>struct</span> nouveau_bo *bo, uint32_t access,</td></tr>
<tr><td class="num" id="LN446">446</td><td class="line"> <span class='keyword'>struct</span> nouveau_client *client)</td></tr>
<tr><td class="num" id="LN447">447</td><td class="line">{</td></tr>
<tr><td class="num" id="LN448">448</td><td class="line"> <span class='keyword'>struct</span> nouveau_bo_priv *nvbo = nouveau_bo(bo);</td></tr>
<tr><td class="num" id="LN449">449</td><td class="line"> <span class='keyword'>struct</span> drm_nouveau_gem_cpu_prep req;</td></tr>
<tr><td class="num" id="LN450">450</td><td class="line"> <span class='keyword'>struct</span> nouveau_pushbuf *push;</td></tr>
<tr><td class="num" id="LN451">451</td><td class="line"> <span class='keyword'>int</span> ret = 0;</td></tr>
<tr><td class="num" id="LN452">452</td><td class="line"> </td></tr>
<tr><td class="num" id="LN453">453</td><td class="line"> <span class='keyword'>if</span> (!(access & <span class='macro'>NOUVEAU_BO_RDWR<span class='expansion'>(0x00000100 | 0x00000200)</span></span>))</td></tr>
<tr><td class="num" id="LN454">454</td><td class="line"> <span class='keyword'>return</span> 0;</td></tr>
<tr><td class="num" id="LN455">455</td><td class="line"> </td></tr>
<tr><td class="num" id="LN456">456</td><td class="line"> push = cli_push_get(client, bo);</td></tr>
<tr><td class="num" id="LN457">457</td><td class="line"> <span class='keyword'>if</span> (push && push->channel)</td></tr>
<tr><td class="num" id="LN458">458</td><td class="line"> nouveau_pushbuf_kick(push, push->channel);</td></tr>
<tr><td class="num" id="LN459">459</td><td class="line"> </td></tr>
<tr><td class="num" id="LN460">460</td><td class="line"> <span class='keyword'>if</span> (!nvbo->name && !(nvbo->access & <span class='macro'>NOUVEAU_BO_WR<span class='expansion'>0x00000200</span></span>) &&</td></tr>
<tr><td class="num" id="LN461">461</td><td class="line"> !( access & <span class='macro'>NOUVEAU_BO_WR<span class='expansion'>0x00000200</span></span>))</td></tr>
<tr><td class="num" id="LN462">462</td><td class="line"> <span class='keyword'>return</span> 0;</td></tr>
<tr><td class="num" id="LN463">463</td><td class="line"> </td></tr>
<tr><td class="num" id="LN464">464</td><td class="line"> req.handle = bo->handle;</td></tr>
<tr><td class="num" id="LN465">465</td><td class="line"> req.flags = 0;</td></tr>
<tr><td class="num" id="LN466">466</td><td class="line"> <span class='keyword'>if</span> (access & <span class='macro'>NOUVEAU_BO_WR<span class='expansion'>0x00000200</span></span>)</td></tr>
<tr><td class="num" id="LN467">467</td><td class="line"> req.flags |= <span class='macro'>NOUVEAU_GEM_CPU_PREP_WRITE<span class='expansion'>0x00000004</span></span>;</td></tr>
<tr><td class="num" id="LN468">468</td><td class="line"> <span class='keyword'>if</span> (access & <span class='macro'>NOUVEAU_BO_NOBLOCK<span class='expansion'>0x00000400</span></span>)</td></tr>
<tr><td class="num" id="LN469">469</td><td class="line"> req.flags |= <span class='macro'>NOUVEAU_GEM_CPU_PREP_NOWAIT<span class='expansion'>0x00000001</span></span>;</td></tr>
<tr><td class="num" id="LN470">470</td><td class="line"> </td></tr>
<tr><td class="num" id="LN471">471</td><td class="line"> ret = drmCommandWrite(bo->device->fd, <span class='macro'>DRM_NOUVEAU_GEM_CPU_PREP<span class='expansion'>0x42</span></span>,</td></tr>
<tr><td class="num" id="LN472">472</td><td class="line"> &req, <span class='keyword'>sizeof</span>(req));</td></tr>
<tr><td class="num" id="LN473">473</td><td class="line"> <span class='keyword'>if</span> (ret == 0)</td></tr>
<tr><td class="num" id="LN474">474</td><td class="line"> nvbo->access = 0;</td></tr>
<tr><td class="num" id="LN475">475</td><td class="line"> <span class='keyword'>return</span> ret;</td></tr>
<tr><td class="num" id="LN476">476</td><td class="line">}</td></tr>
<tr><td class="num" id="LN477">477</td><td class="line"> </td></tr>
<tr><td class="num" id="LN478">478</td><td class="line"><span class='keyword'>int</span></td></tr>
<tr><td class="num" id="LN479">479</td><td class="line">nouveau_bo_map(<span class='keyword'>struct</span> nouveau_bo *bo, uint32_t access,</td></tr>
<tr><td class="num" id="LN480">480</td><td class="line"> <span class='keyword'>struct</span> nouveau_client *client)</td></tr>
<tr><td class="num" id="LN481">481</td><td class="line">{</td></tr>
<tr><td class="num" id="LN482">482</td><td class="line"> <span class='keyword'>struct</span> nouveau_bo_priv *nvbo = nouveau_bo(bo);</td></tr>
<tr><td class="num" id="LN483">483</td><td class="line"> <span class='keyword'>if</span> (bo->map == <span class='macro'>NULL<span class='expansion'>((void *)0)</span></span>) {</td></tr>
<tr><td class="num" id="LN484">484</td><td class="line"> bo->map = mmap(0, bo->size, <span class='macro'>PROT_READ<span class='expansion'>0x1</span></span> | <span class='macro'>PROT_WRITE<span class='expansion'>0x2</span></span>,</td></tr>
<tr><td class="num" id="LN485">485</td><td class="line"> <span class='macro'>MAP_SHARED<span class='expansion'>0x01</span></span>, bo->device->fd, nvbo->map_handle);</td></tr>
<tr><td class="num" id="LN486">486</td><td class="line"> <span class='keyword'>if</span> (bo->map == <span class='macro'>MAP_FAILED<span class='expansion'>((void *) -1)</span></span>) {</td></tr>
<tr><td class="num" id="LN487">487</td><td class="line"> bo->map = <span class='macro'>NULL<span class='expansion'>((void *)0)</span></span>;</td></tr>
<tr><td class="num" id="LN488">488</td><td class="line"> <span class='keyword'>return</span> -<span class='macro'>errno<span class='expansion'>(*__errno_location ())</span></span>;</td></tr>
<tr><td class="num" id="LN489">489</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN490">490</td><td class="line"> }</td></tr>
<tr><td class="num" id="LN491">491</td><td class="line"> <span class='keyword'>return</span> nouveau_bo_wait(bo, access, client);</td></tr>
<tr><td class="num" id="LN492">492</td><td class="line">}</td></tr>
</table></body></html>