\hypertarget{xdma__sglist_8c_source}{}\doxysection{xdma\+\_\+sglist.\+c}
\label{xdma__sglist_8c_source}\index{dev/xdma/xdma\_sglist.c@{dev/xdma/xdma\_sglist.c}}
\mbox{\hyperlink{xdma__sglist_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00002}00002 \textcolor{comment}{ * Copyright (c) 2017-\/2018 Ruslan Bukin <br@bsdpad.com>}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00003}00003 \textcolor{comment}{ * All rights reserved.}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00004}00004 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00005}00005 \textcolor{comment}{ * This software was developed by SRI International and the University of}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00006}00006 \textcolor{comment}{ * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-\/10-\/C-\/0237}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00007}00007 \textcolor{comment}{ * ("{}CTSRD"{}), as part of the DARPA CRASH research programme.}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00008}00008 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00009}00009 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00010}00010 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00011}00011 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00012}00012 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00013}00013 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00014}00014 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00015}00015 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00016}00016 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00017}00017 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00018}00018 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00019}00019 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00020}00020 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00021}00021 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00022}00022 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00023}00023 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00024}00024 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00025}00025 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00026}00026 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00027}00027 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00028}00028 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00029}00029 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00030}00030 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00031}00031 \textcolor{preprocessor}{\#include <sys/cdefs.h>}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00032}\mbox{\hyperlink{xdma__sglist_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{00032}} \mbox{\hyperlink{xdma__sglist_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{\_\_FBSDID}}(\textcolor{stringliteral}{"{}\$FreeBSD\$"{}});}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00033}00033 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00034}00034 \textcolor{preprocessor}{\#include "{}opt\_platform.h"{}}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00035}00035 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00036}00036 \textcolor{preprocessor}{\#include <sys/conf.h>}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00037}00037 \textcolor{preprocessor}{\#include <sys/bus.h>}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00038}00038 \textcolor{preprocessor}{\#include <sys/kernel.h>}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00039}00039 \textcolor{preprocessor}{\#include <sys/malloc.h>}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00040}00040 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00041}00041 \textcolor{preprocessor}{\#include <machine/bus.h>}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00042}00042 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00043}00043 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{xdma_8h}{dev/xdma/xdma.h}}>}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00044}00044 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00045}00045 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00046}\mbox{\hyperlink{xdma_8h_af8a2efa24f8d77d2f3330d44425a1c25}{00046}} \mbox{\hyperlink{xdma__sglist_8c_af8a2efa24f8d77d2f3330d44425a1c25}{xchan\_sglist\_alloc}}(\mbox{\hyperlink{structxdma__channel}{xdma\_channel\_t}} *\mbox{\hyperlink{xdma__if_8m_ab9f2da5982c567c6121c5d62f9b5b959}{xchan}})}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00047}00047 \{}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00048}00048         uint32\_t sz;}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00049}00049 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00050}00050         \textcolor{keywordflow}{if} (\mbox{\hyperlink{xdma__if_8m_ab9f2da5982c567c6121c5d62f9b5b959}{xchan}}-\/>\mbox{\hyperlink{structxdma__channel_aa2f4e74343b931b260a2590290e4e557}{flags}} \& \mbox{\hyperlink{xdma_8h_aaa5f075383fdcbe1068ba27b2a9ef571}{XCHAN\_SGLIST\_ALLOCATED}})}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00051}00051                 \textcolor{keywordflow}{return} (-\/1);}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00052}00052 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00053}00053         sz = (\textcolor{keyword}{sizeof}(\textcolor{keyword}{struct }\mbox{\hyperlink{structxdma__sglist}{xdma\_sglist}}) * \mbox{\hyperlink{xdma_8h_aa23c787b88cc0f833a299eda5c9348a7}{XDMA\_SGLIST\_MAXLEN}});}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00054}00054         \mbox{\hyperlink{xdma__if_8m_ab9f2da5982c567c6121c5d62f9b5b959}{xchan}}-\/>\mbox{\hyperlink{structxdma__channel_a0f4fc71c54e8c471d48be7f6141312b3}{sg}} = malloc(sz, M\_XDMA, M\_WAITOK | M\_ZERO);}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00055}00055         \mbox{\hyperlink{xdma__if_8m_ab9f2da5982c567c6121c5d62f9b5b959}{xchan}}-\/>\mbox{\hyperlink{structxdma__channel_aa2f4e74343b931b260a2590290e4e557}{flags}} |= \mbox{\hyperlink{xdma_8h_aaa5f075383fdcbe1068ba27b2a9ef571}{XCHAN\_SGLIST\_ALLOCATED}};}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00056}00056 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00057}00057         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00058}00058 \}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00059}00059 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00060}00060 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00061}\mbox{\hyperlink{xdma_8h_add4a8c2851cf5d5c5f24965b4ca898af}{00061}} \mbox{\hyperlink{xdma__sglist_8c_add4a8c2851cf5d5c5f24965b4ca898af}{xchan\_sglist\_free}}(\mbox{\hyperlink{structxdma__channel}{xdma\_channel\_t}} *\mbox{\hyperlink{xdma__if_8m_ab9f2da5982c567c6121c5d62f9b5b959}{xchan}})}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00062}00062 \{}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00063}00063 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00064}00064         \textcolor{keywordflow}{if} (\mbox{\hyperlink{xdma__if_8m_ab9f2da5982c567c6121c5d62f9b5b959}{xchan}}-\/>\mbox{\hyperlink{structxdma__channel_aa2f4e74343b931b260a2590290e4e557}{flags}} \& \mbox{\hyperlink{xdma_8h_aaa5f075383fdcbe1068ba27b2a9ef571}{XCHAN\_SGLIST\_ALLOCATED}})}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00065}00065                 free(\mbox{\hyperlink{xdma__if_8m_ab9f2da5982c567c6121c5d62f9b5b959}{xchan}}-\/>\mbox{\hyperlink{structxdma__channel_a0f4fc71c54e8c471d48be7f6141312b3}{sg}}, M\_XDMA);}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00066}00066 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00067}00067         \mbox{\hyperlink{xdma__if_8m_ab9f2da5982c567c6121c5d62f9b5b959}{xchan}}-\/>\mbox{\hyperlink{structxdma__channel_aa2f4e74343b931b260a2590290e4e557}{flags}} \&= \string~XCHAN\_SGLIST\_ALLOCATED;}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00068}00068 \}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00069}00069 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00070}00070 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00071}\mbox{\hyperlink{xdma_8h_ad8fb727e5cc84b4beeb407fc1299d877}{00071}} \mbox{\hyperlink{xdma__sglist_8c_ad8fb727e5cc84b4beeb407fc1299d877}{xdma\_sglist\_add}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structxdma__sglist}{xdma\_sglist}} *\mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}, \textcolor{keyword}{struct} bus\_dma\_segment *seg,}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00072}00072     uint32\_t nsegs, \textcolor{keyword}{struct} \mbox{\hyperlink{structxdma__request}{xdma\_request}} *xr)}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00073}00073 \{}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00074}00074         \textcolor{keywordtype}{int} i;}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00075}00075 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00076}00076         \textcolor{keywordflow}{if} (nsegs == 0)}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00077}00077                 \textcolor{keywordflow}{return} (-\/1);}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00078}00078 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00079}00079         \textcolor{keywordflow}{for} (i = 0; i < nsegs; i++) \{}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00080}00080                 \mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}[i].\mbox{\hyperlink{structxdma__sglist_ada83c03062979cdfc176777b74598036}{src\_width}} = xr-\/>\mbox{\hyperlink{structxdma__request_a5036cbac788a75d8536102046a6672df}{src\_width}};}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00081}00081                 \mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}[i].\mbox{\hyperlink{structxdma__sglist_a93c29a9b4e471d7264fd7239a20bfa56}{dst\_width}} = xr-\/>\mbox{\hyperlink{structxdma__request_abb800ef67643eb0385986f60d20ab652}{dst\_width}};}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00082}00082 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00083}00083                 \textcolor{keywordflow}{if} (xr-\/>\mbox{\hyperlink{structxdma__request_a5c49879fe6bd892f0ee8ae5b8d537e89}{direction}} == \mbox{\hyperlink{xdma_8h_a2e8ca3bcdbd1e0e6968dfb054dbe32b0a7af1f5353c6778f5d12cd5385652a4ed}{XDMA\_MEM\_TO\_DEV}}) \{}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00084}00084                         \mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}[i].\mbox{\hyperlink{structxdma__sglist_a77a43d0d2e1ca61d68ce757c90bc0bed}{src\_addr}} = seg[i].ds\_addr;}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00085}00085                         \mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}[i].\mbox{\hyperlink{structxdma__sglist_ab12db1cd93c922aef9b4026de05b7579}{dst\_addr}} = xr-\/>\mbox{\hyperlink{structxdma__request_a06717a34a385807d155948cede738bd1}{dst\_addr}};}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00086}00086                 \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00087}00087                         \mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}[i].\mbox{\hyperlink{structxdma__sglist_a77a43d0d2e1ca61d68ce757c90bc0bed}{src\_addr}} = xr-\/>\mbox{\hyperlink{structxdma__request_a6bb85f47eeb0145fadac3960dddbbc16}{src\_addr}};}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00088}00088                         \mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}[i].\mbox{\hyperlink{structxdma__sglist_ab12db1cd93c922aef9b4026de05b7579}{dst\_addr}} = seg[i].ds\_addr;}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00089}00089                 \}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00090}00090                 \mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}[i].\mbox{\hyperlink{structxdma__sglist_a2a66b35f39b69313d514dd32b21b223c}{len}} = seg[i].ds\_len;}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00091}00091                 \mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}[i].\mbox{\hyperlink{structxdma__sglist_a0dd89fa38e7ebdd1a6fb13faa4c9f33f}{direction}} = xr-\/>\mbox{\hyperlink{structxdma__request_a5c49879fe6bd892f0ee8ae5b8d537e89}{direction}};}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00092}00092 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00093}00093                 \mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}[i].\mbox{\hyperlink{structxdma__sglist_a7d004140ce84d9a7a64ca90c737998f9}{first}} = 0;}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00094}00094                 \mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}[i].\mbox{\hyperlink{structxdma__sglist_a20511b83fd5469c1e7a7d708a9014d3c}{last}} = 0;}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00095}00095         \}}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00096}00096 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00097}00097         \mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}[0].\mbox{\hyperlink{structxdma__sglist_a7d004140ce84d9a7a64ca90c737998f9}{first}} = 1;}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00098}00098         \mbox{\hyperlink{xdma__if_8m_a549564cf1ee19d210731b0653f5faa28}{sg}}[nsegs -\/ 1].\mbox{\hyperlink{structxdma__sglist_a20511b83fd5469c1e7a7d708a9014d3c}{last}} = 1;}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00099}00099 }
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00100}00100         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{xdma__sglist_8c_source_l00101}00101 \}}

\end{DoxyCode}
