Ignore:
File:
1 edited

Legend:

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

    racdb5bac rf9b2cb4c  
    3737#include <ddf/log.h>
    3838#include <device/hw_res_parsed.h>
    39 #include <device/pci.h>
    40 #include <sysinfo.h>
    41 #include <ipc/irc.h>
    42 #include <ns.h>
     39#include <pci_dev_iface.h>
     40#include <irc.h>
    4341#include <ahci_iface.h>
    4442#include "ahci.h"
     
    111109        }
    112110
    113 static int ahci_get_sata_device_name(ddf_fun_t *, size_t, char *);
    114 static int ahci_get_num_blocks(ddf_fun_t *, uint64_t *);
    115 static int ahci_get_block_size(ddf_fun_t *, size_t *);
    116 static int ahci_read_blocks(ddf_fun_t *, uint64_t, size_t, void *);
    117 static int ahci_write_blocks(ddf_fun_t *, uint64_t, size_t, void *);
     111static int get_sata_device_name(ddf_fun_t *, size_t, char *);
     112static int get_num_blocks(ddf_fun_t *, uint64_t *);
     113static int get_block_size(ddf_fun_t *, size_t *);
     114static int read_blocks(ddf_fun_t *, uint64_t, size_t, void *);
     115static int write_blocks(ddf_fun_t *, uint64_t, size_t, void *);
    118116
    119117static int ahci_identify_device(sata_dev_t *);
    120118static int ahci_set_highest_ultra_dma_mode(sata_dev_t *);
    121 static int ahci_rb_fpdma(sata_dev_t *, void *, uint64_t);
    122 static int ahci_wb_fpdma(sata_dev_t *, void *, uint64_t);
     119static int ahci_rb_fpdma(sata_dev_t *, uintptr_t, uint64_t);
     120static int ahci_wb_fpdma(sata_dev_t *, uintptr_t, uint64_t);
    123121
    124122static void ahci_sata_devices_create(ahci_dev_t *, ddf_dev_t *);
     
    129127
    130128static void ahci_get_model_name(uint16_t *, char *);
    131 static int ahci_enable_interrupt(int);
    132129
    133130static fibril_mutex_t sata_devices_count_lock;
     
    139136
    140137static ahci_iface_t ahci_interface = {
    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
     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
    146143};
    147144
     
    180177 *
    181178 */
    182 static int ahci_get_sata_device_name(ddf_fun_t *fun,
     179static int get_sata_device_name(ddf_fun_t *fun,
    183180    size_t sata_dev_name_length, char *sata_dev_name)
    184181{
     
    196193 *
    197194 */
    198 static int ahci_get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks)
     195static int get_num_blocks(ddf_fun_t *fun, uint64_t *num_blocks)
    199196{
    200197        sata_dev_t *sata = fun_sata_dev(fun);
     
    211208 *
    212209 */
    213 static int ahci_get_block_size(ddf_fun_t *fun, size_t *block_size)
     210static int get_block_size(ddf_fun_t *fun, size_t *block_size)
    214211{
    215212        sata_dev_t *sata = fun_sata_dev(fun);
     
    228225 *
    229226 */
    230 static int ahci_read_blocks(ddf_fun_t *fun, uint64_t blocknum,
     227static int read_blocks(ddf_fun_t *fun, uint64_t blocknum,
    231228    size_t count, void *buf)
    232229{
    233230        sata_dev_t *sata = fun_sata_dev(fun);
    234231       
    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);
     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);
    239236        if (rc != EOK) {
    240237                ddf_msg(LVL_ERROR, "Cannot allocate read buffer.");
     
    271268 *
    272269 */
    273 static int ahci_write_blocks(ddf_fun_t *fun, uint64_t blocknum,
     270static int write_blocks(ddf_fun_t *fun, uint64_t blocknum,
    274271    size_t count, void *buf)
    275272{
    276273        sata_dev_t *sata = fun_sata_dev(fun);
    277274       
    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);
     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);
    282279        if (rc != EOK) {
    283280                ddf_msg(LVL_ERROR, "Cannot allocate write buffer.");
     
    336333 *
    337334 */
    338 static void ahci_identify_device_cmd(sata_dev_t *sata, void *phys)
     335static void ahci_identify_device_cmd(sata_dev_t *sata, uintptr_t phys)
    339336{
    340337        volatile sata_std_command_frame_t *cmd =
     
    381378 *
    382379 */
    383 static void ahci_identify_packet_device_cmd(sata_dev_t *sata, void *phys)
     380static void ahci_identify_packet_device_cmd(sata_dev_t *sata, uintptr_t phys)
    384381{
    385382        volatile sata_std_command_frame_t *cmd =
     
    435432        }
    436433       
    437         void *phys;
    438         sata_identify_data_t *idata;
     434        uintptr_t phys;
     435        sata_identify_data_t *idata = AS_AREA_ANY;
    439436        int rc = dmamem_map_anonymous(SATA_IDENTIFY_DEVICE_BUFFER_LENGTH,
    440             AS_AREA_READ | AS_AREA_WRITE, 0, &phys, (void **) &idata);
     437            DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
     438            (void *) &idata);
    441439        if (rc != EOK) {
    442440                ddf_msg(LVL_ERROR, "Cannot allocate buffer to identify device.");
     
    561559 *
    562560 */
    563 static void ahci_set_mode_cmd(sata_dev_t *sata, void* phys, uint8_t mode)
     561static void ahci_set_mode_cmd(sata_dev_t *sata, uintptr_t phys, uint8_t mode)
    564562{
    565563        volatile sata_std_command_frame_t *cmd =
     
    567565       
    568566        cmd->fis_type = SATA_CMD_FIS_TYPE;
    569         cmd->c = SATA_CMD_FIS_COMMAND_INDICATOR; 
     567        cmd->c = SATA_CMD_FIS_COMMAND_INDICATOR;
    570568        cmd->command = 0xef;
    571569        cmd->features = 0x03;
     
    628626        }
    629627       
    630         void *phys;
    631         sata_identify_data_t *idata;
     628        uintptr_t phys;
     629        sata_identify_data_t *idata = AS_AREA_ANY;
    632630        int rc = dmamem_map_anonymous(SATA_SET_FEATURE_BUFFER_LENGTH,
    633             AS_AREA_READ | AS_AREA_WRITE, 0, &phys, (void **) &idata);
     631            DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 0, &phys,
     632            (void *) &idata);
    634633        if (rc != EOK) {
    635634                ddf_msg(LVL_ERROR, "Cannot allocate buffer for device set mode.");
     
    677676 *
    678677 */
    679 static void ahci_rb_fpdma_cmd(sata_dev_t *sata, void *phys, uint64_t blocknum)
     678static void ahci_rb_fpdma_cmd(sata_dev_t *sata, uintptr_t phys,
     679    uint64_t blocknum)
    680680{
    681681        volatile sata_ncq_command_frame_t *cmd =
     
    734734 *
    735735 */
    736 static int ahci_rb_fpdma(sata_dev_t *sata, void *phys, uint64_t blocknum)
     736static int ahci_rb_fpdma(sata_dev_t *sata, uintptr_t phys, uint64_t blocknum)
    737737{
    738738        if (sata->is_invalid_device) {
     
    763763 *
    764764 */
    765 static void ahci_wb_fpdma_cmd(sata_dev_t *sata, void *phys, uint64_t blocknum)
     765static void ahci_wb_fpdma_cmd(sata_dev_t *sata, uintptr_t phys,
     766    uint64_t blocknum)
    766767{
    767768        volatile sata_ncq_command_frame_t *cmd =
     
    821822 *
    822823 */
    823 static int ahci_wb_fpdma(sata_dev_t *sata, void *phys, uint64_t blocknum)
     824static int ahci_wb_fpdma(sata_dev_t *sata, uintptr_t phys, uint64_t blocknum)
    824825{
    825826        if (sata->is_invalid_device) {
     
    889890/** AHCI interrupt handler.
    890891 *
    891  * @param dev   DDF device structure.
    892892 * @param iid   The IPC call id.
    893893 * @param icall The IPC call structure.
    894  *
    895  */
    896 static void ahci_interrupt(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *icall)
     894 * @param dev   DDF device structure.
     895 *
     896 */
     897static void ahci_interrupt(ipc_callid_t iid, ipc_call_t *icall, ddf_dev_t *dev)
    897898{
    898899        ahci_dev_t *ahci = dev_ahci_dev(dev);
     
    933934{
    934935        size_t size = 4096;
    935         void *phys = NULL;
    936         void *virt_fb = NULL;
    937         void *virt_cmd = NULL;
    938         void *virt_table = NULL;
     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;
    939940        ddf_fun_t *fun;
    940941       
     
    949950       
    950951        /* Allocate and init retfis structure. */
    951         int rc = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE, 0,
    952             &phys, &virt_fb);
     952        int rc = dmamem_map_anonymous(size, DMAMEM_4GiB,
     953            AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &virt_fb);
    953954        if (rc != EOK)
    954955                goto error_retfis;
     
    959960       
    960961        /* Allocate and init command header structure. */
    961         rc = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE, 0,
    962             &phys, &virt_cmd);
     962        rc = dmamem_map_anonymous(size, DMAMEM_4GiB,
     963            AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &virt_cmd);
    963964        if (rc != EOK)
    964965                goto error_cmd;
     
    970971       
    971972        /* Allocate and init command table structure. */
    972         rc = dmamem_map_anonymous(size, AS_AREA_READ | AS_AREA_WRITE, 0,
    973             &phys, &virt_table);
     973        rc = dmamem_map_anonymous(size, DMAMEM_4GiB,
     974            AS_AREA_READ | AS_AREA_WRITE, 0, &phys, &virt_table);
    974975        if (rc != EOK)
    975976                goto error_table;
     
    11391140       
    11401141        /* Connect to parent device */
    1141         ahci->parent_sess = ddf_dev_parent_sess_create(dev, EXCHANGE_SERIALIZE);
     1142        ahci->parent_sess = ddf_dev_parent_sess_create(dev);
    11421143        if (ahci->parent_sess == NULL)
    11431144                return NULL;
     
    11511152       
    11521153        /* Map AHCI registers. */
    1153         ahci->memregs = NULL;
    1154        
    1155         physmem_map((void *) (size_t) (hw_res_parsed.mem_ranges.ranges[0].address),
     1154        ahci->memregs = AS_AREA_ANY;
     1155       
     1156        physmem_map(RNGABS(hw_res_parsed.mem_ranges.ranges[0]),
    11561157            AHCI_MEMREGS_PAGES_COUNT, AS_AREA_READ | AS_AREA_WRITE,
    1157             (void **) &ahci->memregs);
     1158            (void *) &ahci->memregs);
    11581159        if (ahci->memregs == NULL)
    11591160                goto error_map_registers;
    11601161       
    11611162        /* Register interrupt handler */
    1162         ahci_ranges[0].base = (size_t) hw_res_parsed.mem_ranges.ranges[0].address;
     1163        ahci_ranges[0].base = RNGABS(hw_res_parsed.mem_ranges.ranges[0]);
    11631164        ahci_ranges[0].size = sizeof(ahci_memregs_t);
    11641165       
     
    11671168               
    11681169                ahci_cmds[base].addr =
    1169                     ((uint32_t *) (size_t) hw_res_parsed.mem_ranges.ranges[0].address) +
     1170                    ((uint32_t *) RNGABSPTR(hw_res_parsed.mem_ranges.ranges[0])) +
    11701171                    AHCI_PORTS_REGISTERS_OFFSET + port * AHCI_PORT_REGISTERS_SIZE +
    11711172                    AHCI_PORT_IS_REGISTER_OFFSET;
     
    11731174               
    11741175                ahci_cmds[base + 3].addr =
    1175                     ((uint32_t *) (size_t) hw_res_parsed.mem_ranges.ranges[0].address) +
     1176                    ((uint32_t *) RNGABSPTR(hw_res_parsed.mem_ranges.ranges[0])) +
    11761177                    AHCI_GHC_IS_REGISTER_OFFSET;
    11771178                ahci_cmds[base + 4].addr = ahci_cmds[base + 3].addr;
     
    11911192        }
    11921193       
    1193         rc = ahci_enable_interrupt(hw_res_parsed.irqs.irqs[0]);
     1194        rc = irc_enable_interrupt(hw_res_parsed.irqs.irqs[0]);
    11941195        if (rc != EOK) {
    11951196                ddf_msg(LVL_ERROR, "Failed enable interupt.");
     
    13111312}
    13121313
    1313 /** Enable interrupt using SERVICE_IRC.
    1314  *
    1315  * @param irq Requested irq number.
    1316  *
    1317  * @return EOK if succeed, error code otherwise.
    1318  *
    1319  */
    1320 static 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 
    13351314/*----------------------------------------------------------------------------*/
    13361315/*-- AHCI Main routine -------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.