| [1] | 1 | /* |
|---|
| 2 | * kern/blkio.c - Per-page buffers I/O interface |
|---|
| 3 | * |
|---|
| 4 | * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless |
|---|
| 5 | * Copyright (c) 2011,2012 UPMC Sorbonne Universites |
|---|
| 6 | * |
|---|
| 7 | * This file is part of ALMOS-kernel. |
|---|
| 8 | * |
|---|
| 9 | * ALMOS-kernel is free software; you can redistribute it and/or modify it |
|---|
| 10 | * under the terms of the GNU General Public License as published by |
|---|
| 11 | * the Free Software Foundation; version 2.0 of the License. |
|---|
| 12 | * |
|---|
| 13 | * ALMOS-kernel is distributed in the hope that it will be useful, but |
|---|
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 16 | * General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * You should have received a copy of the GNU General Public License |
|---|
| 19 | * along with ALMOS-kernel; if not, write to the Free Software Foundation, |
|---|
| 20 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | #ifndef BLKIO_H_ |
|---|
| 24 | #define BLKIO_H_ |
|---|
| 25 | |
|---|
| 26 | #include <list.h> |
|---|
| 27 | |
|---|
| 28 | #define BLKIO_RD 0x01 |
|---|
| 29 | #define BLKIO_SYNC 0x02 |
|---|
| 30 | |
|---|
| 31 | #define BLKIO_INIT 0x01 |
|---|
| 32 | |
|---|
| 33 | #include <page.h> |
|---|
| 34 | #include <device.h> |
|---|
| 35 | #include <list.h> |
|---|
| 36 | |
|---|
| 37 | /****************************************************************************************** |
|---|
| 38 | *****************************************************************************************/ |
|---|
| 39 | typedef struct blkio_s |
|---|
| 40 | { |
|---|
| 41 | uint32_t b_flags; // BLKIO_INIT |
|---|
| 42 | |
|---|
| 43 | struct |
|---|
| 44 | { |
|---|
| 45 | spinlock_t lock; |
|---|
| 46 | uint16_t count; |
|---|
| 47 | uint16_t cntr; |
|---|
| 48 | error_t error; |
|---|
| 49 | struct wait_queue_s wait; |
|---|
| 50 | |
|---|
| 51 | } b_ctrl; // Only used in head-blkio |
|---|
| 52 | |
|---|
| 53 | dev_request_t b_dev_rq; // request for the block device |
|---|
| 54 | page_t * b_page; // buffer page descriptor |
|---|
| 55 | device_t * b_dev; // block device |
|---|
| 56 | slist_entry_t b_list; // next buffer in this page |
|---|
| 57 | void * b_private; // data for the I/O completion method |
|---|
| 58 | } |
|---|
| 59 | blkio_t; |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * Macro to set a blkio to be skiped while first sync |
|---|
| 63 | * |
|---|
| 64 | * @b pointer to blkio |
|---|
| 65 | */ |
|---|
| 66 | #define blkio_set_initial(b) \ |
|---|
| 67 | do{(b)->b_flags |= BLKIO_INIT;}while(0) |
|---|
| 68 | |
|---|
| 69 | KMEM_OBJATTR_INIT(blkio_kmem_init); |
|---|
| 70 | |
|---|
| 71 | /****************************************************************************************** |
|---|
| 72 | * Initializes the blkio structure. |
|---|
| 73 | ****************************************************************************************** |
|---|
| 74 | * @ dev : pointer on block device. |
|---|
| 75 | * @ page : buffer page to get blkio structures initialized |
|---|
| 76 | * @ count : number of blocks in the page |
|---|
| 77 | * @ return error code, 0 if OK |
|---|
| 78 | *****************************************************************************************/ |
|---|
| 79 | error_t blkio_init( device_t * dev, |
|---|
| 80 | page_t * page, |
|---|
| 81 | uint32_t count ); |
|---|
| 82 | |
|---|
| 83 | /** |
|---|
| 84 | * Synchronizes all the buffers in a buffer page. |
|---|
| 85 | * |
|---|
| 86 | * @page buffer page to be synced with the disk |
|---|
| 87 | * @flags blkio flags |
|---|
| 88 | * @return error code, 0 if OK |
|---|
| 89 | */ |
|---|
| 90 | error_t blkio_sync(struct page_s *page, uint_t flags); |
|---|
| 91 | |
|---|
| 92 | /** |
|---|
| 93 | * Destroys the blkio structures for a buffer page. |
|---|
| 94 | * |
|---|
| 95 | * @page buffer page to have its blkio structures destroyed |
|---|
| 96 | * @return error code, 0 if OK |
|---|
| 97 | */ |
|---|
| 98 | error_t blkio_destroy(struct page_s *page); |
|---|
| 99 | |
|---|
| 100 | #endif /* BLKIO_H_ */ |
|---|