@@ -861,6 +861,90 @@ static void tsi721_init_pc2sr_mapping(struct tsi721_device *priv)
861861 iowrite32 (0 , priv -> regs + TSI721_OBWINLB (i ));
862862}
863863
864+ /**
865+ * tsi721_rio_map_inb_mem -- Mapping inbound memory region.
866+ * @mport: RapidIO master port
867+ * @lstart: Local memory space start address.
868+ * @rstart: RapidIO space start address.
869+ * @size: The mapping region size.
870+ * @flags: Flags for mapping. 0 for using default flags.
871+ *
872+ * Return: 0 -- Success.
873+ *
874+ * This function will create the inbound mapping
875+ * from rstart to lstart.
876+ */
877+ static int tsi721_rio_map_inb_mem (struct rio_mport * mport , dma_addr_t lstart ,
878+ u64 rstart , u32 size , u32 flags )
879+ {
880+ struct tsi721_device * priv = mport -> priv ;
881+ int i ;
882+ u32 regval ;
883+
884+ if (!is_power_of_2 (size ) || size < 0x1000 ||
885+ ((u64 )lstart & (size - 1 )) || (rstart & (size - 1 )))
886+ return - EINVAL ;
887+
888+ /* Search for free inbound translation window */
889+ for (i = 0 ; i < TSI721_IBWIN_NUM ; i ++ ) {
890+ regval = ioread32 (priv -> regs + TSI721_IBWIN_LB (i ));
891+ if (!(regval & TSI721_IBWIN_LB_WEN ))
892+ break ;
893+ }
894+
895+ if (i >= TSI721_IBWIN_NUM ) {
896+ dev_err (& priv -> pdev -> dev ,
897+ "Unable to find free inbound window\n" );
898+ return - EBUSY ;
899+ }
900+
901+ iowrite32 (TSI721_IBWIN_SIZE (size ) << 8 ,
902+ priv -> regs + TSI721_IBWIN_SZ (i ));
903+
904+ iowrite32 (((u64 )lstart >> 32 ), priv -> regs + TSI721_IBWIN_TUA (i ));
905+ iowrite32 (((u64 )lstart & TSI721_IBWIN_TLA_ADD ),
906+ priv -> regs + TSI721_IBWIN_TLA (i ));
907+
908+ iowrite32 (rstart >> 32 , priv -> regs + TSI721_IBWIN_UB (i ));
909+ iowrite32 ((rstart & TSI721_IBWIN_LB_BA ) | TSI721_IBWIN_LB_WEN ,
910+ priv -> regs + TSI721_IBWIN_LB (i ));
911+ dev_dbg (& priv -> pdev -> dev ,
912+ "Configured IBWIN%d mapping (RIO_0x%llx -> PCIe_0x%llx)\n" ,
913+ i , rstart , (unsigned long long )lstart );
914+
915+ return 0 ;
916+ }
917+
918+ /**
919+ * fsl_rio_unmap_inb_mem -- Unmapping inbound memory region.
920+ * @mport: RapidIO master port
921+ * @lstart: Local memory space start address.
922+ */
923+ static void tsi721_rio_unmap_inb_mem (struct rio_mport * mport ,
924+ dma_addr_t lstart )
925+ {
926+ struct tsi721_device * priv = mport -> priv ;
927+ int i ;
928+ u64 addr ;
929+ u32 regval ;
930+
931+ /* Search for matching active inbound translation window */
932+ for (i = 0 ; i < TSI721_IBWIN_NUM ; i ++ ) {
933+ regval = ioread32 (priv -> regs + TSI721_IBWIN_LB (i ));
934+ if (regval & TSI721_IBWIN_LB_WEN ) {
935+ regval = ioread32 (priv -> regs + TSI721_IBWIN_TUA (i ));
936+ addr = (u64 )regval << 32 ;
937+ regval = ioread32 (priv -> regs + TSI721_IBWIN_TLA (i ));
938+ addr |= regval & TSI721_IBWIN_TLA_ADD ;
939+
940+ if (addr == (u64 )lstart ) {
941+ iowrite32 (0 , priv -> regs + TSI721_IBWIN_LB (i ));
942+ break ;
943+ }
944+ }
945+ }
946+ }
947+
864948/**
865949 * tsi721_init_sr2pc_mapping - initializes inbound (SRIO->PCIe)
866950 * translation regions.
@@ -874,7 +958,7 @@ static void tsi721_init_sr2pc_mapping(struct tsi721_device *priv)
874958
875959 /* Disable all SR2PC inbound windows */
876960 for (i = 0 ; i < TSI721_IBWIN_NUM ; i ++ )
877- iowrite32 (0 , priv -> regs + TSI721_IBWINLB (i ));
961+ iowrite32 (0 , priv -> regs + TSI721_IBWIN_LB (i ));
878962}
879963
880964/**
@@ -2144,6 +2228,8 @@ static int __devinit tsi721_setup_mport(struct tsi721_device *priv)
21442228 ops -> add_outb_message = tsi721_add_outb_message ;
21452229 ops -> add_inb_buffer = tsi721_add_inb_buffer ;
21462230 ops -> get_inb_message = tsi721_get_inb_message ;
2231+ ops -> map_inb = tsi721_rio_map_inb_mem ;
2232+ ops -> unmap_inb = tsi721_rio_unmap_inb_mem ;
21472233
21482234 mport = kzalloc (sizeof (struct rio_mport ), GFP_KERNEL );
21492235 if (!mport ) {
0 commit comments