[b402dadd] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Jiri Michalec
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup libc
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <ipc/dev_iface.h>
|
---|
| 36 | #include <assert.h>
|
---|
| 37 | #include <device/pci.h>
|
---|
| 38 | #include <errno.h>
|
---|
| 39 | #include <async.h>
|
---|
| 40 | #include <ipc/services.h>
|
---|
| 41 |
|
---|
| 42 | int pci_config_space_read_8(async_sess_t *sess, uint32_t address, uint8_t *val)
|
---|
| 43 | {
|
---|
| 44 | sysarg_t res = 0;
|
---|
| 45 |
|
---|
| 46 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 47 | int rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
|
---|
| 48 | IPC_M_CONFIG_SPACE_READ_8, address, &res);
|
---|
| 49 | async_exchange_end(exch);
|
---|
| 50 |
|
---|
| 51 | *val = (uint8_t) res;
|
---|
| 52 | return rc;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | int pci_config_space_read_16(async_sess_t *sess, uint32_t address,
|
---|
| 56 | uint16_t *val)
|
---|
| 57 | {
|
---|
| 58 | sysarg_t res = 0;
|
---|
| 59 |
|
---|
| 60 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 61 | int rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
|
---|
| 62 | IPC_M_CONFIG_SPACE_READ_16, address, &res);
|
---|
| 63 | async_exchange_end(exch);
|
---|
| 64 |
|
---|
| 65 | *val = (uint16_t) res;
|
---|
| 66 | return rc;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | int pci_config_space_read_32(async_sess_t *sess, uint32_t address,
|
---|
| 70 | uint32_t *val)
|
---|
| 71 | {
|
---|
| 72 | sysarg_t res = 0;
|
---|
| 73 |
|
---|
| 74 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 75 | int rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
|
---|
| 76 | IPC_M_CONFIG_SPACE_READ_32, address, &res);
|
---|
| 77 | async_exchange_end(exch);
|
---|
| 78 |
|
---|
| 79 | *val = (uint32_t) res;
|
---|
| 80 | return rc;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | int pci_config_space_write_8(async_sess_t *sess, uint32_t address, uint8_t val)
|
---|
| 84 | {
|
---|
| 85 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 86 | int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
|
---|
| 87 | IPC_M_CONFIG_SPACE_WRITE_8, address, val);
|
---|
| 88 | async_exchange_end(exch);
|
---|
| 89 |
|
---|
| 90 | return rc;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | int pci_config_space_write_16(async_sess_t *sess, uint32_t address,
|
---|
| 94 | uint16_t val)
|
---|
| 95 | {
|
---|
| 96 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 97 | int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
|
---|
| 98 | IPC_M_CONFIG_SPACE_WRITE_16, address, val);
|
---|
| 99 | async_exchange_end(exch);
|
---|
| 100 |
|
---|
| 101 | return rc;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | int pci_config_space_write_32(async_sess_t *sess, uint32_t address,
|
---|
| 105 | uint32_t val)
|
---|
| 106 | {
|
---|
| 107 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 108 | int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
|
---|
| 109 | IPC_M_CONFIG_SPACE_WRITE_32, address, val);
|
---|
| 110 | async_exchange_end(exch);
|
---|
| 111 |
|
---|
| 112 | return rc;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | /** @}
|
---|
| 116 | */
|
---|