Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syscall
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
8
Issues
8
List
Boards
Labels
Service Desk
Milestones
Merge Requests
9
Merge Requests
9
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
redox-os
syscall
Commits
6beba083
Commit
6beba083
authored
Feb 03, 2020
by
Jeremy Soller
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dma-slices' into 'master'
Allow Dma<[T]> See merge request
!42
parents
c969ac06
08a3800e
Pipeline
#6934
failed with stages
in 60 minutes and 52 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
7 deletions
+27
-7
src/io/dma.rs
src/io/dma.rs
+27
-7
No files found.
src/io/dma.rs
View file @
6beba083
...
...
@@ -24,7 +24,7 @@ impl Drop for PhysBox {
}
}
pub
struct
Dma
<
T
>
{
pub
struct
Dma
<
T
:
?
Sized
>
{
phys
:
PhysBox
,
virt
:
*
mut
T
}
...
...
@@ -49,28 +49,48 @@ impl<T> Dma<T> {
virt
:
virt
})
}
}
impl
<
T
:
?
Sized
>
Dma
<
T
>
{
pub
fn
physical
(
&
self
)
->
usize
{
self
.phys.address
}
}
impl
<
T
>
Deref
for
Dma
<
T
>
{
impl
<
T
>
Dma
<
[
T
]
>
{
/// Crates a new DMA buffer with a size only known at runtime.
/// ## Safety
/// * `T` must be properly aligned.
/// * `T` must be valid as zeroed (i.e. no NonNull pointers).
pub
unsafe
fn
zeroed_unsized
(
count
:
usize
)
->
Result
<
Self
>
{
let
phys
=
PhysBox
::
new
(
mem
::
size_of
::
<
T
>
()
*
count
)
?
;
let
virt_ptr
=
crate
::
physmap
(
phys
.address
,
phys
.size
,
crate
::
PHYSMAP_WRITE
)
?
as
*
mut
T
;
ptr
::
write_bytes
(
virt_ptr
,
0
,
count
);
let
virt
=
core
::
slice
::
from_raw_parts_mut
(
virt_ptr
,
count
);
Ok
(
Dma
{
phys
,
virt
,
})
}
}
impl
<
T
:
?
Sized
>
Deref
for
Dma
<
T
>
{
type
Target
=
T
;
fn
deref
(
&
self
)
->
&
T
{
unsafe
{
&*
self
.virt
}
}
}
impl
<
T
>
DerefMut
for
Dma
<
T
>
{
impl
<
T
:
?
Sized
>
DerefMut
for
Dma
<
T
>
{
fn
deref_mut
(
&
mut
self
)
->
&
mut
T
{
unsafe
{
&
mut
*
self
.virt
}
}
}
impl
<
T
>
Drop
for
Dma
<
T
>
{
impl
<
T
:
?
Sized
>
Drop
for
Dma
<
T
>
{
fn
drop
(
&
mut
self
)
{
unsafe
{
drop
(
ptr
::
read
(
self
.virt
));
}
let
_
=
unsafe
{
crate
::
physunmap
(
self
.virt
as
usize
)
};
unsafe
{
ptr
::
drop_in_place
(
self
.virt
)
}
let
_
=
unsafe
{
crate
::
physunmap
(
self
.virt
as
*
mut
u8
as
usize
)
};
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment