From patchwork Fri Apr 8 12:49:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Suthikulpanit, Suravee" X-Patchwork-Id: 65398 Delivered-To: patch@linaro.org Received: by 10.112.43.237 with SMTP id z13csp49456lbl; Fri, 8 Apr 2016 05:50:41 -0700 (PDT) X-Received: by 10.98.72.29 with SMTP id v29mr12319848pfa.71.1460119838421; Fri, 08 Apr 2016 05:50:38 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 81si741542pfq.221.2016.04.08.05.50.38; Fri, 08 Apr 2016 05:50:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932798AbcDHMuT (ORCPT + 29 others); Fri, 8 Apr 2016 08:50:19 -0400 Received: from mail-bn1on0061.outbound.protection.outlook.com ([157.56.110.61]:21856 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752071AbcDHMuP (ORCPT ); Fri, 8 Apr 2016 08:50:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=dJQw0cxDDYecahRT+eOterohi7Z0mN9kGMOOUjo1qLs=; b=omKty86E69tynQ7oZ0n19i/+lUvSXskoEZhHaPENFpxBZU88C7ndiJw0JnFJcQZh61IrDOdPoMFD2gxWK8+e741BgGzgkeeigeUpKOIc94OvcCrc93sj3juC8Q9E1jigHY3ghNID/zDskDSV6P+bJYhviV4wOT/ddz1b+CDlrGw= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=amd.com; Received: from localhost.localdomain (124.121.8.20) by SN1PR12MB0446.namprd12.prod.outlook.com (10.162.105.14) with Microsoft SMTP Server (TLS) id 15.1.453.26; Fri, 8 Apr 2016 12:50:03 +0000 From: Suravee Suthikulpanit To: , , , , , CC: , , , , Suravee Suthikulpanit Subject: [PART2 RFC v1 3/9] iommu/amd: Detect and initialize guest vAPIC log Date: Fri, 8 Apr 2016 07:49:24 -0500 Message-ID: <1460119770-2896-4-git-send-email-Suravee.Suthikulpanit@amd.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460119770-2896-1-git-send-email-Suravee.Suthikulpanit@amd.com> References: <1460119770-2896-1-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 X-Originating-IP: [124.121.8.20] X-ClientProxiedBy: HKNPR06CA0022.apcprd06.prod.outlook.com (10.141.16.12) To SN1PR12MB0446.namprd12.prod.outlook.com (10.162.105.14) X-MS-Office365-Filtering-Correlation-Id: 592b46a6-5f18-461e-71fb-08d35fac4fed X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0446; 2:1JB5OVkuOjMj2OHDqxepCUGTXlznmChOb7+A6IOYtfNh6PLlpPMV23UAM5/e3FyR8C3CHqtCfRY6tPg6rla9lsC9pSnSdhwKl9trs2kS5pDLPG5pGyJVu2W67AOiyfygBcpxOAZ4oPtCZPtpjbRvjEvWNlyaMc3jXEResX3M9bb1j2uIkrOFij5M/VRTw8JN; 3:A5eVxEntCDo4CMVKywBAk0eX7rXb7o/MWW29amGW4uN/KdFCgmpmpENclZL3II6KwonlOH42cV26ZRyBIIqWviKAyn8QYlvI83G5uM6Tc4OjG7pt8ZrR/lAzlULP+NNZ; 25:5HPSJ/ie/5XVSx0mr+JIaoK3Lx1AWKfCm4t7c2dSCENoqt+LV/mH7oN007YERnJoGLWHdPxQpOd92CTzuFail2CtvFOopMF+2mVQgjSqE15B2I12D0gyA+jKnfNdwYI28qhRXze4HHQ2szbw6hzokpQSk3pcD7DFoONy2E+03S6yoTQqk1guo2DJx4aDI8nnxN8vmP/oAiSnyCX0pqYv+KyjjEKT++j2ZSLS78ie+/hYkVo8t90JvrK8O1v3vW09c2BqdPFDcWvvUiqr7dXmygmtoHj07MdCmbL1KZsteEhjYODVh4jfEU0i9CoRWFSMLaeut8jS3c9aN3FzzueP0A== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR12MB0446; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0446; 20:UdBGKlFIn+4+TA2wsZAZRZE3YRQY62is5OyescfWY8dH6+PM8wHViqGyni036RlL5IZ19HTomUbwg/7vpv+PLyq3SC8rjXK4QS4tqo/mERU1lYwf13dqjk5py6oDvn4Xe3C73ihRxf0hUPyq+HsEKYkFmcyeGuk0js41NlRLzU2Ae3LarBLHAx/9yJ84dgrWzG1VsLqmc5LPUFFzAnprZE1qIte/mRrtirQDbZ8BGM3A3lzycewpn6JZUYJTQSMPQ42Vh1Y2nmYs20BK1mDys6tpj2IvJnvzMJ7O+Mh8yZr52WlP1NfeGS/EQ66c/fHRjLKaf826fg52oqVwwvVUTZKzznXZwhNGdzF9fInqAwqnMsjBMCXfdezKpoIer6BKkQPwRO08MhPcQV7zpnPPHdZKZFmzFrWeX2UB23CO9RzRgK68Om4heyMOY/gsMhWs504SiBRXLtcoXRwSkcJrrQBHLTYlw+TBr6FtMKQ7VGYPscH2OqQZPnYDnzG2wBLC; 4:pPVoxAPN/yAwejH8R8alvVCTJk2OLB1BSQqRedvd5MITEeTMme/8F5HxxKF5yw0thXClRydZGoqogWOHEqWQolfiK1qns4g1gcjhQ2LCfAmBR+0IRUghFgzSNtrpfJVO4DLWvJ+EmwJC6hqS3D7gQ59e6Un7yuZJkdSC6uWAHAFY3uKZA9dRNZO9v949wowGCTyEQLoASrGux6DG/tRI8TWRkGSOukn7w0+GgOcur17NwR72K5cloLPFgmpKHCWekFaLpNjGNDnLm4f6b11mWeKs3ZM3fDRU5nDNM24sNcECwac1KvDeQW0U1UpdrNrQyW/ZeKUhX+GCOeiza5qExDZjjc8fNHSaM1V9RKCRJjmbVn4cOBpk6GFrgqiwDiUt X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046); SRVR:SN1PR12MB0446; BCL:0; PCL:0; RULEID:; SRVR:SN1PR12MB0446; X-Forefront-PRVS: 0906E83A25 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(50466002)(48376002)(77096005)(47776003)(66066001)(229853001)(36756003)(86362001)(1096002)(42186005)(19580405001)(19580395003)(92566002)(6116002)(3846002)(586003)(5004730100002)(50986999)(76176999)(4326007)(189998001)(5003940100001)(2950100001)(2201001)(2906002)(5008740100001)(5001770100001)(81166005)(50226001); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1PR12MB0446; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SN1PR12MB0446; 23:UvPdOdwDyvPFsFgt0uTZxu2UOvcIpZzrQjMHblt96P/v4+yUt3qb8ZMY1c40CMgLWJz59K87xWkVIiGTu7riVkp7Xb6GIM+zL7QsQeE5v8n4KIoU1l7NboXznLdnS2MQFr/7/LuBx9KhlAEunUt7Kr+Uv3mg+e82YhS2guXF7rIIdgKc1u1T6amCnynpdXGY4iRyoabjx/+FXSdbSer8UDcO11nlt+SXewQnVYvWuZvWuKkVz+2bi/LOUXw/7+etzyFZqDApI0yhS2wvuyGrHZX7fA8wbX05054Z8v0fgVXoAG0THhSGivAHM4VkMGpfPm2diklhWYFDbVjuuiA28ZkBjiSsJ3i97yma9j3QhuivIkHjGx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mwwV06Vg2bDUCLIyQaaY1b8EPZ7ApoGjZaIMSryA X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2016 12:50:03.4970 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB0446 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suravee Suthikulpanit This patch adds support to detect and initialize IOMMU Guest vAPIC log (GALOG). By default, it also enable GALog interrupt to notify IOMMU driver when GA Log entry is created. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd_iommu_init.c | 82 +++++++++++++++++++++++++++++++++++++++++ drivers/iommu/amd_iommu_types.h | 30 +++++++++++++++ 2 files changed, 112 insertions(+) -- 1.9.1 diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 83a5300..5b783af 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -79,6 +79,7 @@ #define ACPI_DEVFLAG_LINT1 0x80 #define ACPI_DEVFLAG_ATSDIS 0x10000000 +#define LOOP_TIMEOUT 100000 /* * ACPI table definitions * @@ -368,6 +369,10 @@ static void iommu_disable(struct amd_iommu *iommu) iommu_feature_disable(iommu, CONTROL_EVT_INT_EN); iommu_feature_disable(iommu, CONTROL_EVT_LOG_EN); + /* Disable IOMMU GA_LOG */ + iommu_feature_disable(iommu, CONTROL_GALOG_EN); + iommu_feature_disable(iommu, CONTROL_GAINT_EN); + /* Disable IOMMU hardware itself */ iommu_feature_disable(iommu, CONTROL_IOMMU_EN); } @@ -618,6 +623,75 @@ static void __init free_ppr_log(struct amd_iommu *iommu) free_pages((unsigned long)iommu->ppr_log, get_order(PPR_LOG_SIZE)); } +static void __init free_ga_log(struct amd_iommu *iommu) +{ + if (iommu->ga_log) + free_pages((unsigned long)iommu->ga_log, + get_order(GA_LOG_SIZE)); + if (iommu->ga_log_tail) + free_pages((unsigned long)iommu->ga_log_tail, + get_order(8)); +} + +static int iommu_ga_log_enable(struct amd_iommu *iommu) +{ + u32 status, i; + + if (!iommu->ga_log) + return -EINVAL; + + status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET); + + /* Check if already running */ + if (status & (MMIO_STATUS_GALOG_RUN_MASK)) + return 0; + + iommu_feature_enable(iommu, CONTROL_GAINT_EN); + iommu_feature_enable(iommu, CONTROL_GALOG_EN); + + for (i = 0; i < LOOP_TIMEOUT; ++i) { + status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET); + if (status & (MMIO_STATUS_GALOG_RUN_MASK)) + break; + } + + if (i >= LOOP_TIMEOUT) + return -EINVAL; + return 0; +} + +static int iommu_init_ga_log(struct amd_iommu *iommu) +{ + u64 entry; + + if (amd_iommu_guest_ir < AMD_IOMMU_GUEST_IR_GA) + return 0; + + iommu->ga_log = (u8 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, + get_order(GA_LOG_SIZE)); + if (!iommu->ga_log) + goto err_out; + + iommu->ga_log_tail = (u8 *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, + get_order(8)); + if (!iommu->ga_log_tail) + goto err_out; + + entry = (u64)virt_to_phys(iommu->ga_log) | GA_LOG_SIZE_512; + memcpy_toio(iommu->mmio_base + MMIO_GA_LOG_BASE_OFFSET, + &entry, sizeof(entry)); + entry = ((u64)virt_to_phys(iommu->ga_log) & 0xFFFFFFFFFFFFFULL) & ~7ULL; + memcpy_toio(iommu->mmio_base + MMIO_GA_LOG_TAIL_OFFSET, + &entry, sizeof(entry)); + writel(0x00, iommu->mmio_base + MMIO_GA_HEAD_OFFSET); + writel(0x00, iommu->mmio_base + MMIO_GA_TAIL_OFFSET); + + return 0; +err_out: + free_ga_log(iommu); + return -EINVAL; +} + static void iommu_enable_gt(struct amd_iommu *iommu) { if (!iommu_feature(iommu, FEATURE_GT)) @@ -974,6 +1048,7 @@ static void __init free_iommu_one(struct amd_iommu *iommu) free_command_buffer(iommu); free_event_buffer(iommu); free_ppr_log(iommu); + free_ga_log(iommu); iommu_unmap_mmio_space(iommu); } @@ -1231,6 +1306,7 @@ static int iommu_init_pci(struct amd_iommu *iommu) { int cap_ptr = iommu->cap_ptr; u32 range, misc, low, high; + int ret; iommu->dev = pci_get_bus_and_slot(PCI_BUS_NUM(iommu->devid), iommu->devid & 0xff); @@ -1295,6 +1371,10 @@ static int iommu_init_pci(struct amd_iommu *iommu) amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA; + ret = iommu_init_ga_log(iommu); + if (ret) + return ret; + if (iommu->cap & (1UL << IOMMU_CAP_NPCACHE)) amd_iommu_np_cache = true; @@ -1449,6 +1529,8 @@ enable_faults: if (iommu->ppr_log != NULL) iommu_feature_enable(iommu, CONTROL_PPFINT_EN); + iommu_ga_log_enable(iommu); + return 0; } diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index ec546f3..d528a46 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -69,6 +69,8 @@ #define MMIO_EXCL_LIMIT_OFFSET 0x0028 #define MMIO_EXT_FEATURES 0x0030 #define MMIO_PPR_LOG_OFFSET 0x0038 +#define MMIO_GA_LOG_BASE_OFFSET 0x00e0 +#define MMIO_GA_LOG_TAIL_OFFSET 0x00e8 #define MMIO_CMD_HEAD_OFFSET 0x2000 #define MMIO_CMD_TAIL_OFFSET 0x2008 #define MMIO_EVT_HEAD_OFFSET 0x2010 @@ -76,6 +78,8 @@ #define MMIO_STATUS_OFFSET 0x2020 #define MMIO_PPR_HEAD_OFFSET 0x2030 #define MMIO_PPR_TAIL_OFFSET 0x2038 +#define MMIO_GA_HEAD_OFFSET 0x2040 +#define MMIO_GA_TAIL_OFFSET 0x2048 #define MMIO_CNTR_CONF_OFFSET 0x4000 #define MMIO_CNTR_REG_OFFSET 0x40000 #define MMIO_REG_END_OFFSET 0x80000 @@ -111,6 +115,9 @@ #define MMIO_STATUS_EVT_INT_MASK (1 << 1) #define MMIO_STATUS_COM_WAIT_INT_MASK (1 << 2) #define MMIO_STATUS_PPR_INT_MASK (1 << 6) +#define MMIO_STATUS_GALOG_RUN_MASK (1 << 8) +#define MMIO_STATUS_GALOG_OVERFLOW_MASK (1 << 9) +#define MMIO_STATUS_GALOG_INT_MASK (1 << 10) /* event logging constants */ #define EVENT_ENTRY_SIZE 0x10 @@ -149,6 +156,8 @@ #define CONTROL_GT_EN 0x10ULL #define CONTROL_GA_EN 0x11ULL #define CONTROL_GAM_EN 0x19ULL +#define CONTROL_GALOG_EN 0x1CULL +#define CONTROL_GAINT_EN 0x1DULL #define CTRL_INV_TO_MASK (7 << CONTROL_INV_TIMEOUT) #define CTRL_INV_TO_NONE 0 @@ -227,6 +236,19 @@ #define PPR_REQ_FAULT 0x01 +/* Constants for GA Log handling */ +#define GA_LOG_ENTRIES 512 +#define GA_LOG_SIZE_SHIFT 56 +#define GA_LOG_SIZE_512 (0x8ULL << GA_LOG_SIZE_SHIFT) +#define GA_ENTRY_SIZE 8 +#define GA_LOG_SIZE (GA_ENTRY_SIZE * GA_LOG_ENTRIES) + +#define GA_TAG(x) (u32)(x & 0xffffffffULL) +#define GA_DEVID(x) (u16)(((x) >> 32) & 0xffffULL) +#define GA_REQ_TYPE(x) (((x) >> 60) & 0xfULL) + +#define GA_GUEST_NR 0x1 + #define PAGE_MODE_NONE 0x00 #define PAGE_MODE_1_LEVEL 0x01 #define PAGE_MODE_2_LEVEL 0x02 @@ -494,6 +516,12 @@ struct amd_iommu { /* Base of the PPR log, if present */ u8 *ppr_log; + /* Base of the GA log, if present */ + u8 *ga_log; + + /* Tail of the GA log, if present */ + u8 *ga_log_tail; + /* true if interrupts for this IOMMU are already enabled */ bool int_enabled; @@ -687,6 +715,8 @@ struct __iommu_counter { #define INC_STATS_COUNTER(name) name.value += 1 #define ADD_STATS_COUNTER(name, x) name.value += (x) #define SUB_STATS_COUNTER(name, x) name.value -= (x) +#define SET_STATS_COUNTER(name, x) name.value = (x) +#define STATS_COUNTER(name) (name.value) #else /* CONFIG_AMD_IOMMU_STATS */