From patchwork Fri Oct 30 05:56:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 7524081 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A1295BEEA4 for ; Fri, 30 Oct 2015 06:03:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CE1782081C for ; Fri, 30 Oct 2015 06:03:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6254F20816 for ; Fri, 30 Oct 2015 06:03:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758647AbbJ3GDB (ORCPT ); Fri, 30 Oct 2015 02:03:01 -0400 Received: from mga11.intel.com ([192.55.52.93]:24296 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758630AbbJ3GC5 (ORCPT ); Fri, 30 Oct 2015 02:02:57 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP; 29 Oct 2015 23:02:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,217,1444719600"; d="scan'208";a="590814407" Received: from xiaoreal1.sh.intel.com (HELO xiaoreal1.sh.intel.com.sh.intel.com) ([10.239.48.79]) by FMSMGA003.fm.intel.com with ESMTP; 29 Oct 2015 23:02:55 -0700 From: Xiao Guangrong To: pbonzini@redhat.com, imammedo@redhat.com Cc: gleb@kernel.org, mtosatti@redhat.com, stefanha@redhat.com, mst@redhat.com, rth@twiddle.net, ehabkost@redhat.com, dan.j.williams@intel.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, Xiao Guangrong Subject: [PATCH v6 29/33] nvdimm acpi: support Get Namespace Label Data function Date: Fri, 30 Oct 2015 13:56:23 +0800 Message-Id: <1446184587-142784-30-git-send-email-guangrong.xiao@linux.intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1446184587-142784-1-git-send-email-guangrong.xiao@linux.intel.com> References: <1446184587-142784-1-git-send-email-guangrong.xiao@linux.intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Function 5 is used to get Namespace Label Data Signed-off-by: Xiao Guangrong --- hw/acpi/nvdimm.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/hw/acpi/nvdimm.c b/hw/acpi/nvdimm.c index 67c4699..8c27b25 100644 --- a/hw/acpi/nvdimm.c +++ b/hw/acpi/nvdimm.c @@ -428,6 +428,7 @@ struct NvdimmDsmIn { union { uint8_t arg3[0]; NvdimmFuncInSetLabelData func_set_label_data; + NvdimmFuncInGetLabelData func_get_label_data; }; } QEMU_PACKED; typedef struct NvdimmDsmIn NvdimmDsmIn; @@ -527,6 +528,65 @@ static void nvdimm_dsm_func_label_size(NVDIMMDevice *nvdimm, GArray *out) g_array_append_vals(out, &func_label_size, sizeof(func_label_size)); } +static uint32_t nvdimm_rw_label_data_check(NVDIMMDevice *nvdimm, + uint32_t offset, uint32_t length) +{ + if (offset + length < offset) { + nvdimm_debug("offset %#x + length %#x is overflow.\n", offset, + length); + return NVDIMM_DSM_DEV_STATUS_INVALID_PARAS; + } + + if (nvdimm->label_size < offset + length) { + nvdimm_debug("position %#x is beyond label data (len = %#lx).\n", + offset + length, nvdimm->label_size); + return NVDIMM_DSM_DEV_STATUS_INVALID_PARAS; + } + + if (length > nvdimm_get_max_xfer_label_size()) { + nvdimm_debug("length (%#x) is larger than max_xfer (%#x).\n", + length, nvdimm_get_max_xfer_label_size()); + return NVDIMM_DSM_DEV_STATUS_INVALID_PARAS; + } + + return NVDIMM_DSM_STATUS_SUCCESS; +} + +/* + * DSM Spec Rev1 4.5 Get Namespace Label Data (Function Index 5). + */ +static void nvdimm_dsm_func_get_label_data(NVDIMMDevice *nvdimm, + NvdimmDsmIn *in, GArray *out) +{ + NVDIMMClass *nvc = NVDIMM_GET_CLASS(nvdimm); + NvdimmFuncInGetLabelData *get_label_data = &in->func_get_label_data; + void *buf; + uint32_t status; + + le32_to_cpus(&get_label_data->offset); + le32_to_cpus(&get_label_data->length); + + nvdimm_debug("Read Label Data: offset %#x length %#x.\n", + get_label_data->offset, get_label_data->length); + + status = nvdimm_rw_label_data_check(nvdimm, get_label_data->offset, + get_label_data->length); + if (status != NVDIMM_DSM_STATUS_SUCCESS) { + goto exit; + } + + /* write nvdimm_func_out_get_label_data.status. */ + nvdimm_dsm_write_status(out, status); + /* write nvdimm_func_out_get_label_data.out_buf. */ + buf = acpi_data_push(out, get_label_data->length); + nvc->read_label_data(nvdimm, buf, get_label_data->length, + get_label_data->offset); + return; + +exit: + nvdimm_dsm_write_status(out, status); +} + static void nvdimm_dsm_device(NvdimmDsmIn *in, GArray *out) { GSList *list = nvdimm_get_plugged_device_list(); @@ -554,6 +614,9 @@ static void nvdimm_dsm_device(NvdimmDsmIn *in, GArray *out) case 0x4 /* Get Namespace Label Size */: nvdimm_dsm_func_label_size(nvdimm, out); goto free; + case 0x5 /* Get Namespace Label Data */: + nvdimm_dsm_func_get_label_data(nvdimm, in, out); + goto free; default: status = NVDIMM_DSM_STATUS_NOT_SUPPORTED; };