@@ -1591,6 +1591,68 @@ static void psp_ras_ta_check_status(struct psp_context *psp)
1591
1591
}
1592
1592
}
1593
1593
1594
+ static int psp_ras_send_cmd (struct psp_context * psp ,
1595
+ enum ras_command cmd_id , void * in , void * out )
1596
+ {
1597
+ struct ta_ras_shared_memory * ras_cmd ;
1598
+ uint32_t cmd = cmd_id ;
1599
+ int ret = 0 ;
1600
+
1601
+ if (!in )
1602
+ return - EINVAL ;
1603
+
1604
+ mutex_lock (& psp -> ras_context .mutex );
1605
+ ras_cmd = (struct ta_ras_shared_memory * )psp -> ras_context .context .mem_context .shared_buf ;
1606
+ memset (ras_cmd , 0 , sizeof (struct ta_ras_shared_memory ));
1607
+
1608
+ switch (cmd ) {
1609
+ case TA_RAS_COMMAND__ENABLE_FEATURES :
1610
+ case TA_RAS_COMMAND__DISABLE_FEATURES :
1611
+ memcpy (& ras_cmd -> ras_in_message ,
1612
+ in , sizeof (ras_cmd -> ras_in_message ));
1613
+ break ;
1614
+ case TA_RAS_COMMAND__TRIGGER_ERROR :
1615
+ memcpy (& ras_cmd -> ras_in_message .trigger_error ,
1616
+ in , sizeof (ras_cmd -> ras_in_message .trigger_error ));
1617
+ break ;
1618
+ case TA_RAS_COMMAND__QUERY_ADDRESS :
1619
+ memcpy (& ras_cmd -> ras_in_message .address ,
1620
+ in , sizeof (ras_cmd -> ras_in_message .address ));
1621
+ break ;
1622
+ default :
1623
+ dev_err (psp -> adev -> dev , "Invalid ras cmd id: %u\n" , cmd );
1624
+ ret = - EINVAL ;
1625
+ goto err_out ;
1626
+ }
1627
+
1628
+ ras_cmd -> cmd_id = cmd ;
1629
+ ret = psp_ras_invoke (psp , ras_cmd -> cmd_id );
1630
+
1631
+ switch (cmd ) {
1632
+ case TA_RAS_COMMAND__TRIGGER_ERROR :
1633
+ if (ret || psp -> cmd_buf_mem -> resp .status )
1634
+ ret = - EINVAL ;
1635
+ else if (out )
1636
+ memcpy (out , & ras_cmd -> ras_status , sizeof (ras_cmd -> ras_status ));
1637
+ break ;
1638
+ case TA_RAS_COMMAND__QUERY_ADDRESS :
1639
+ if (ret || ras_cmd -> ras_status || psp -> cmd_buf_mem -> resp .status )
1640
+ ret = - EINVAL ;
1641
+ else if (out )
1642
+ memcpy (out ,
1643
+ & ras_cmd -> ras_out_message .address ,
1644
+ sizeof (ras_cmd -> ras_out_message .address ));
1645
+ break ;
1646
+ default :
1647
+ break ;
1648
+ }
1649
+
1650
+ err_out :
1651
+ mutex_unlock (& psp -> ras_context .mutex );
1652
+
1653
+ return ret ;
1654
+ }
1655
+
1594
1656
int psp_ras_invoke (struct psp_context * psp , uint32_t ta_cmd_id )
1595
1657
{
1596
1658
struct ta_ras_shared_memory * ras_cmd ;
@@ -1632,23 +1694,15 @@ int psp_ras_invoke(struct psp_context *psp, uint32_t ta_cmd_id)
1632
1694
int psp_ras_enable_features (struct psp_context * psp ,
1633
1695
union ta_ras_cmd_input * info , bool enable )
1634
1696
{
1635
- struct ta_ras_shared_memory * ras_cmd ;
1697
+ enum ras_command cmd_id ;
1636
1698
int ret ;
1637
1699
1638
- if (!psp -> ras_context .context .initialized )
1700
+ if (!psp -> ras_context .context .initialized || ! info )
1639
1701
return - EINVAL ;
1640
1702
1641
- ras_cmd = (struct ta_ras_shared_memory * )psp -> ras_context .context .mem_context .shared_buf ;
1642
- memset (ras_cmd , 0 , sizeof (struct ta_ras_shared_memory ));
1643
-
1644
- if (enable )
1645
- ras_cmd -> cmd_id = TA_RAS_COMMAND__ENABLE_FEATURES ;
1646
- else
1647
- ras_cmd -> cmd_id = TA_RAS_COMMAND__DISABLE_FEATURES ;
1648
-
1649
- ras_cmd -> ras_in_message = * info ;
1650
-
1651
- ret = psp_ras_invoke (psp , ras_cmd -> cmd_id );
1703
+ cmd_id = enable ?
1704
+ TA_RAS_COMMAND__ENABLE_FEATURES : TA_RAS_COMMAND__DISABLE_FEATURES ;
1705
+ ret = psp_ras_send_cmd (psp , cmd_id , info , NULL );
1652
1706
if (ret )
1653
1707
return - EINVAL ;
1654
1708
@@ -1672,6 +1726,8 @@ int psp_ras_terminate(struct psp_context *psp)
1672
1726
1673
1727
psp -> ras_context .context .initialized = false;
1674
1728
1729
+ mutex_destroy (& psp -> ras_context .mutex );
1730
+
1675
1731
return ret ;
1676
1732
}
1677
1733
@@ -1756,9 +1812,10 @@ int psp_ras_initialize(struct psp_context *psp)
1756
1812
1757
1813
ret = psp_ta_load (psp , & psp -> ras_context .context );
1758
1814
1759
- if (!ret && !ras_cmd -> ras_status )
1815
+ if (!ret && !ras_cmd -> ras_status ) {
1760
1816
psp -> ras_context .context .initialized = true;
1761
- else {
1817
+ mutex_init (& psp -> ras_context .mutex );
1818
+ } else {
1762
1819
if (ras_cmd -> ras_status )
1763
1820
dev_warn (adev -> dev , "RAS Init Status: 0x%X\n" , ras_cmd -> ras_status );
1764
1821
@@ -1772,12 +1829,12 @@ int psp_ras_initialize(struct psp_context *psp)
1772
1829
int psp_ras_trigger_error (struct psp_context * psp ,
1773
1830
struct ta_ras_trigger_error_input * info , uint32_t instance_mask )
1774
1831
{
1775
- struct ta_ras_shared_memory * ras_cmd ;
1776
1832
struct amdgpu_device * adev = psp -> adev ;
1777
1833
int ret ;
1778
1834
uint32_t dev_mask ;
1835
+ uint32_t ras_status = 0 ;
1779
1836
1780
- if (!psp -> ras_context .context .initialized )
1837
+ if (!psp -> ras_context .context .initialized || ! info )
1781
1838
return - EINVAL ;
1782
1839
1783
1840
switch (info -> block_id ) {
@@ -1801,13 +1858,8 @@ int psp_ras_trigger_error(struct psp_context *psp,
1801
1858
dev_mask &= AMDGPU_RAS_INST_MASK ;
1802
1859
info -> sub_block_index |= dev_mask ;
1803
1860
1804
- ras_cmd = (struct ta_ras_shared_memory * )psp -> ras_context .context .mem_context .shared_buf ;
1805
- memset (ras_cmd , 0 , sizeof (struct ta_ras_shared_memory ));
1806
-
1807
- ras_cmd -> cmd_id = TA_RAS_COMMAND__TRIGGER_ERROR ;
1808
- ras_cmd -> ras_in_message .trigger_error = * info ;
1809
-
1810
- ret = psp_ras_invoke (psp , ras_cmd -> cmd_id );
1861
+ ret = psp_ras_send_cmd (psp ,
1862
+ TA_RAS_COMMAND__TRIGGER_ERROR , info , & ras_status );
1811
1863
if (ret )
1812
1864
return - EINVAL ;
1813
1865
@@ -1817,9 +1869,9 @@ int psp_ras_trigger_error(struct psp_context *psp,
1817
1869
if (amdgpu_ras_intr_triggered ())
1818
1870
return 0 ;
1819
1871
1820
- if (ras_cmd -> ras_status == TA_RAS_STATUS__TEE_ERROR_ACCESS_DENIED )
1872
+ if (ras_status == TA_RAS_STATUS__TEE_ERROR_ACCESS_DENIED )
1821
1873
return - EACCES ;
1822
- else if (ras_cmd -> ras_status )
1874
+ else if (ras_status )
1823
1875
return - EINVAL ;
1824
1876
1825
1877
return 0 ;
@@ -1829,25 +1881,16 @@ int psp_ras_query_address(struct psp_context *psp,
1829
1881
struct ta_ras_query_address_input * addr_in ,
1830
1882
struct ta_ras_query_address_output * addr_out )
1831
1883
{
1832
- struct ta_ras_shared_memory * ras_cmd ;
1833
1884
int ret ;
1834
1885
1835
- if (!psp -> ras_context .context .initialized )
1836
- return - EINVAL ;
1837
-
1838
- ras_cmd = (struct ta_ras_shared_memory * )psp -> ras_context .context .mem_context .shared_buf ;
1839
- memset (ras_cmd , 0 , sizeof (struct ta_ras_shared_memory ));
1840
-
1841
- ras_cmd -> cmd_id = TA_RAS_COMMAND__QUERY_ADDRESS ;
1842
- ras_cmd -> ras_in_message .address = * addr_in ;
1843
-
1844
- ret = psp_ras_invoke (psp , ras_cmd -> cmd_id );
1845
- if (ret || ras_cmd -> ras_status || psp -> cmd_buf_mem -> resp .status )
1886
+ if (!psp -> ras_context .context .initialized ||
1887
+ !addr_in || !addr_out )
1846
1888
return - EINVAL ;
1847
1889
1848
- * addr_out = ras_cmd -> ras_out_message .address ;
1890
+ ret = psp_ras_send_cmd (psp ,
1891
+ TA_RAS_COMMAND__QUERY_ADDRESS , addr_in , addr_out );
1849
1892
1850
- return 0 ;
1893
+ return ret ;
1851
1894
}
1852
1895
// ras end
1853
1896
0 commit comments