Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/block/ahci/ahci.c

    rf9b2cb4c racdb5bac  
    3737#include <ddf/log.h>
    3838#include <device/hw_res_parsed.h>
    39 #include <pci_dev_iface.h>
    40 #include <irc.h>
     39#include <device/pci.h>
     40#include <sysinfo.h>
     41#include <ipc/irc.h>
     42#include <ns.h>
    4143#include <ahci_iface.h>
    4244#include "ahci.h"
     
    109111        }
    110112
    111 static int get_sata_device_name(ddf_fun_t *, size_t, char *);
    112 static int get_num_blocks(ddf_fun_t *, uint64_t *);
    113 static int get_block_size(ddf_fun_t *, size_t *);
    114 static int read_blocks(ddf_fun_t *, uint64_t, size_t, void *);
    115 static int write_blocks(ddf_fun_t *, uint64_t, size_t, void *);
     113static int ahci_get_sata_device_name(ddf_fun_t *, size_t, char *);
     114static int ahci_get_num_blocks(ddf_fun_t *, uint64_t *);
     115static int ahci_get_block_size(ddf_fun_t *, size_t *);
     116static int ahci_read_blocks(ddf_fun_t *, uint64_t, size_t, void *);
     117static int ahci_write_blocks(ddf_fun_t *, uint64_t, size_t, void *);
    116118
    117119static int ahci_identify_device(sata_dev_t *);
    118120static int ahci_set_highest_ultra_dma_mode(sata_dev_t *);
    119 static int ahci_rb_fpdma(sata_dev_t *, uintptr_t, uint64_t);
    120 static int ahci_wb_fpdma(sata_dev_t *, uintptr_t, uint64_t);
     121static int ahci_rb_fpdma(sata_dev_t *, void *, uint64_t);
     122static int ahci_wb_fpdma(sata_dev_t *, void *, uint64_t);
    121123
    122124static void ahci_sata_devices_create(ahci_dev_t *, ddf_dev_t *);
     
    127129
    128130static void ahci_get_model_name(uint16_t *, char *);
     131static int ahci_enable_interrupt(int);
    129132
    130133static fibril_mutex_t sata_devices_count_lock;
     
    136139
    137140static ahci_iface_t ahci_interface = {
    138         .get_sata_device_name = &get_sata_device_name,
    139         .get_num_blocks = &get_num_blocks,
    140         .get_block_size = &get_block_size,
    141         .read_blocks = &read_blocks,
    142         .write_blocks = &write_blocks
     141        .get_sata_device_name = &ahci_get_sata_device_name,
     142        .get_num_blocks = &ahci_get_num_blocks,
     143        .get_block_size = &ahci_get_block_size,
     144        .read_blocks = &ahci_read_blocks,
     145        .write_blocks = &ahci_write_blocks
    143146};
    144147
     
    177180 *
    178181 */
    179 static int get_sata_device_name(ddf_fun_t *fun,
     182static int ahci_get_sata_device_name(ddf_fun_t *fun,
    180183    size_t sata_dev_name_length, char *sata_dev_name)
    181184{
     
    193196 *
    194197 */
    195 static int get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks)
     198static int ahci_get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks)
    196199{
    197200        sata_dev_t *sata = fun_sata_dev(fun);
     
    208211 *
    209212 */
    210 static int get_block_size(ddf_fun_t *fun, size_t *block_size)
     213static int ahci_get_block_size(ddf_fun_t *fun, size_t *block_size)
    211214{
    212215        sata_dev_t *sata = fun_sata_dev(fun);
     
    225228 *
    226229 */
    227 static int read_blocks(ddf_fun_t *fun, uint64_t blocknum,
     230static int ahci_read_blocks(ddf_fun_t *fun, uint64_t blocknum,
    228231    size_t count, void *buf)
    229232{
    230233        sata_dev_t *sata = fun_sata_dev(fun);
    231234       
    232         uintptr_t phys;
    233         void *ibuf = AS_AREA_ANY;
    234         int rc = dmamem_map_anonymous(sata->block_size, DMAMEM_4GiB,
    235             AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &ibuf);
     235        void *phys;
     236        void *ibuf;
     237        int rc = dmamem_map_anonymous(sata->block_size, AS_AREA_READ | AS_AREA_WRITE,
     238            0, &phys, (void **) &ibuf);
    236239        if (rc != EOK) {
    237240                ddf_msg(LVL_ERROR, "Cannot allocate read buffer.");
     
    268271 *
    269272 */
    270 static int write_blocks(ddf_fun_t *fun, uint64_t blocknum,
     273static int ahci_write_blocks(ddf_fun_t *fun, uint64_t blocknum,
    271274    size_t count, void *buf)
    272275{
    273276        sata_dev_t *sata = fun_sata_dev(fun);
    274277       
    275         uintptr_t phys;
    276         void *ibuf = AS_AREA_ANY;
    277         int rc = dmamem_map_anonymous(sata->block_size, DMAMEM_4GiB,
    278             AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &ibuf);
     278        void *phys;
     279        void *ibuf;
     280        int rc = dmamem_map_anonymous(sata->block_size, AS_AREA_READ | AS_AREA_WRITE,
     281            0, &phys, (void **) &ibuf);
    279282        if (rc != EOK) {
    280283                ddf_msg(LVL_ERROR, "Cannot allocate write buffer.");
     
    333336 *
    334337 */
    335 static void ahci_identify_device_cmd(sata_dev_t *sata, uintptr_t phys)
     338static void ahci_identify_device_cmd(sata_dev_t *sata, void *phys)
    336339{
    337340        volatile sata_std_command_frame_t *cmd =
     
    378381 *
    379382 */
    380 static void ahci_identify_packet_device_cmd(sata_dev_t *sata, uintptr_t phys)
     383static void ahci_identify_packet_device_cmd(sata_dev_t *sata, void *phys)
    381384{
    382385        volatile sata_std_command_frame_t *cmd =
     
    432435        }
    433436       
    434         uintptr_t phys;
    435         sata_identify_data_t *idata = AS_AREA_ANY;
     437        void *phys;
     438        sata_identify_data_t *idata;
    436439        int rc = dmamem_map_anonymous(SATA_IDENTIFY_DEVICE_BUFFER_LENGTH,
    437             DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
    438             (void *) &idata);
     440            AS_AREA_READ | AS_AREA_WRITE, 0, &phys, (void **) &idata);
    439441        if (rc != EOK) {
    440442                ddf_msg(LVL_ERROR, "Cannot allocate buffer to identify device.");
     
    559561 *
    560562 */
    561 static void ahci_set_mode_cmd(sata_dev_t *sata, uintptr_t phys, uint8_t mode)
     563static void ahci_set_mode_cmd(sata_dev_t *sata, void* phys, uint8_t mode)
    562564{
    563565        volatile sata_std_command_frame_t *cmd =
     
    565567       
    566568        cmd->fis_type = SATA_CMD_FIS_TYPE;
    567         cmd->c = SATA_CMD_FIS_COMMAND_INDICATOR;
     569        cmd->c = SATA_CMD_FIS_COMMAND_INDICATOR; 
    568570        cmd->command = 0xef;
    569571        cmd->features = 0x03;
     
    626628        }
    627629       
    628         uintptr_t phys;
    629         sata_identify_data_t *idata = AS_AREA_ANY;
     630        void *phys;
     631        sata_identify_data_t *idata;
    630632        int rc = dmamem_map_anonymous(SATA_SET_FEATURE_BUFFER_LENGTH,
    631             DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
    632             (void *) &idata);
     633            AS_AREA_READ | AS_AREA_WRITE, 0, &phys, (void **) &idata);
    633634        if (rc != EOK) {
    634635                ddf_msg(LVL_ERROR, "Cannot allocate buffer for device set mode.");
     
    676677 *
    677678 */
    678 static void ahci_rb_fpdma_cmd(sata_dev_t *sata, uintptr_t phys,
    679     uint64_t blocknum)
     679static void ahci_rb_fpdma_cmd(sata_dev_t *sata, void *phys, uint64_t blocknum)
    680680{
    681681        volatile sata_ncq_command_frame_t *cmd =
     
    734734 *
    735735 */
    736 static int ahci_rb_fpdma(sata_dev_t *sata, uintptr_t phys, uint64_t blocknum)
     736static int ahci_rb_fpdma(sata_dev_t *sata, void *phys, uint64_t blocknum)
    737737{
    738738        if (sata->is_invalid_device) {
     
    763763 *
    764764 */
    765 static void ahci_wb_fpdma_cmd(sata_dev_t *sata, uintptr_t phys,
    766     uint64_t blocknum)
     765static void ahci_wb_fpdma_cmd(sata_dev_t *sata, void *phys, uint64_t blocknum)
    767766{
    768767        volatile sata_ncq_command_frame_t *cmd =
     
    822821 *
    823822 */
    824 static int ahci_wb_fpdma(sata_dev_t *sata, uintptr_t phys, uint64_t blocknum)
     823static int ahci_wb_fpdma(sata_dev_t *sata, void *phys, uint64_t blocknum)
    825824{
    826825        if (sata->is_invalid_device) {
     
    890889/** AHCI interrupt handler.
    891890 *
     891 * @param dev   DDF device structure.
    892892 * @param iid   The IPC call id.
    893893 * @param icall The IPC call structure.
    894  * @param dev   DDF device structure.
    895  *
    896  */
    897 static void ahci_interrupt(ipc_callid_t iid, ipc_call_t *icall, ddf_dev_t *dev)
     894 *
     895 */
     896static void ahci_interrupt(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *icall)
    898897{
    899898        ahci_dev_t *ahci = dev_ahci_dev(dev);
     
    934933{
    935934        size_t size = 4096;
    936         uintptr_t phys = 0;
    937         void *virt_fb = AS_AREA_ANY;
    938         void *virt_cmd = AS_AREA_ANY;
    939         void *virt_table = AS_AREA_ANY;
     935        void *phys = NULL;
     936        void *virt_fb = NULL;
     937        void *virt_cmd = NULL;
     938        void *virt_table = NULL;
    940939        ddf_fun_t *fun;
    941940       
     
    950949       
    951950        /* Allocate and init retfis structure. */
    952         int rc = dmamem_map_anonymous(size, DMAMEM_4GiB,
    953             AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &virt_fb);
     951        int rc = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE, 0,
     952            &phys, &virt_fb);
    954953        if (rc != EOK)
    955954                goto error_retfis;
     
    960959       
    961960        /* Allocate and init command header structure. */
    962         rc = dmamem_map_anonymous(size, DMAMEM_4GiB,
    963             AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &virt_cmd);
     961        rc = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE, 0,
     962            &phys, &virt_cmd);
    964963        if (rc != EOK)
    965964                goto error_cmd;
     
    971970       
    972971        /* Allocate and init command table structure. */
    973         rc = dmamem_map_anonymous(size, DMAMEM_4GiB,
    974             AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &virt_table);
     972        rc = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE, 0,
     973            &phys, &virt_table);
    975974        if (rc != EOK)
    976975                goto error_table;
     
    11401139       
    11411140        /* Connect to parent device */
    1142         ahci->parent_sess = ddf_dev_parent_sess_create(dev);
     1141        ahci->parent_sess = ddf_dev_parent_sess_create(dev, EXCHANGE_SERIALIZE);
    11431142        if (ahci->parent_sess == NULL)
    11441143                return NULL;
     
    11521151       
    11531152        /* Map AHCI registers. */
    1154         ahci->memregs = AS_AREA_ANY;
    1155        
    1156         physmem_map(RNGABS(hw_res_parsed.mem_ranges.ranges[0]),
     1153        ahci->memregs = NULL;
     1154       
     1155        physmem_map((void *) (size_t) (hw_res_parsed.mem_ranges.ranges[0].address),
    11571156            AHCI_MEMREGS_PAGES_COUNT, AS_AREA_READ | AS_AREA_WRITE,
    1158             (void *) &ahci->memregs);
     1157            (void **) &ahci->memregs);
    11591158        if (ahci->memregs == NULL)
    11601159                goto error_map_registers;
    11611160       
    11621161        /* Register interrupt handler */
    1163         ahci_ranges[0].base = RNGABS(hw_res_parsed.mem_ranges.ranges[0]);
     1162        ahci_ranges[0].base = (size_t) hw_res_parsed.mem_ranges.ranges[0].address;
    11641163        ahci_ranges[0].size = sizeof(ahci_memregs_t);
    11651164       
     
    11681167               
    11691168                ahci_cmds[base].addr =
    1170                     ((uint32_t *) RNGABSPTR(hw_res_parsed.mem_ranges.ranges[0])) +
     1169                    ((uint32_t *) (size_t) hw_res_parsed.mem_ranges.ranges[0].address) +
    11711170                    AHCI_PORTS_REGISTERS_OFFSET + port * AHCI_PORT_REGISTERS_SIZE +
    11721171                    AHCI_PORT_IS_REGISTER_OFFSET;
     
    11741173               
    11751174                ahci_cmds[base + 3].addr =
    1176                     ((uint32_t *) RNGABSPTR(hw_res_parsed.mem_ranges.ranges[0])) +
     1175                    ((uint32_t *) (size_t) hw_res_parsed.mem_ranges.ranges[0].address) +
    11771176                    AHCI_GHC_IS_REGISTER_OFFSET;
    11781177                ahci_cmds[base + 4].addr = ahci_cmds[base + 3].addr;
     
    11921191        }
    11931192       
    1194         rc = irc_enable_interrupt(hw_res_parsed.irqs.irqs[0]);
     1193        rc = ahci_enable_interrupt(hw_res_parsed.irqs.irqs[0]);
    11951194        if (rc != EOK) {
    11961195                ddf_msg(LVL_ERROR, "Failed enable interupt.");
     
    13121311}
    13131312
     1313/** Enable interrupt using SERVICE_IRC.
     1314 *
     1315 * @param irq Requested irq number.
     1316 *
     1317 * @return EOK if succeed, error code otherwise.
     1318 *
     1319 */
     1320static int ahci_enable_interrupt(int irq)
     1321{
     1322        async_sess_t *irc_sess = NULL;
     1323        irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_IRC, 0, 0);
     1324        if (!irc_sess)
     1325                return EINTR;
     1326       
     1327        async_exch_t *exch = async_exchange_begin(irc_sess);
     1328        const int rc = async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
     1329        async_exchange_end(exch);
     1330       
     1331        async_hangup(irc_sess);
     1332        return rc;
     1333}
     1334
    13141335/*----------------------------------------------------------------------------*/
    13151336/*-- AHCI Main routine -------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.