From 54b150fc32374921cb583d129c439b5704744dc4 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 18 May 2018 15:11:42 +0200 Subject: Implement surface read --- pci.c | 6 ++++-- surface.c | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pci.c b/pci.c index dd31f57..e747118 100644 --- a/pci.c +++ b/pci.c @@ -9,7 +9,8 @@ #include "harddoomdev.h" #include "private_data.h" -int init_pci(struct pci_dev *dev) { +int init_pci(struct pci_dev *dev) +{ struct doom_data *doom_data; int err = 0; @@ -39,7 +40,8 @@ error_enable: return err; } -void cleanup_pci(struct pci_dev *dev) { +void cleanup_pci(struct pci_dev *dev) +{ struct doom_data *doom_data; doom_data = pci_get_drvdata(dev); diff --git a/surface.c b/surface.c index 4020a31..fd5d37b 100644 --- a/surface.c +++ b/surface.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "private_data.h" #include "harddoom.h" @@ -17,7 +18,22 @@ long surface_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ssize_t surface_read(struct file *filp, char __user *buf, size_t count, loff_t *offset) { - return -1; + struct surface_data *surface_data; + unsigned long not_written; + + surface_data = filp->private_data; + if (*offset >= surface_data->surface_size) { + return 0; + } + + if (*offset + count > surface_data->surface_size) { + count = surface_data->surface_size - *offset; + } + + not_written = copy_to_user(buf, surface_data->surface_cpu + *offset, + count); + + return count - not_written; } loff_t surface_llseek(struct file *filp, loff_t offset, int origin) -- cgit v1.2.3