Changeset 3ecc02e in mainline


Ignore:
Timestamp:
2009-05-21T20:06:31Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
16d17ca
Parents:
ae55ee8
Message:

Allow arbitrary block size in gxe_bd. Fix offset calculation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/gxe_bd/gxe_bd.c

    rae55ee8 r3ecc02e  
    8585} gxe_buf_t;
    8686
    87 static size_t maxblock_size = 512;
     87static const size_t block_size = 512;
     88static size_t comm_size;
     89
    8890static uintptr_t dev_physical = 0x13000000;
    8991static gxe_bd_t *dev;
     
    9698static int gxe_bd_init(void);
    9799static void gxe_bd_connection(ipc_callid_t iid, ipc_call_t *icall);
    98 static int gxe_bd_read_block(uint64_t offset, size_t block_size, void *buf);
    99 static int gxe_bd_write_block(uint64_t offset, size_t block_size,
    100     const void *buf);
     100static int gx_bd_rdwr(ipcarg_t method, off_t offset, off_t size, void *buf);
     101static int gxe_bd_read_block(uint64_t offset, size_t size, void *buf);
     102static int gxe_bd_write_block(uint64_t offset, size_t size, const void *buf);
    101103
    102104int main(int argc, char **argv)
     
    157159        ipc_callid_t callid;
    158160        ipc_call_t call;
     161        ipcarg_t method;
    159162        int flags;
    160163        int retval;
    161         off_t offset;
    162         size_t block_size;
     164        off_t idx;
     165        off_t size;
    163166
    164167        /* Answer the IPC_M_CONNECT_ME_TO call. */
    165168        ipc_answer_0(iid, EOK);
    166169
    167         if (!ipc_share_out_receive(&callid, &maxblock_size, &flags)) {
     170        if (!ipc_share_out_receive(&callid, &comm_size, &flags)) {
    168171                ipc_answer_0(callid, EHANGUP);
    169172                return;
    170173        }
    171         maxblock_size = 512;
    172 
    173         fs_va = as_get_mappable_page(maxblock_size);
     174
     175        fs_va = as_get_mappable_page(comm_size);
    174176        if (fs_va == NULL) {
    175177                ipc_answer_0(callid, EHANGUP);
     
    181183        while (1) {
    182184                callid = async_get_call(&call);
    183                 switch (IPC_GET_METHOD(call)) {
     185                method = IPC_GET_METHOD(call);
     186                switch (method) {
    184187                case IPC_M_PHONE_HUNGUP:
    185188                        /* The other side has hung up. */
     
    187190                        return;
    188191                case BD_READ_BLOCK:
    189                         offset = IPC_GET_ARG1(call);
    190                         block_size = IPC_GET_ARG2(call);
    191                         retval = gxe_bd_read_block(offset, block_size, fs_va);
    192                         break;
    193192                case BD_WRITE_BLOCK:
    194                         offset = IPC_GET_ARG1(call);
    195                         block_size = IPC_GET_ARG2(call);
    196                         retval = gxe_bd_write_block(offset, block_size, fs_va);
     193                        idx = IPC_GET_ARG1(call);
     194                        size = IPC_GET_ARG2(call);
     195                        if (size > comm_size) {
     196                                retval = EINVAL;
     197                                break;
     198                        }
     199                        retval = gx_bd_rdwr(method, idx * size, size, fs_va);
    197200                        break;
    198201                default:
     
    204207}
    205208
    206 static int gxe_bd_read_block(uint64_t offset, size_t block_size, void *buf)
     209static int gx_bd_rdwr(ipcarg_t method, off_t offset, off_t size, void *buf)
     210{
     211        int rc;
     212        size_t now;
     213
     214        while (size > 0) {
     215                now = size < block_size ? size : block_size;
     216
     217                if (method == BD_READ_BLOCK)
     218                        rc = gxe_bd_read_block(offset, now, buf);
     219                else
     220                        rc = gxe_bd_write_block(offset, now, buf);
     221
     222                if (rc != EOK)
     223                        return rc;
     224
     225                buf += block_size;
     226                offset += block_size;
     227
     228                if (size > block_size)
     229                        size -= block_size;
     230                else
     231                        size = 0;
     232        }
     233
     234        return EOK;
     235}
     236
     237static int gxe_bd_read_block(uint64_t offset, size_t size, void *buf)
    207238{
    208239        uint32_t status;
    209240        size_t i;
    210241        uint32_t w;
    211 
    212         if (block_size != maxblock_size) {
    213                 printf("Failed: bs = %d, mbs = %d\n", block_size,
    214                     maxblock_size);
    215                 return EINVAL;
    216         }
    217242
    218243        futex_down(&dev_futex);
     
    227252        }
    228253
    229         for (i = 0; i < maxblock_size; i++) {
     254        for (i = 0; i < size; i++) {
    230255                ((uint8_t *) buf)[i] = w =
    231256                    pio_read_8(&devbuf->buffer[i]);
     
    236261}
    237262
    238 static int gxe_bd_write_block(uint64_t offset, size_t block_size,
    239     const void *buf)
     263static int gxe_bd_write_block(uint64_t offset, size_t size, const void *buf)
    240264{
    241265        uint32_t status;
     
    243267        uint32_t w;
    244268
    245         if (block_size != maxblock_size) {
    246                 printf("Failed: bs = %d, mbs = %d\n", block_size,
    247                     maxblock_size);
    248                 return EINVAL;
    249         }
    250 
    251         for (i = 0; i < maxblock_size; i++) {
     269        for (i = 0; i < size; i++) {
    252270                pio_write_8(&devbuf->buffer[i], ((const uint8_t *) buf)[i]);
    253271        }
Note: See TracChangeset for help on using the changeset viewer.